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.

PWM duty cycle cannot update

Other Parts Discussed in Thread: CCSTUDIO

Hi,

I have some problems with programming F28335 chip by Simulink.
I opened the demo c28335 adcpwmasyntest.mdl from Target Support Package TC2, all the setting are default. I build this model, the C code is generated automatically in CCS without any errors and warnings, and was downloaded into the DSP correctly. However, with the scope observing the PWM output, the duty cycle didn't vary according to the ADC output values.

In order to simplify the model, then I revised the ePWM block of this demo:

The time period units still select Clock cycles, Time period source still select Specify via dialog, Time period is still 20480, I set up initial value in CMPA for 10240, CMPA source is set to input port. For this input port I have attached constant block with 5120 value. Counting mode is Up-down, CMPA on CAU Set, CMPA on CAD Clear. I can download this program and run it, but I don't get proper working program: on scope the PWM signal is filled 50% (like initial value=10240/20480), i.e. the PWM duty cycle can not update from the input port, always equal to the initial value. Then I change the input port constant block with other values, but the duty cycle of the PWM signal output from ePWM pin still did change (always equal to CMPA initial value/Time period). I was trying check all options in ePWM block, but I don't find any solution.


Does anybody had similar problem? What am I doing wrong?
About my software and hardware: I have Matlab R2009a, CCStudio 3.3 and F28335 DSP

Best regards!

Jerry

  • Jerry,

    Cam you provide me with a scope shot and pseudo code of what duty cycle control you are trying to do.

    I might be able to provide a snipett pesudo code based off of that.

     

    Regards,

    Mahesh

     

  • Hi Mahesh,

    Below is the PWM output from pin ePWM3A and ePWM3B. Actually my problem is that the duty cycle of the PWM cannot update, i.e. the CMPA cannot update from the input port value but alway equal to the initial CMPA value. I am kind of thinking that this issue maybe related to RTW and CCS setting rather than code.

    Below are the related C code generated automatically.

    //main function file:

    void rt_OneStep(void)

    {

      if (OverrunFlag++) {

        IsrOverrun = 1;

        OverrunFlag--;

        return;

      }

      asm(" SETC INTM");

      PieCtrlRegs.PIEIER1.all |= (1 << 6);

      asm(" CLRC INTM");

      Rectifier_CDPC_step();

      asm(" SETC INTM");

      PieCtrlRegs.PIEIER1.all &= ~(1 << 6);

      asm(" RPT #5 || NOP");

      IFR &= 0xFFFE;

      PieCtrlRegs.PIEACK.all = 0x1;

      asm(" CLRC INTM");

      OverrunFlag--;

    }

    // Entry point into the code

    void main(void)

    {

      volatile boolean_T noErr;

      init_board();

      Rectifier_CDPC_initialize(1);

     

      /* **starting the model** */

      config_schedulerTimer();

      noErr =

        rtmGetErrorStatus(Rectifier_CDPC_M) == (NULL);

      enable_interrupts();

      while (noErr ) {

        noErr =

          rtmGetErrorStatus(Rectifier_CDPC_M) == (NULL);

      }

      /* **stopping the model** */

      /* Disable rt_OneStep() here */

      /* Terminate model */

      Rectifier_CDPC_terminate();

      disable_interrupts();

    }

    //Call-function file, CMPA of ePWM1and ePWM2 is updated from input port which connected to ADC output, CMPA of ePWM3 is updated from input port which is connected to //a constant value

    void isr_int1pie1_task_fcn(void)

    {

      /* Call the system: <Root>/ADC-PWM Subsystem */

       /* Output and update for function-call system: '<Root>/ADC-PWM Subsystem' */

      {

        /* local block i/o variables */

        uint16_T rtb_Gain1;

     

        /* S-Function Block: <S1>/ADC (c280xadc) */

        {

          Rectifier_CDPC_B.ADC[0] = (AdcRegs.ADCRESULT0) >> 4;

          AdcRegs.ADCTRL2.bit.RST_SEQ1 = 0x1;// Sequencer reset

        }

     

        /* Gain: '<S1>/Gain1' */

        rtb_Gain1 = Rectifier_CDPC_P.Gain1_Gain * Rectifier_CDPC_B.ADC[0];

        /*-- Update CMPA value for ePWM1 --*/

        {

          EPwm1Regs.CMPA.half.CMPA = (uint16_T)(rtb_Gain1);

        }

         /*-- Update CMPA value for ePWM2 --*/

        {

          EPwm2Regs.CMPA.half.CMPA = (uint16_T)(rtb_Gain1);

        }

         /*-- Update CMPA value for ePWM3 --*/

        {

          EPwm3Regs.CMPA.half.CMPA = (uint16_T)(Rectifier_CDPC_P.Constant1_Value);

        }

      }

    }

    //ePWM and ADC initialization (only ePWMx3 setting is given)

    void Rectifier_CDPC_initialize(boolean_T firstTime)

    {

      (void)firstTime;

       /* Registration code */

       /* initialize error status */

      rtmSetErrorStatus(Rectifier_CDPC_M, (NULL));

       /* block I/O */

      (void) memset(((void *) &Rectifier_CDPC_B),0,

                    sizeof(BlockIO_Rectifier_CDPC));

       /* Start for function-call system: '<Root>/ADC-PWM Subsystem' */

      InitAdc();

      config_ADC_A (5U, 12816U, 84U, 0U, 0U);

     

    /*** Initialize ePWM3 modules ***/

      {

        EPWMPARAMS EPwm3Params;

     

        /*-- Setup Time-Base (TB) Submodule --*/

        EPwm3Params.TBPRD = 20480;

        EPwm3Params.TBCTL_CTRMODE = 2;

        EPwm3Params.TBCTL_SYNCOSEL = 0;

        EPwm3Params.TBCTL_PHSEN = 1;

        EPwm3Params.TBCTL_PHSDIR = 0;

        EPwm3Params.TBPHS = 0;

        EPwm3Params.TBCTL_HSPCLKDIV = 0;

        EPwm3Params.TBCTL_CLKDIV = 0;

     

        /*-- Setup Counter_Compare (CC) Submodule --*/

        EPwm3Params.CMPCTL_LOADAMODE = 0;

        EPwm3Params.CMPCTL_LOADBMODE = 0;

        EPwm3Params.CMPA = 10240;

        EPwm3Params.CMPB = 0;

     

        /*-- Setup Action-Qualifier (AQ) Submodule --*/

        EPwm3Params.AQCTLA = 96;

        EPwm3Params.AQCTLB = 264;

        EPwm3Params.AQCSFRC_CSFA = 0;

        EPwm3Params.AQCSFRC_CSFB = 0;

        EPwm3Params.AQCSFRC_RLDCSF = 0;

     

        /*-- Setup Dead-Band Generator (DB) Submodule --*/

        EPwm3Params.DBCTL_OUT_MODE = 3;

        EPwm3Params.DBCTL_IN_MODE = 0;

        EPwm3Params.DBCTL_POLSEL = 1;

        EPwm3Params.DBRED = 200.0;

        EPwm3Params.DBFED = 200.0;

     

        /*-- Setup Event-Trigger (ET) Submodule --*/

        EPwm3Params.ETSEL_SOCAEN = 0;

        EPwm3Params.ETSEL_SOCASEL = 2;

        EPwm3Params.ETPS_SOCAPRD = 1;

        EPwm3Params.ETSEL_SOCBEN = 0;

        EPwm3Params.ETSEL_SOCBSEL = 1;

        EPwm3Params.ETPS_SOCBPRD = 1;

        EPwm3Params.ETSEL_INTEN = 0;

        EPwm3Params.ETSEL_INTSEL = 1;

        EPwm3Params.ETPS_INTPRD = 1;

     

        /*-- Setup PWM-Chopper (PC) Submodule --*/

        EPwm3Params.PCCTL_CHPEN = 0;

        EPwm3Params.PCCTL_CHPFREQ = 0;

        EPwm3Params.PCCTL_OSHTWTH = 0;

        EPwm3Params.PCCTL_CHPDUTY = 0;

     

        /*-- Setup Trip-Zone (TZ) Submodule --*/

        EPwm3Params.TZSEL = 256;

        EPwm3Params.TZCTL_TZA = 0;

        EPwm3Params.TZCTL_TZB = 0;

        EPwm3Params.TZEINT_OST = 0;

        EPwm3Params.TZEINT_CBC = 0;

         /*-- Initial ePWM3 --*/

        config_ePWMRegs(&EPwm3Regs, &EPwm3Params);

      }

    }

    Kind regards,

    Jerry

  • Old post but did you ever find a solution?

    I am having a similar problem with no PWM update.

    Thanks