Hello everyone,
I'm just implementing a few optimizations of my code of the dual active bridge power converter.
To calculate the HRPWM TBPHS register values, I'm using the following example code:
PHSFine = -(long)controlvalue; //controlvalue is negativ PHS_reg_val = (long)(PHSFine * (EPwm3Regs.TBPRD*2 + 2))>>15; tempPHS = (long)(PHSFine * (EPwm3Regs.TBPRD*2 + 2)) ; tempPHS = tempPHS - ((long)PHS_reg_val << 15); PHSHR_reg_val = tempPHS << 1; // convert to Q16 EPwm3Regs.TBPHS.all = (((long)PHS_reg_val) << 16) | PHSHR_reg_val; // loses lower 8-bits EPwm4Regs.TBPHS.all = (((long)PHS_reg_val) << 16) | PHSHR_reg_val; // loses lower 8-bits
I have the following issue:
during the control phase, the PHSHR_reg_val is always near the maximum value and jumps between ~65000 and ~200. The PHS_reg_val value jumps also between two values.
This results in jitter on the PWM signal and is no smooth transition.
If I add 16384 to PHSFine and subtract 100 from the register value PHS_reg_val , the jitter disappears. The code follows.
PHSFine = 16384 +(long)controlvalue; //Phase Shift Mode PHS_reg_val = (long)(PHSFine * (EPwm3Regs.TBPRD*2 + 2))>>15; tempPHS = (long)(PHSFine * (EPwm3Regs.TBPRD*2 + 2)) ; tempPHS = tempPHS - ((long)PHS_reg_val << 15); PHSHR_reg_val = tempPHS << 1; // convert to Q16 EPwm3Regs.TBPHS.all = (100-((long)PHS_reg_val) << 16) | PHSHR_reg_val; // loses lower 8-bits EPwm4Regs.TBPHS.all = (100-((long)PHS_reg_val) << 16) | PHSHR_reg_val; // loses lower 8-bits
I cannot understand why there is a difference because normally the control loop should generate the same phase shift value.
Thanks for your help.