I'm trying to diplay the total time my Esp32 has been running, on a LCD display.
I'm using the esp_timer_get_time() function which gives back the running time in microseconds.
I'm reading that value into a variable called microSecondsSinceBoot, and the data type is a long, which should be 64 bit, and shouldn't overflow for something like 290 million years.
Yet, something strange happens consistently at 35 minutes, 48 seconds. (35:47 is still correct), instead of displaying 00:35:48 it goes to something like 00:35:-4000 (don't remember the exact number, but anyway a negative number in the thousands).
This is my code:
Code: Select all
void upTime(void *parameter)
{
for (;;)
{
microSecondsSinceBoot = esp_timer_get_time();
previousSecondsSinceBoot = secondsSinceBoot;
secondsSinceBoot = microSecondsSinceBoot / 1000000;
timeSeconds += (secondsSinceBoot - previousSecondsSinceBoot);
if (timeSeconds > 59)
{
timeSeconds = 0;
timeMinutes += 1;
}
if (timeMinutes > 59)
{
timeMinutes = 0;
timeHours += 1;
}
if (timeHours > 23)
{
timeHours = 0;
}
sprintf(uptimeBuffer, " %02i:%02i:%02i ", timeHours, timeMinutes, timeSeconds);
bootTimePrinted = false;
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
Thanks!
Jens