RTC API errors on SC13048Q

We have been having interesting RTC clock issues on some boards.

Sometime this works just fine, and we can update the RTC, but sometimes it fails.
Our board does NOT have a clock crystal.

The current RTC time on this board with the Error is 08/30/2024 00:04:08.

Also, most of the time, the following code takes a few seconds to complete:

     var rtc = RtcController.GetDefault();

But, sometimes there is no delay.

======================================================
Here’s the code:

namespace RealTimeClock
{
    internal class Program
    {
        static void Main()
        {
            RtcController rtc = RtcController.GetDefault();

            DateTime MyTime = new DateTime(2024, 8, 30, 15, 10, 20);
            rtc.Now = MyTime;
            SystemTime.SetTime(rtc.Now);

            Debug.WriteLine($"RTC set to {rtc.Now.ToString("M/d/yyyy HH:mm:ss")}");
        }
    }
}


may sound silly, but I would try a short sleep before settime call.

And getcontroller…

Also, is there any special procedure for activating the internal SC13… RTC oscillator, or is it on by default?

1 Like
            DateTime MyTime = new DateTime(2024, 8, 30, 15, 10, 20);
            rtc.Now = MyTime;
            SystemTime.SetTime(rtc.Now);

Change to:

var rtc = RtcController.GetDefault();

// make sure RTC battery still good.
DateTime MyTime = new DateTime(2024, 8, 30, 15, 10, 20);
var newDt = RtcDateTime.FromDateTime(MyTime );
rtc.SetTime(newDt);
///rtc and system time are different, you may need update system time
 SystemTime.SetTime(MyTime );

Yeah, I tried that too before posting.
Still fails.

Dat,
Here’s some more clues…

The RTC is NOT running !
But the System clock is.

I executed this on the same board from Visual Studio Immediate Window.
?DateTime.Now.Ticks
636188257822428706
?DateTime.Now.Ticks
636188257840136941
?rtc.Now.Ticks
638605730480000000
?rtc.Now.Ticks
638605730480000000
?rtc.Now.Ticks
638605730480000000
?DateTime.Now.Ticks
636188257985426954

And this line … take about 4 seconds to execute:

var rtc = RtcController.GetDefault();

The board has USB power and a lithium battery.
Power to Vdd is 2.803 Vdc

VBat pin is not connected

Same board … if I disconnect all power and then reset the application.
It works ! RTC can be set and it runs … for a while.

The RTC seems to be getting into an unstable state.

Dat,
CORRECTION !!

The RTC is running. It is running at about 1/10 the speed.
It will increment 6 seconds for every minute.

Seems like the clock source is not set correctly in firmware.

After Power On, the RTC runs just fine. Then after a while it will switch to 1/10th the speed. And then later stop running completely.

Let me know if you need to me to run some tests or debugging code.

– Don

Hi, we just tested again, no issue. Rtc and PC always have same time speed.
As the test below, RTC time are same as PC, after ~ 20 minutes disconnected power source.

~ 6 minutes you see System Time just mean 6minute from last boot.

After Power On, the RTC runs just fine. Then after a while it will switch to 1/10th the speed. And then later stop running completely.

Seems to me your battery is bad. Is this custom board or our dev board?

If our dev board that using big cap, you need to charge the cap if it is low. That cap can hold only ~ 2days, if I remember correctly. There is command to charge the cap.

rtc.SetChargeMode(BatteryChargeMode.Fast);

RTC runs incorrectly if battery is lower than needed.

And here is 17 mins from last boot. Nothing wrong with RTC.

If this is custom board, make sure RTC parts are good or same as our parts.

Dat,
I’m confused here … what do you mean by “RTC parts”.
Do you mean 32kHz crystal? There is no 32kHz crystal on the board.

Is there some code that needs to be run to tell TinyCLR to use the RC clock instead of a 32kHz crystal ???

This is a custom board. VBAT is left open.
Battery is good. Power to MCU is good.

RTC runs fine until …
TinyCLR is shutdown and restarted numerous times.

Shutdown via :

            Power.WakeupEdge = WakeupEdge.Rising;
            Power.Shutdown(true, DateTime.Now + TimeInterval);

WakeUp is via PA0 or RTC

After a while it randomly fails.
Once the RTC stops running or is running very slowly, it will give the errors I stated in the original post. Only fix is to COMPLETELY disconnect all power and restart. RESET does not fix the problem. Shutdown does not fix the problem.

Also … why does it take 4 seconds to talk to the RTC clock ?

            var rtc = RtcController.GetDefault();

During the 4 seconds, TinyCLR misses interrupts, threads don’t run, etc.

Hi, I thought your setup has 32k crystal.

try version 2.3.0.2000:

https://ghistorage.blob.core.windows.net/downloads/TinyCLR/Firmwares/SITCore/SITCore-SC13-Firmware-v2.3.0.2000.ghi

  • Fixed internal RC clock.
  • Reduced 4 seconds to 1 seconds. This is timeout when not detect 32.768 crystal.

A note here is, the fix uses TIM16 to calibrate LSI clock, and TIM16 is PB8 pwm. if you are using PWM on this pin, you need call RtcController.GetDefault() before initialize pwm. I don’t see any wrong if call it right after Main(), all should be fine.

Also, it is using RC clock so still not perfect, I am seeing time is different 1-2 seconds after 10-20 minutes.

So there is

rtc.Calibrate(xxx); 

xxx: from [-510…510] pulses.
each pulse: 0.030517578125ms.
You can add / remove xxx pulses every 32 seconds.

After a while it randomly fails.
Once the RTC stops running or is running very slowly, it will give the errors I stated in the original post.

I could not reproduce this issue. I need simple project that I can reproduce the issue. But hopefully the new version fix it.

Let us know the result.