cancel
Showing results for 
Search instead for 
Did you mean: 

RTC accuracy under LPWFI ??

shinnlin
Associate II
Posted on October 24, 2005 at 05:46

RTC accuracy under LPWFI ??

13 REPLIES 13
shinnlin
Associate II
Posted on March 03, 2005 at 03:23

I 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 );

}

}

hichem2
Associate II
Posted on March 03, 2005 at 07:35

Hello Shinn,

I come just to test our RTC and you find attached an example when the RTC generate an interrupt every 1ms.

Hope that this can help you,

Don't hesitate for any clarification.

With regards,

Hich

[ This message was edited by: Hich on 03-03-2005 12:08 ]

________________

Attachments :

rtc.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I13K&d=%2Fa%2F0X0000000bmF%2FSpT1WWIZtQHV17SGxK83wZQ9_CwBgGHzVVFlRnb9g78&asPdf=false
shinnlin
Associate II
Posted on March 03, 2005 at 22:31

Thank you, Hich.

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 ]

hichem2
Associate II
Posted on March 04, 2005 at 11:07

Hi Shinn,

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

shinnlin
Associate II
Posted on March 04, 2005 at 11:20

I 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);

hichem2
Associate II
Posted on March 04, 2005 at 11:49

hi Shinn,

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 ;)

shinnlin
Associate II
Posted on March 04, 2005 at 12:03

I 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 ?

hichem2
Associate II
Posted on March 04, 2005 at 12:19

Shinn,

You have to include the line:

''RCCU_RCLKSourceConfig( RCCU_CLOCK2);''

just in the beginning of the RTC interrupt routine not before.

Regards :D

shinnlin
Associate II
Posted on March 04, 2005 at 12:56

Oh... 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()''