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.
Hello,
This is related to my previous question on HRPWM TBPHSHR. I am in updown count mode, HR autoconvert is on, HRPE is off, and switching at 200 khz. I am now able to get symmetric waveforms and the edges shift correctly. The problem I am seeing now is the tbphs and tbphshr shift the waveforms in opposite directions. That is, a tbphs to tbphs+1 will move the slave in one direction and a tbphshr =256 (minimum) to tbphshr = 64000 will move it in the opposite direction. This is shown in the figure below and I am setting/verifying the register values in the expression windows.
If all the HRPWM registers do is shift the waveform to the right (both edges for tbphshr) then I can see this behavior being correct and the math needing to be different depending on if you are leading or lagging. However, I didn't see this in the datasheet or online. This question (https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/858613/tms320f28379d-usage-information-on-trrem-register-for-periodic-hr-phase-update) says you need to subtract the HR phase for a negative phase shift, but that still wouldn't give the right value as you have to add +1 to tbphs first.
For example, if my understanding is correct and I wanted a leading phase shift of 5.75 I would need tbphs = 6 (not 5) and then set tbphshr = 64000-48000 (roughly) so the correct phase comes out to be 6-0.25 = 5.75. Is this the proper way to do a leading tbphshr phase shift?
Meanwhile a lagging phase shift of 5.75 would be tbphs =5 tbphshr = 0.75*(64000)?
Thanks
So that register is not the default value! you set this to a one.
Can you try changing this to 0 and testing if the behavior of the TBPHSHR reverses?
PHSDIR was set to 1 to get a leading shift
I am unable to double check at the moment, but if I remember correctly I verified TBPHS and TBPHSHR move in the same direction (i.e to the right/lagging) when PHSDIR = 0
I am currently setting TBPHSHR differently if I am leading/lagging as per below
//leading code PWM2_SHIFT_float>0 EPwm2Regs.TBCTL.bit.PHSDIR = 1; PWM2_SHIFT_float+= 1.0; PWM2_SHIFT = (uint16_t)PWM2_SHIFT_float; PWM2_SHIFT_frac = (PWM2_SHIFT_float - PWM2_SHIFT)*PWM_TBPRD_UPDOWN; EPwm2Regs.TBPHS.bit.TBPHSHR = 0xFF00 - ((uint16_t)(PWM2_SHIFT_frac*256)); //lagging code PWM2_SHIFT_float<0 EPwm2Regs.TBCTL.bit.PHSDIR = 0; PWM2_SHIFT_float = fabs(PWM2_SHIFT_float); PWM2_SHIFT = (uint16_t)PWM2_SHIFT_float; PWM2_SHIFT_frac = (PWM2_SHIFT_float - PWM2_SHIFT)*PWM_TBPRD_UPDOWN; EPwm2Regs.TBPHS.bit.TBPHSHR = 0x0100|((uint16_t)(PWM2_SHIFT_frac*256));
Jason,
That is the correct solution. You will need to subtract from 0xFF to shift the other direction for TBPHSHR. That is what I had in other threads as well.
I will consult this quickly with the design team and get back to you with another confirmation.
Nima
Verified with design. HR is always a delay value! so what you are doing is 100% correct.