Hi,
We are working with MPC5744P and we have got an error flag (ERRCMP flag in CTU_EFR register) which appears as soon as we initialize CTU. The configured trigger signal for the CTU is I1_RE which corresponds with FlexPWM0 submodule 0 VAL0. If we change TGSCCR register to 4801 or less value (< FlexPWM_0.SUB[0].VAL1), ERRCMP error flag is set when CTU is initialized and once per PWM cycle. But if we change TGSCCR value to 5000 (or > FlexPWM_0.SUB[0].VAL1) ERRCMP error flag is set just when CTU is initiated.
Is there any way of avoiding this error first time CTU is initalized?
In Main program, we initialize CTU first and then we initialize FlexPWM as you can see in included functions at the end of the message.
Thanks in advance for your help.
Maite
void CTU_Init(void)
{
CTU_0.TGSISR.R = 0x00000004; // I1_RE (Input1: FlexPWM0 SubMod0 VAL0 VAL2 VAL4
CTU_0.THCR1.R = 0x00000061; //Enable Triger 0 and set to ADC
CTU_0.TCR[0].R = 1; // For triggering single conversion on ADC0
CTU_0.TGSCCR.R = 5000; // end value
CTU_0.TGSCRR.R = 0; // initial value
CTU_0.TGSCR.R = 0x0100; // Toggle mode for external trigger
//===== Set ADC messages 2 CHANNELS=====
CTU_0.FTH.R = 0x00000001; // set FIFO 0 threshold to 1, overflow is set when 2 results comes Max 8 bits
CTU_0.CLR[0].A.R = 0x4000; // Command 0 - first command in command sequence, sample ADC1-CH0, result to FIFO0
CTU_0.CLR[1].A.R = 0x0001; // Command 1 - next command in command sequence,sample ADC1-CH1, result to FIFO0
CTU_0.CLR[2].A.R = 0x4000; // stop the sequence, first command of second sequence which is not started
CTU_0.CLR[0].A.B.SU = 1; // ADC_1 ch0
CTU_0.CLR[1].A.B.SU = 1; // ADC_1 ch1
CTU_0.FCR.R = 0x00000004; // FIFO 0 threshold overflow interrupt enable
CTU_0.CR.R = 0x0003; // General reload and TGS input selection reload
if(CTU_0.EFR.B.ERRCMP == 1)
{
CTU_0.EFR.B.ERRCMP = 1;
SIUL2.GPDO[LED1].R = ~SIUL2.GPDO[LED1].R;
}
}
void FlexPWM_Init(void)
{
FlexPWM_0.OUTEN.R = 0x110;
//----- control register ---
FlexPWM_0.SUB[0].CTRL1.R = 0x0400;
FlexPWM_0.SUB[0].CTRL2.R = 0x0000;
FlexPWM_0.SUB[0].TCTRL.R = 0x0001; // VAL0 reg determine OUT_TRIG0 generation
//----- INIT, VAL0, VAL1, VAL2, VAL3 -----
FlexPWM_0.SUB[0].INIT.R = 0; // init value
FlexPWM_0.SUB[0].VAL1.R = 4802; // end value
FlexPWM_0.SUB[0].VAL2.R = 0; // PWM A0 rising edge
FlexPWM_0.SUB[0].VAL3.R = 800; // PWM A0 falling edge
FlexPWM_0.SUB[0].VAL0.R = 0;
//----- interrupt enable register ---
FlexPWM_0.SUB[0].INTEN.R = 0x1000; //reload
//========== LDOK (reload) & RUN (run PWMs) =========
FlexPWM_0.MCTRL.B.LDOK = 0x1; //submodule 0
FlexPWM_0.MCTRL.B.RUN = 0x1; // Submodule 0 PWM0 generator enabled
}
Hi Petr,
Thanks for your answer. We are working with reference manual Rev 5 which do not include this paragraph. Could you include Rev 6 pdf from the reference manual in this post please? As it is imposible to get it from web (web link is not working well as it goes to Rev 5 from reference manual)
Many thanks,
Maite
Thanks!!
Regards,
Maite
Hi Maite,
This flag is set each time the CTU becomes clocked. See this info from the RM
So just clear this flag during initialization.
BR, Petr