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.

TMS320F28377D: HRPWM understanding manual conversion

Part Number: TMS320F28377D

Hello,

I'm trying to implement HRPWM capabilities in F28337D. In order to understand it, I tried to compare Autoconversion mode results and manual conversion results, but it seems to be different. Why do I get different results for CMPA and CMPAHR registers enabling or not autoconversion mode? I tried with the example of TI (hrpwm_duty_sfo_v8.c) and I also get these different results:

DutyFine = 0x5737

EPwm1Regs.TBPRD = 9

MEP_ScaleFactor = 64 (it is calculated by SFO)

With autoconversion mode enabled I get: 

EPwm1Regs.CMPA.bit.CMPA=0x6

EPwm1Regs.CMPA.bit.CMPAHR=0x2100

With manual mode enabled I get: 

EPwm1Regs.CMPA.bit.CMPA=0x6

EPwm1Regs.CMPA.bit.CMPAHR=0x0800

For manual conversion,  I see that the example of TI for F28379D (hrpwm_duty_sfo_v8.c) says:

COMMENTS:
** If auto-conversion is enabled, the following step is performed
automatically in hardware and can be skipped
// Add the offset and rounding
CMPAHR_reg_val += 0x0080;

However, in the TI code below I can't see this offset and rounding. In the Technical Reference Manual, in fact, it doesn't appear either, so I don't know if it's a mistake of the example or not.

CODE:

#if (AUTOCONVERT)
CMPAHR_reg_val = temp<<1; // convert to Q16
CMPBHR_reg_val = temp<<1; // convert to Q16
#else
CMPAHR_reg_val = ((temp*MEP_ScaleFactor)+(0x0080<<7))>>15;
CMPAHR_reg_val = CMPAHR_reg_val << 8;
CMPBHR_reg_val = ((temp1*MEP_ScaleFactor)+(0x0080<<7))>>15;
CMPBHR_reg_val = CMPBHR_reg_val << 8;
#endif

So, it is necessary to add 0x0080 for offset and rounding or not? And why do I get different results for both modes?
Thank you!

Maite

 

  • Hi Maite,

    I believe the 0x80 is equivalent to the rounding factor of +0.5 called for in the TRM shifted left 8 bits.  In the manual code, we go through the steps

    0x80

    (0x80 << 7)

    (0x80 << 7) >> 15

    ((0x80 << 7) >> 15) << 8

    Which should resolve back to the desired final offset value of 0x80 written to the register.

    I'm not sure why you don't get similar values for both procedures.  

  • Hi Devin,

    it is possible you're right. The problem (or doubt) is that in the example of TI it seems they do it two times (acoording to the comments), but in the code they only implement what I posted before.

    I attach here comments:

     ** If auto-conversion is enabled, the following step is performed
                   automatically in hardware and can be skipped
                // This obtains the MEP count in digits, from
                // 0,1, .... MEP_Scalefactor.
                // 0x0080 (0.5 in Q8) is converted to 0.5 in Q15 by shifting left 7.
                // This is added to fractional duty*MEP_SF product in order to round
                // the decimal portion of the product up to the next integer if the
                // decimal portion is >=0.5.
                //
                //Once again since this is Q15
                // convert to Q0 by shifting:
                CMPAHR_reg_val = (temp*MEP_ScaleFactor+(0x0080<<7))>>15;

                ** If auto-conversion is enabled, the following step is performed
                   automatically in hardware and can be skipped
                // Now the lower 8 bits contain the MEP count.
                // Since the MEP count needs to be in the upper 8 bits of
                // the 16 bit CMPAHR register, shift left by 8.
                CMPAHR_reg_val = CMPAHR_reg_val << 8;

                ** If auto-conversion is enabled, the following step is performed
                   automatically in hardware and can be skipped
                // Add the offset and rounding
                CMPAHR_reg_val += 0x0080;


    On the other hand, I think that the different between CMPAHR register value doing autoconversion mode and manual mode is normal. According to the technical reference manual, in automatic mode the hardware converts the value in CMPAHR to a scaled micro-edge delyay on the PWM output using the MEP_ScaleFactor....so I think that it is not possible to compare both CMPAHR values, we should compare PWM output instead.

    thank you very much!

    Maite

  • Hi Maite,

    We are working on confirming that the comments do need to be updated. We will then eventually push an update to the SW to align the comments, documentation, and actual procedure.