AnsweredAssumed Answered

Problem of access FIFO of CTU with it works at dual conversion mode

Question asked by Max Lee on Mar 22, 2018
Latest reply on Dec 8, 2019 by 宝宝 闫



I'm trying to test the FlexPWM- CTU-ADC program. I configured the CTU for triggering on FlexPWM MRS and generate the Trigger0 to send 3 ADC dual conversion commands, and the results are saved in FIFO0. I set the threshold of FIFO0 to 5 and enable the FIFO0 overflow interrupt. Here is my code.


Configuration of CTU

#define CTU0_TGSISR 0x00000001 /* Input 0 Rising Edge Enable - FlexPWM0_MRS */
#define CTU0_TGSCR 0x0000          /* Triggered Mode */
#define CTU0_T0CR 0x0000             /* ADC and SGEN - same time with MRS*/
#define CTU0_TGSCCR 0x3E80       /* TGS Counter Compare Value - 16000 DEC - 100us */
#define CTU0_CLCR1 0x00000000   /* Trigger 0 Commands List 1st command address */
#define CTU0_THCR1 0x00000065   /* T0_E - T0_T2E - T0_ADCE */
#define CTU0_COTR 0x0064             /* Control ON-Time and Guard Time for external trigger */
#define CTU0_CTU0CR 0x0003         /* General Reload Enable - TGS Input Selection Register Reload Enable */
#define CTU0_CLR0 0x218B              /* PhaseA current ADC0_CH11 - PhaseB current ADC1_CH12 - FIFO_0 */
#define CTU0_CLR1 0x21C1              /* DC bus current ADC0_CH1 - DC bus voltage ADC1_CH14 - FIFO_0 */
#define CTU0_CLR2 0x20C0              /* Resolver sin ADC0_CH0 - Pot ADC1_CH6 - FIFO_0 */
#define CTU0_CLR3 0x4000               /* Last command */
#define CTU0_FTH 0x0005                 /* FIFO_0 threshold is 5 to accept 6 ADC results */
#define CTU0_FCR 0x0004                 /* FIFO 0 threshold overflow interrupt enable */


void FIFO0_ISR(void)
SIUL2.GPDO[42].R = 1;
uint32_t fifo_status;

fifo_status = CTU_0.FST.R & 0xf;

if (fifo_status == 4) // if overflow
Result[0] = (uint32_t)CTU_0.FR[0].R;
Result[1] = (uint32_t)CTU_0.FL[0].R;
Result[2] = (uint32_t)CTU_0.FR[0].R;
Result[3] = (uint32_t)CTU_0.FL[0].R;
Result[4] = (uint32_t)CTU_0.FR[0].R;
Result[5] = (uint32_t)CTU_0.FL[0].R;
FlexPWM_0.SUB[0].VAL3.R = (uint16_t)(Result[5] & 0xfff);      // use the value of pot to change the duty of PWM

FlexPWM_0.MCTRL.B.LDOK = 0x7;

CTU_0.CR.B.GRE = 1; // CTU General Reload Enable

if (fifo_status == 8) // if overrun
CTU_0.FST.R = 8; // clear overrun flag

SIUL2.GPDO[42].R = 0;


According to my configuration, there will be 6 ADC results saved in CTU_FIFO0 every time the overflow interrupt happened. And the last result entered in FIFO0 should be the value of the Pot(PE12).


When I debug the project, I find the FIFO0_FR0 has the result of ADC0_CH11 and FIFO0_FL0 has the result of ADC1_CH12, these are conform to my configuration. And somehow I found the overflow flag, overrun flag and full flag of FIFO0 are all set via the EmbSysRegister. And the PWM duty didn't change as I want.


I don't know whether I read the FIFO correctly. I'm quite confused about this FIFO and I want to know whether there are some methods to check the correctness of my code.


Thanks for any help.


Best regards,

Max Lee