Tool/software: Code Composer Studio
Hi to everyone,
I have three cascaded ePWM modules, which they are synchronized -and dephased- with one another. I want the first PWM to be synchronized to software
More specifically: everytime the angle produced by a PLL resets, I want to create an software event in ePWM1, which then will synchronize accordingly the other two ePWMs.
The PLL itself and the resetting function are programmed in C++.
I have also written a class for setting up the PWMs. Voila:
Firing::Firing(volatile struct EPWM_REGS *APwmRegs, unsigned int PWM_PRD, unsigned int PWM_PHASE, bool PWM_SYNC) { ThePwm=APwmRegs; EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0; // Disable ePWM clocks EDIS; ThePwm->TBPRD=PWM_PRD; // Set timer period ThePwm->TBCTR = 0; // clear-reset TB counter to 0 ThePwm->CMPA.half.CMPA = ThePwm->TBPRD; // initial duty ratio for CMPA (RS+,ST+,TR+) ThePwm->CMPB = 0; // initial duty ratio for CMPB (RS-,ST-,TR-) ThePwm->TBPHS.half.TBPHS = PWM_PHASE; // phase register value ThePwm->TBCTL.bit.CTRMODE=TB_COUNT_UP; // set triangular waveform as count up ThePwm->TBCTL.bit.PHSEN = TB_ENABLE; // enable loading phase register value ThePwm->TBCTL.bit.SYNCOSEL= TB_SYNC_IN; // synchronization ThePwm->TBCTL.bit.PRDLD=TB_SHADOW; // enable shadow register for period register ThePwm->CMPCTL.bit.SHDWAMODE=CC_SHADOW; // enable Shadows for CMPA ThePwm->CMPCTL.bit.SHDWBMODE=CC_SHADOW; // enable Shadows for CMPB ThePwm->CMPCTL.bit.LOADAMODE=CC_CTR_ZERO; // load reference for ePWMA - on ZERO ThePwm->CMPCTL.bit.LOADBMODE=CC_CTR_ZERO; // load reference for ePWMB - on ZERO //TBCLK = SYSCLKOUT / (HSPCLKDIV * CLKDIV) = 300MHz / (12 * 8) = 3.125MHz ThePwm->TBCTL.bit.HSPCLKDIV = 0x6; //HSPCLKDIV: divide by 12 ThePwm->TBCTL.bit.CLKDIV = 0x3; // CLKDIV: divide by 8 // disable action qualifier - AQ_NO_ACTION ThePwm->AQCTLA.bit.CAU = AQ_NO_ACTION; ThePwm->AQCTLB.bit.CBU = AQ_NO_ACTION; ThePwm->ETSEL.bit.INTEN = 1; // enable ePWM Interrupts ThePwm->ETPS.bit.INTPRD = ET_1ST; // number of events needed to generate an interrupt (here: every event) ThePwm->ETSEL.bit.INTSEL = ET_CTR_ZERO; // when active trigger interrupt at ZERO ThePwm->ETCLR.bit.INT = 1; // clear the INT flag if any EALLOW; SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // Enable ePWM clocks EDIS; }
void Firing::Synchronize(bool zeroCrossing_) { ThePwm->TBCTL.bit.SWFSYNC = zeroCrossing_; //zero crossing is a function that returns 1 or 0 every time the angle resets (from 2pi to 0 again) }
Could you please indicate possible reasons for which I don't manage to create the SWFSYNC event?