sandeepmistry / arduino-nRF5

Arduino Core for Nordic Semiconductor nRF5 based boards
Other
873 stars 278 forks source link

millis() reset every ~36 hours #417

Open 0x416c6578 opened 3 years ago

0x416c6578 commented 3 years ago

Setting NRF_RTC1->TASKS_TRIGOVRFLW = 1; and the internal overflows variable in delay.c to 255 will cause millis to reset. This is because the overflows variable is ANDed with 0xff so any overflow above 255 is reset to 0, meaning that after 255((2^24)(1/32768)) = 130560 seconds or 36.2 hours, the overflow variable is reset and millis drops to 0. This can be fixed by removing the & 0xff on overflows = (overflows + 1) & 0xff; in https://github.com/sandeepmistry/arduino-nRF5/blob/master/cores/nRF5/delay.c so that the overflows variable can increment past 255.