I'm trying to have two blocks of 3 PWMs each. The first 3 should be synchronized to each other while the other 3 should be shifted by a half period. For this purpose I decided to manipulate the PWM_INIT_MACRO() from the example PM_Sensorless.
The 3d ePWM from the first block should generate a synchronization event when it reaches the Period-Value (in Up-Down count mode). At this point, the following PWMs load 0 to their counter and will be delayed by 180°.
But right after execution of the PWM_INIT_MACRO() both SYNCOSEL and PHSEN are 0, so the changes are not applied and the code doesn't work. If I apply the changes manually in debug mode, it works. Why are the values not applied to the registers, or are there any other write-commands that cause a reset of the register?
The Code I use is here below, it's almost identical to the example code:
#define PWM_INIT_MACRO(m) \
/* Setup Sync*/ \
m->PwmARegs->TBCTL.bit.SYNCOSEL = 0; /* Pass through sync-signal to next ePWM*/ \
m->PwmBRegs->TBCTL.bit.SYNCOSEL = 0; /* Pass through sync-signal to next ePWM*/ \
m->PwmCRegs->TBCTL.bit.SYNCOSEL = 2; /* Sync-Event for next ePWM at Counter = Period. Following ePWMs will have 50% Phase delay */ \
\
/* Allow each timer to be sync'ed*/ \
m->PwmARegs->TBCTL.bit.PHSEN = 1; /*Enable Phase Load */ \
m->PwmBRegs->TBCTL.bit.PHSEN = 1; \
m->PwmCRegs->TBCTL.bit.PHSEN = 1; \
\
/* Init Timer-Base Period Register for EPWM1-EPWM3*/ \
m->PwmARegs->TBPRD = m->pwm.PeriodMax; \
m->PwmBRegs->TBPRD = m->pwm.PeriodMax; \
m->PwmCRegs->TBPRD = m->pwm.PeriodMax; \
\
/* Init Timer-Base Phase Register for EPWM1-EPWM3 (Value loaded to Counter on Sync-Event)*/ \
m->PwmARegs->TBPHS.half.TBPHS = 0; \
m->PwmBRegs->TBPHS.half.TBPHS = 0; \
m->PwmCRegs->TBPHS.half.TBPHS = 0; \
\
/* Init Timer-Base Control Register for EPWM1-EPWM3*/ \
m->PwmARegs->TBCTL.all = PWM_INIT_STATE; /* Count Up-Down, After Sync start with up Count,... */ \
m->PwmBRegs->TBCTL.all = PWM_INIT_STATE; \
m->PwmCRegs->TBCTL.all = PWM_INIT_STATE; \
\
/* Init Compare Control Register for EPWM1-EPWM3*/ \
m->PwmARegs->CMPCTL.all = CMPCTL_INIT_STATE; /*Load from Shadowed Registers when Counter is at 0*/ \
m->PwmBRegs->CMPCTL.all = CMPCTL_INIT_STATE; \
m->PwmCRegs->CMPCTL.all = CMPCTL_INIT_STATE; \
\
/* Init Action Qualifier Output A Register for EPWM1-EPWM3*/ \
m->PwmARegs->AQCTLA.all = AQCTLA_INIT_STATE; /* SET when counting Up, CLEAR when counting down*/ \
m->PwmBRegs->AQCTLA.all = AQCTLA_INIT_STATE; \
m->PwmCRegs->AQCTLA.all = AQCTLA_INIT_STATE; \
\
/* Init Dead-Band Generator Control Register for EPWM1-EPWM3*/ \
m->PwmARegs->DBCTL.all = DBCTL_INIT_STATE; /* Enable Dead-Band Module, Dead-Band (both signals low during this time) */ \
m->PwmBRegs->DBCTL.all = DBCTL_INIT_STATE; \
m->PwmCRegs->DBCTL.all = DBCTL_INIT_STATE; \
\
/* Init Dead-Band Generator for EPWM1-EPWM3*/ \
m->PwmARegs->DBFED = DBCNT_INIT_STATE; /* Set number of delay-counts between switching edges */ \
m->PwmARegs->DBRED = DBCNT_INIT_STATE; \
m->PwmBRegs->DBFED = DBCNT_INIT_STATE; \
m->PwmBRegs->DBRED = DBCNT_INIT_STATE; \
m->PwmCRegs->DBFED = DBCNT_INIT_STATE; \
m->PwmCRegs->DBRED = DBCNT_INIT_STATE; \
\
/* Init PWM Chopper Control Register for EPWM1-EPWM3*/ \
m->PwmARegs->PCCTL.all = PCCTL_INIT_STATE; /* No PWM-Chopping*/ \
m->PwmBRegs->PCCTL.all = PCCTL_INIT_STATE; \
m->PwmCRegs->PCCTL.all = PCCTL_INIT_STATE; \
\
EALLOW; /* Enable EALLOW */ \
\
/* Init Trip Zone Select Register*/ \
m->PwmARegs->TZSEL.all = TZSEL_INIT_STATE; \
m->PwmBRegs->TZSEL.all = TZSEL_INIT_STATE; \
m->PwmCRegs->TZSEL.all = TZSEL_INIT_STATE; \
\
/* Init Trip Zone Control Register*/ \
m->PwmARegs->TZCTL.all = TZCTL_INIT_STATE; \
m->PwmBRegs->TZCTL.all = TZCTL_INIT_STATE; \
m->PwmCRegs->TZCTL.all = TZCTL_INIT_STATE; \
\
EDIS; /* Disable EALLOW*/