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.

TMS320F28035: HRPWM example code

Part Number: TMS320F28035
Other Parts Discussed in Thread: C2000WARE

Hi,

I'm testing our HRPWM example code in C2000WARE.

For the code below, I did minor modification.

C:\ti\c2000\C2000Ware_3_02_00_00\device_support\f2803x\examples\c28\hrpwm

And I find that for DutyFine varying from 0-255, the actual duty cycle of PWM1A is 50% to 70%. 

In this example code, PWM1 period=10, PWM1 CMPA=5.

1. My question is: we don't know MEP_ScaleFactor value, what will happen if CMPAHR=DutyFine>MEP_ScaleFactor?

Then we test the next example code below:

C:\ti\c2000\C2000Ware_3_02_00_00\device_support\f2803x\examples\c28\hrpwm_duty_sfo_v6

PRD=10, CMPA=5, MEP_ScaleFactor=128.

When

CMPAHR=0X0100, we get 50% duty cycle.

CMPAHR=0X8000, we get 55% duty cycle.

CMPAHR=0XFF00, we get 60% duty cycle.

2. So it seems that MEP_ScaleFactor is 255(0xFF) instead of 128, what's wrong here?

  • Howard,

    are you running the SFO? Running the SFO will set the MEP scale factor to the correct size. After that you should be able to simply write a value between 0 and 255 and the HRPWM will use figure out the correct number of MEPs to use.

    I don't think there is any restriction on CMPHR and the size of your scale factor, the scale factor is just used for scaling the values you input to the correct hardware conditions.

    Regards,
    Cody  

  • Cody,

    for the first example I'm not running SFO.

    My question is: 

    1. if MEPScaleFactor=100, if I write CMPAHR=110, CMPA=5, then the compare value that take effect will be 5+110/100=6.1, right?

    2. My second question is related to the second example code, we run SFO and MEPScaleFactor=128.

    CMPAHR=0X0100, we get 50% duty cycle.

    CMPAHR=0X8000, we get 55% duty cycle. which we suppose to get 60% duty cycle, since CMPA=5, PEROID=10, duty cycle=(5+0x80/128)/10=6/10=60%

    CMPAHR=0XFF00, we get 60% duty cycle.

    That's why I say MEPScaleFactor=128, but the effect value seems to be 256, that's what I don't understand.

  • I find that the second problem happens only when 

    HRCNFG.bit.AUTOCONV=1.

    If it's 0.

    CMPAHR=0X0100, we get 50% duty cycle.

    CMPAHR=0X8000, we get 60% duty cycle. which is what we supposed to get.

    CMPAHR=0XFE00, we get 70% duty cycle. which is what we supposed to get. 

    CMPAHR=0XFF00, we get 50% duty cycle. which means the CMPAHR register is ignored, why?

    And why the duty cycle is not what we supposed to get when HRCNFG.bit.AUTOCONV=1.?

  • In the TRM it says:

    If the AUTOCONV bit (HRCNFG.6) is set and the MEP_ScaleFactor is in the HRMSTEP
    register, then CMPAHR register value = frac (PWMDuty*PWMperiod<<8). The rest of the
    conversion calculations are performed automatically in hardware, and the correct MEPscaled
    signal edge appears on the ePWM channel output. If AUTOCONV is not set, the
    above calculations must be performed by software.

    My question is:

    If PWMperiod=10, PWMDuty=0.55.

    Should I write CMPAHR=frac(10*0.55)<<8=0.5<<8=0.5*256=128?

  • Howard, 

    If you are calculation the values in code please do not use AUTOCONV. Follow this procedure:

    If you are using AUTOCONV then follow these instructions:

    When AUTOCONV is enabled the maximum useable value is 0xFE, 0xFF and 0x00 are not valid. 

    I did not verify your calculation above, but remember you need to multiply by your MEP_Scalefactor which looks incorrect in your calculation. Please see the picture above for more info on how to calculate. its the number of MEP steps in one coarse step(one sysclk period).

    Regards,
    Cody 

  • Cody,

    when AUTOCONV is enabled, it has nothing to do with MEP_Scalefactor

    My question is:

    If PWMperiod=10, PWMDuty=0.55.

    Should I write CMPAHR=frac(10*0.55)<<8=0.5<<8=0.5*256=128=0x0080?

  • Howard,

    yes, if you are using AUTOCONV it looks like that math is correct.

    Regards,
    Cody

  • Howard,

    please allow me sometime to confirm that when AUTOCONV is enabled that the lower 8 bits are not ignored.

    Regards,
    Cody 

  • Howard,

    I can confirm that the lower 8 bits of the CMPAHR register are ignored.

    Please note that the result of the calculation you have preformed (0x0080) should be written into the CMPAHR bits of the CMPAHR register. These are the upper 8 bits of the CMPAHR register. (0x8000) will be the value as read from the CMPAHR register. And if you look at CMPAHR.CMPAHR you should see a value of 0x80.

    Regards,
    Cody