Repository navigation
atmega: add opt-in Timer0 time HAL for ATmega328P - #1087
Conversation
|
Wait so you sat there for an entire minute counting the number of times the LED blinked? |
|
Guilty. Most suspenseful minute of my week :) It only catches gross errors though (a wrong prescaler or tick size is 2x off), so I measured it properly too. A test firmware prints
Both methods agree on each board, so Happy to share the firmware and the script if they're useful. |
|
How much of that comment was generated by an LLM? |
|
I usually use LLMs to help write my comments, as I'm not very good at writing in English. I ran the tests and measurements myself on both boards, and the numbers are copied from the output. |
|
Yeah we know you're working with an LLM. That is fine (imo), as long as you're not doing drive-by slop PRs. These have been rather good quality, and you've been testing on hardware (which is important) |
|
That's okay, but honestly I'd prefer you use the language you're most comfortable with. It puts a little more work on us having to put it through a translator, but I'd rather read a translation of how you express yourself over a machine talking for you. |
Adds
hal.timefor the ATmega328P using Timer0. Part of #1069; the timer is opt-in, as discussed there.init,get_time_since_boot,sleep_msandsleep_us. Time is measured frominit.hal.time.timer0_overflowforTIMER0_OVF, callsinitand enables interrupts.initchecks the handler registration at compile time. AVR does not use HALdefault_interrupts, so registration is explicit. Without initialization, Timer0 remains available for PWM on D5/D6.find_us_per_tick.sleep_msuses 1 ms chunks to avoid runtime 64-bit multiplication. Sleeps require interrupts enabled. The overflow handler must run within one overflow period: 1.024 ms at 16 MHz or 2.048 ms at 8 MHz.blinky_timefor the Nano, Pro Mini 3.3 V and RF-Nano V3.Hardware-tested on an Emakefun RF-Nano V3.0 (16 MHz) and an Arduino Pro Mini 3.3 V (8 MHz). The example toggles the LED with
sleep_ms(500)between toggles. On each board, I counted 60 LED turn-ons over a manually timed 60-second interval.Inspected the example ELFs: vector 16 points to the Timer0 overflow handler, which returns with
reti, and no compiler_rt helpers are linked.