Thanks for correcting me
I did show the "mp_hal_ticks_ms()" overflow.
You showed that "time_ticks_us(void)" calls that function and reduces its overflow.
Before I read your answer I wrote a script that did show me experimentally where the overflow occurs. It used the method I posted yesterday allowing to execute a single MicroPython command on a ESP8266 from within a Linux command line using unix port MicroPython and mp.py:
viewtopic.php?f=15&t=233&p=31846#p31846
This is the script, it collects Linux epoch timestamps and ESP8266 utime.tick_us():
Code: Select all
#!/bin/bash
./micropython mp.py 192.168.4.1 import utime
t0=$((`date +%s`))
m0=`./micropython mp.py 192.168.4.1 utime.ticks_us'()' | sed "s/\r//"`
while true
do
ms=`./micropython mp.py 192.168.4.1 utime.ticks_us'()' | sed "s/\r//"`
s=$((`date +%s`))
echo $ms $((($s - $t0)*1000000 - ($ms - $m0)))
done
I did power cycle the ESP8266 and then started the command. Each while loop roughly takes a second to run. This is initial part of output, left column showing ESP8266 ticks_us(), and right column showing difference of Linux time and ESP8266 time:
Code: Select all
$ head -7 log.us.txt
18799977 1123105
19960828 962254
20780697 1142385
21807231 1115851
22712514 210568
23523399 399683
24673486 249596
$
Here is where the first overflow happened:
Code: Select all
$ head -1099 log.us.txt | tail -7
1070894263 1028819
1071673017 1250065
1072698003 1225079
1073659491 263591
806039 1074117043
1758467 1074164615
2700779 1074222303
$
The measured overflow corresponds to the code you did show since 1073741824 is 2**30.
So for ESP8266 as well as ESP32 ticks_us() overflows after 17 minutes, and ticks_ms() overflows after 12 days:
Code: Select all
>>> 2**30/(60*1000000)
17.8957
>>> 2**30/(24*60*60*1000)
12.4276
>>>
P.S:
The script did well despite the fact that bash script, starting/closing unix micropython, doing websockets connection to ESP8266 all are variables. The Linux to ESP8266 time differences are in rage 0.14s .. 1.97s only:
Code: Select all
$ head -1096 log.us.txt | cut -f2 -d\ | sort -n | head -3
147436
150795
158603
$ head -1096 log.us.txt | cut -f2 -d\ | sort -n | tail -3
1423278
1811667
1964856
$