While getting the time from the RTC on the ESP32, there are gaps in milliseconds

sema11
Posts: 2
Joined: Mon Mar 18, 2024 7:08 am

While getting the time from the RTC on the ESP32, there are gaps in milliseconds

Postby sema11 » Thu Jul 18, 2024 12:55 pm

Hello,

I am using a timer interrupt on the ESP32 that triggers every 1ms. However, when I read the millisecond time from the RTC, there are gaps between the millisecond values. Instead of the values increasing sequentially (e.g., 0.001, 0.002, 0.003, etc.), they are jumping (e.g., 0.001, 0.004, 0.007, etc.).

How can I solve this issue? I am open to any ideas that might help simplify the solution.

Thank you very much. :roll:



[Codebox]#include <Arduino.h>
#include <esp32-hal-timer.h>
#include <sys/time.h>
#include <ESP32Time.h>

ESP32Time rtc(0);

volatile bool timer_flag = false;
hw_timer_t *My_timer = NULL; // Donanım zamanlayıcı oluşturuluyor
volatile unsigned long millisCounter = 0; // Milisaniye sayacı

void IRAM_ATTR onTimer() // Zamanlayıcı kesme fonksiyonu oluşturuluyor
{
timer_flag = true;
millisCounter++; // Milisaniye sayacını her milisaniyede bir arttır
}

void setup()
{


Serial.begin(115200);
My_timer = timerBegin(1, 80, true); // Hesaplanan prescaler ile zamanlayıcıyı başlat
timerAttachInterrupt(My_timer, &onTimer, true);
timerAlarmWrite(My_timer, 1000, true); // Alarm her 10000 tikte bir (1 milisaniye @ 100 kHz)
timerAlarmEnable(My_timer); // Zamanlayıcı alarmını etkinleştir



}

void loop()
{
if (timer_flag)
{
timer_flag = false;

// RTC'den zaman bilgilerini al
int currentSecond = rtc.getSecond(); // Saniye bilgisini al
unsigned long currentMillis = rtc.getMicros()/100;

// Sadece gerekli bilgileri yazdır
Serial.print("Saniye: ");
Serial.print(currentSecond);
Serial.print(", Milis: ");
Serial.println(currentMillis); // Sadece milisaniye kısmını yazdır
}
}
[/Codebox]

Who is online

Users browsing this forum: No registered users and 67 guests