This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: Matlab Simulink Overwirte PWM CMPA CMPB Registers directly in Interrupt

Part Number: TMS320F28379D

Hello guy,

do somebody know how I write in the PWM CMPA/CMPB Registers directly inside of an interrupt.

I'm using Simulink.

Thanks

  • Hi Kevin,

    We have C28x Hardware Interrupt block for the same.

    Please refer the example 'c28379Dpmsmfocdual_cpu1_ert' for more information.

    Here we are updating the CMPA and CMPB register inside an interrupt.

  • Hello Venkatesh,

    I try to put all PWM blocks into the Interrupt , but it takes to much time.

    I just want to write into the CMPA, CMPB and Deadband (DBRED /DBFED) register.

    I did use an System Update customcode block and it work, but the variablenames  are combined with the projectname. So when I'm  save the project under  another name, the customcode doesn't work anymore and must be edited.

    Also I want to read ADC values.

    Can I use the Memory Copy and how?  I tried it, but it doesn't work.

    Here my settings:

    Best regards

    Kevin

  • Hi,

    With Memory Copy block you are probably missing on the EALLOW and EDIS instructions before and after the lines of code that update the register values.

    To do this, you need to check on the 'Insert custom code.....' options under the Memory Copy 'options' tab.

    The options Tab is already captured by you above.

  • Hello,

    it doesn't work.

    When I'm looking into the C-Code the Memory Copy blocks aren't in the direct Interrupt function...

    I want to overwrite the CMPA/CMPA/ Deadtime values every Interrupt. Also want to read every Interrupt the ADC Values.

    That's the generated code:


    /* ConstCode for S-Function (c28xisr_c2000): '<Root>/C28x Hardware Interrupt' incorporates:
    * SubSystem: '<Root>/Interrupt_ADC'
    */
    /* ConstCode for function-call system: '<Root>/Interrupt_ADC' */
    {
    /* local block i/o variables */
    real32_T rtb_Conv9;
    real32_T rtb_CCminusCMPA;
    /* ConstCode for S-Function (memorycopy): '<S3>/Memory Copy' */
    {
    real32_T *memindsrc = (real32_T *) (&rtb_Conv9);
    real32_T *meminddst = (real32_T *) (EPwm1Regs.CMPA.bit.CMPA);
    EALLOW;
    *(real32_T *) (meminddst) = *(real32_T *) (memindsrc);
    EDIS;
    }
    /* ConstCode for S-Function (memorycopy): '<S3>/Memory Copy1' */
    {
    real32_T *memindsrc = (real32_T *) (&rtb_CCminusCMPA);
    real32_T *meminddst = (real32_T *) (EPwm1Regs.CMPB.bit.CMPB);
    EALLOW;
    *(real32_T *) (meminddst) = *(real32_T *) (memindsrc);
    EDIS;
    }
    /* ConstCode for S-Function (memorycopy): '<S3>/Memory Copy2' */
    {
    real32_T *memindsrc = (real32_T *)
    (&PWM_3PHASE_DAB_30_09_V1_B.Deadtimecheck);
    real32_T *meminddst = (real32_T *) (EPwm1Regs.DBRED.bit.DBRED);
    EALLOW;
    *(real32_T *) (meminddst) = *(real32_T *) (memindsrc);
    EDIS;
    }
    /* ConstCode for S-Function (memorycopy): '<S3>/Memory Copy3' */
    {
    real32_T *memindsrc = (real32_T *)
    (&PWM_3PHASE_DAB_30_09_V1_B.Deadtimecheck);
    real32_T *meminddst = (real32_T *) (EPwm1Regs.DBFED.bit.DBFED);
    EALLOW;
    *(real32_T *) (meminddst) = *(real32_T *) (memindsrc);
    EDIS;
    }
    }
    /* End of ConstCode for S-Function (c28xisr_c2000): '<Root>/C28x Hardware Interrupt' */
  • Hi Kevin,

    Please can you attach your model?

  • Hello,

    i now did a workaround. I'm using Data Store Memory and Custom Code Blocks.