MCUdude / MiniCore

Arduino hardware package for ATmega8, ATmega48, ATmega88, ATmega168, ATmega328 and ATmega328PB
Other
1k stars 245 forks source link

328P - Inaccurate timings using internal oscillator #314

Closed jmanncontrel closed 3 months ago

jmanncontrel commented 3 months ago

Configuring an ATMEGA328P internal clock at anything below 4MHz (2MHz or 1MHz) seems to produce inaccurate timings (beyond the inherent inaccuracy of the internal oscillator) using delay() and delayMicroseconds() functions.

MCUdude commented 3 months ago

Well, delay and delayMicroseconds uses timer0 for timekeeping. If the internal oscillator is off, I'll assume it will heavily affect the timing functions as well. The delay and delayMicroseconds code is written by Arduino, and not me. I'll suggest performing an oscillator calibration (not something this core has built-in support for) or using an external oscillator instead, which is what I do for everything that requires somewhat accurate timing, like UART.