cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate number of RTC ticks MCU spends in STOP2 mode

deckhard
Associate III

I want to calculate the actual time the CPU spends in STOP2 mode.

I wake up the MCU either by RTC Alert or LPUART.

The issue is more relevant to LPUART wake use case, because it could happen before the RTC alert expires.

I'm using RTC with LSI which continues to work in low power modes.

Is there a proper way to save the RTC time before and after entering the stop mode?

The RTC is configured to scale from 488 µs to 32s.

So I want the timestamp calculation to support both milliseconds and seconds.

How can I achieve that?

Thanks All!!!

13 REPLIES 13
Uwe Bonnes
Principal III

What about using the LP-Timer?

Yes I'm using a battery.

Good idea.

JW

This the calculation I'm using:

 int duration = (int)((int)rtcStart.SubSeconds-(int)rtcEnd.SubSeconds)*1000;

 duration = ((int)rtcEnd.Seconds-(int)rtcStart.Seconds)*1000+duration/(int)rtcEnd.SecondFraction;

looks like it works.