Hi,
I observe the following interesting behaviour:
First, I have a PWM control task that is splitted in two parts, and so I use two ADC conversions: One at the zero event (TBCTR = 0) and another at the period event, while PWM counter mode of the two modules used is UP-DOWN. Works fine, I get 2 ADC interrupts per period (ratio 1:1).
Second, I have to synchronize my PWM to an external signal. I use a third EPWM module as source for an internal sync signal that is compared to the external signal using ECAPs. This third EPWM (EPwm1) generates the SYNCI signals for the other two EPWMs (7 and 8). Synchronisation is done by an adjustment of the period of Epwm1, and the sync chain (see Figure 13-7. Time-Base Counter Synchronization Scheme in the TRM SPRUHX5E.pdf) forwards the synchronisation to the other two modules. Also works fine.
However, as soon as the synchronisation runs (external signal on), I get much less ADC conversions/interrupts on zero than on period, the ratio is now about 1/sqrt(2) : 1. Since I use TBPHS = 0, I expect that the ZERO event (generation) takes place in every cycle (TBCTR = TBPHS = 0!), but obviously it does not.
As a workaround, I used Epwm1 for the ADCSOC generation, and all is fine again.
I did not find any hint for this behaviour in the TRM.
Frank
Here some code snippets for explanation:
/* Time Base Control Register (TBCTL) - set counter mode, divider */
epwm_regs->TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; /* count up / down */
epwm_regs->TBCTL.bit.PHSEN = TB_ENABLE; /* enable phase loading */
epwm_regs->TBCTL.bit.PRDLD = 0; /* on CTR = 0 and SYNC */
epwm_regs->TBCTL.bit.SYNCOSEL = 0; /* SYNCO = SYNCI */
epwm_regs->TBCTL.bit.HSPCLKDIV = TB_DIV1; /* clock divs = 1 */
epwm_regs->TBCTL.bit.CLKDIV = TB_DIV1;
epwm_regs->TBCTL.bit.FREE_SOFT = 0x02; /* 0x02 = free run */
/* Time Base Control Register 2 (TBCTL2) */
epwm_regs->TBCTL2.all = 0x0000; /* default = 0 */
/* Time Base Counter Register (TBCTR) - clear counter */
epwm_regs->TBCTR = 0x0000;
/* Time Base Status Register (TBSTS) - clear events */
epwm_regs->TBSTS.bit.CTRMAX = 1;
epwm_regs->TBSTS.bit.SYNCI = 1;
/* Time Base Phase High (TBPHS) */
epwm_regs->TBPHS.all = 0x00000000;
This does not work for a synchronised EPWM module:
/* generate SOC A event on zero */
epwm_regs->ETSEL.bit.SOCAEN = 1; /* enable SOC on A group */
epwm_regs->ETSEL.bit.SOCASEL = 1; /* 1 = SOC on CTR = ZRO */