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.

ePWM with F28377s launchpad.

  I am using the launchpad to do the ePWM. I have been able to get the correct PWM wave form. I am trying to do something in addition, where instead of manually imputing values to modulate the PWM  in the CMPA_Reg  I can just put in the duty cycle percentage and the result will be automatically computed and inserted to the CMPA. I am considering writing a code that will do the calculation but how can I link it to the CMPA where it automatically inputs the result for the duty cycle I want to determine. Is there any specific approach that you think will be better? Thank you!

  • Hi,

    This is pretty simply. All you need to do is:
    You know the TBPRD value and lets assume that its 1000.
    Hence, when CMPA = 500, duty cycle = 50%
    when CMPA = 789, duty cycle = 78.9%

    I hope you understood and now all you've to do is reverse calculation ie calculating CMPA value from duty cycle percentage. Let me know if you got the calculations.

    Regards,
    Gautam
  • Thanks Guatam,

       can you tell me where i can edit  this file or register for the  above TBPRD. thank you

  • You can find the same in ePWM initialization.
  • Oh ok thanks i will let you know of my advances

  • Hey Gautam,
    i did checked the Epwm but couldn't figure it out can you please explain in details what to do that will help, i just saw registers but dont know what to do with your previous explanation. example of register i saw are


    asm(" EALLOW"); // Enable EALLOW protected register access
    DevCfgRegs.SOFTPRES2.bit.EPWM1 = 1; // ePWM1 is reset
    DevCfgRegs.SOFTPRES2.bit.EPWM1 = 0; // ePWM1 is released from reset
    asm(" EDIS"); // Disable EALLOW protected register access

    EPwm3Regs.TBCTL.bit.CTRMODE = 0x3; // Disable the timer

    EPwm3Regs.TBCTL.all = 0xC033; // Configure timer control register


    // bit 15-14 11: FREE/SOFT, 11 = ignore emulation suspend
    // bit 13 0: PHSDIR, 0 = count down after sync event
    // bit 12-10 000: CLKDIV, 000 => TBCLK = HSPCLK/1
    // bit 9-7 000: HSPCLKDIV, 000 => HSPCLK = EPWMCLK/1
    // bit 6 0: SWFSYNC, 0 = no software sync produced
    // bit 5-4 11: SYNCOSEL, 11 = sync-out disabled
    // bit 3 0: PRDLD, 0 = reload PRD on counter=0
    // bit 2 0: PHSEN, 0 = phase control disabled
    // bit 1-0 11: CTRMODE, 11 = timer stopped (disabled)

    EPwm3Regs.TBCTR = 0x0000; // Clear timer counter
    EPwm3Regs.TBPRD = PWM_HALF_PERIOD; // Set timer period
    EPwm3Regs.TBPHS.bit.TBPHS = 0x0000; // Set timer phase

    EPwm3Regs.CMPA.bit.CMPA = PWM_DUTY_CYCLE; // Set PWM duty cycle

    EPwm3Regs.CMPCTL.all = 0x0002; // Compare control register
    // bit 15-10 0's: reserved

    Thanks for your help.