Posted on March 03, 2005 at 03:23I have problem to get an accurate RTC under LPWFI !!!!!! The RTC is setup to get an interrupt at every 1/1024 sec, about 1ms. I output high/low signal on GPIO1.14 according to every RTC interrupt with the following code to measure the period between two RTC interrupts. The measured period is 50ms, instead of 1ms. WHY ????? main() { u32 Myprescaler; // RTC init Myprescaler = 31; RTC_PrescalerConfig ( Myprescaler ); RTC_AlarmConfig(10); RTC_FlagClear ( RTC_OWIR ); RTC_FlagClear ( RTC_AIR ); RTC_FlagClear ( RTC_SIR ); RTC_FlagClear ( RTC_GIR ); EIC_IRQChannelConfig( RTC_IRQChannel, ENABLE ); EIC_IRQChannelPriorityConfig( RTC_IRQChannel, 1); EIC_IRQConfig( ENABLE ); RTC_ITConfig( RTC_SIT | RTC_AIT| RTC_GIR, ENABLE ); // init LED1 (red) GPIO_Config( GPIO1, BIT14, GPIO_OUT_PP); GPIO_BitWrite( GPIO1, BIT14, 0); PCU_EnterWFI( WFI_EXTERNAL, ENABLE, ENABLE); while(1); } u8 bRedLedOn = 0; void RTC_IRQHandler(void) { if ( !bRedLedOn) { GPIO1->PD |= BIT14; bRedLedOn = 1; } else { GPIO1->PD &= ~BIT14; bRedLedOn = 0; } if ( RTC_FlagStatus ( RTC_SIR ) == SET ) { RTC_FlagClear ( RTC_SIR ); RTC_FlagClear ( RTC_GIR ); } if ( RTC_FlagStatus ( RTC_AIR ) == SET ) { /*GPIO0->PD = ~GPIO0->PD;*/ /*LED_Flashing2(0x02);*/ RTC_FlagClear ( RTC_AIR ); RTC_FlagClear ( RTC_GIR ); } }
I can get an accurate 1ms RTC interrupt under RUN mode. However, no way to get RTC accurate in LPWFI mode with CK_AF. There seems a limitation that RTC external clock should be at least 4 times smaller than PCLK2. So, it seems that accurate RTC under LPWFI with CK_AF clock is mission impossible since PCLK2 is equal or smaller than RTC clock in this situation... Any solution ???? Btw, if I wanna get an 1/1024 sec interrupt on 32768Hz RTC clock, which prescaler value should I use ? 32 or 31 ? Thanks !! [ This message was edited by: Shinn on 04-03-2005 03:05 ]
Here is the explanation for your problem: - The RTC interrupt exits the MCU from LPWFI mode (32KHz) to RUN mode and when exiting from LPWFI, the system clock (RCLK) will be kept 32KHz. In the RTC interrupt routine, you are clearing the RTC interrupt flags, but with the 32KHz as system clock these flags will be not cleared.this because the RTC registers will need PCLK > 4 times the RTC clock (32KHz) to be accessed. So the solution for your case is to return to the PLL clock before clearing the RTC flags: RCCU_RCLKSourceConfig(RCCU_PLL1_OutPut); Best regards. :p :p
Posted on March 04, 2005 at 11:20I did put the system clock to CK (8MHz) before entering ISR... So.. it seems not the solution... ?? RCCU_RCLKSourceConfig( RCCU_CLOCK2); RCCU_MCLKConfig( RCCU_DEFAULT); RCCU_FCLKConfig( RCCU_DEFAULT); RCCU_PCLKConfig( RCCU_DEFAULT);
You should return to the PLL clock when entering in the RTC interrupt routine. Because when entering in the LPWFI mode the system clock will change to 32KHz and will remain 32KHz after exit. Regards, Hich ;)
Posted on March 04, 2005 at 12:03I had use RCCU_RCLKSourceConfig( RCCU_CLOCK2) instead of using PLL to get high system clock before entering interrupt service routine. Since using CLK2 eliminate the time waiting for PLL to lock... This result should be the same as putting back PLL for system clock, doesn't it ?
Posted on March 04, 2005 at 12:56Oh... The ''before'' I mean is in ASM code put in 71x_vect.s before RTC_IRQHandler() is branched to. So, it's the same as you said ''put in the begining of RTC_IRQHandler()''