I'm working with the BLDC_Sensored example for the DRV8312 kit. Here's some code from "f2803xbldcpwm_BLDC.h". It looks like it has multiple bugs (unless I'm missing something).
1. Why is "EPwm1Regs.CMPB = (int16)(Tmp2>>15)" always set for all commutation states?
2. Why is "EPwm1Regs.CMPA.half.CMPA = (int16)(Tmp>>15)" when the next statement forces output A high?
3. Why is "CMPB_SMPL_POINT" important? The motor control code in the "C:\ti\controlSUITE\libs\app_libs\motor_control\drivers\f2803x_v2.0\f2803xbldcpwm.h" file doesn't use this technique.
4. Is the DRV8312 board configured to drive the PWM signal on output B (for all commutation states)? The motor control code uses output A.
5. When PWM is "active high", do you need to invert forced outputs (change from "force low" to "force high", etc)?
6. Why does this example work at all?
#define BLDCPWM_MACRO(v)\
/* Convert "Period" (Q15) modulation function to Q0 */\
Tmp = (int32)v.PeriodMax*(int32)v.MfuncPeriod; /* Q15 = Q0xQ15 */\
Period = (int16)(Tmp>>15); /* Q15 -> Q0 (Period) */\
\
/* Check PwmActive setting */\
if (v.PwmActive==1) /* PWM active high */\
{\
GPR0_BLDC_PWM = 0x7FFF - v.DutyFunc; \
CMPB_SMPL_POINT = 0x7FFF - (v.DutyFunc >> 1); /* Sample in center of PWM pulse using CMPB */\
}\
else if (v.PwmActive==0) /* PWM active low */\
{\
GPR0_BLDC_PWM = v.DutyFunc;\
CMPB_SMPL_POINT = v.DutyFunc >> 1; /* Sample in center of PWM pulse using CMPB */\
}\
\
/* Convert "DutyFunc" or "GPR0_BLDC_PWM" (Q15) duty modulation function to Q0 */\
Tmp = (int32)Period*(int32)GPR0_BLDC_PWM; /* Q15 = Q0xQ15 */\
Tmp2 = (int32)Period*(int32)CMPB_SMPL_POINT; /* Q15 = Q0xQ15 */\
EPwm1Regs.CMPB = (int16)(Tmp2>>15); /* Sample in center of PWM pulse using CMPB */\
\
/* State s1: current flows to motor windings from phase A->B, de-energized phase = C */\
if (v.CmtnPointer==0)\
{\
EPwm1Regs.AQCSFRC.bit.CSFB = 0; /* Forcing disabled on output B of EPWM1 */\
EPwm1Regs.AQCTLB.bit.CAU = 2; /* Set high when CTR = CMPA on UP-count */\
EPwm1Regs.AQCTLB.bit.ZRO = 1; /* Set low when CTR = Zero */\
EPwm1Regs.CMPA.half.CMPA = (int16)(Tmp>>15); /* PWM signal on output B of EPWM1 (Q15 -> Q0) */\
EPwm1Regs.AQCSFRC.bit.CSFA = 2; /* Forcing a continuous High on output A of EPWM1 */\
\
EPwm2Regs.AQCSFRC.bit.CSFA = 1; /* Forcing a continuous Low on output A of EPWM2 */\
EPwm2Regs.AQCSFRC.bit.CSFB = 2; /* Forcing a continuous High on output B of EPWM2 */\
\
EPwm3Regs.AQCSFRC.bit.CSFA = 1; /* Forcing a continuous Low on output A of EPWM3 */\
EPwm3Regs.AQCSFRC.bit.CSFB = 1; /* Forcing a continuous Low on output B of EPWM3 */\
}\
...