Flaw in ATmega4809 TCA Clock Prescaler

While working toward a final draft of the Arduino Nano Every book I noticed that I didn’t have an example using events and Timer/Counter A. So I wrote a demonstration program which failed to run. Diagnosing the problem I came across a design flaw in the ATmega4809 microcontroller.

Timer/Counter A has a clock prescaler that is connected not only to Timer/Counter A but is also the prescaler used by the four Timer/Counter B. When using the event system to gate the Timer/Counter A counter, such as to measure pulse periods, the prescaler connection to Timer/Counter B is gated as well. This means that the system time functions (such as micros, millis, and delay) won’t work and the PWM outputs driven by TCB channels won’t work either. The other event controlled modes also seem to mess up the prescaler, but I’ve been unable to conclude exactly how they misbehave.

This basically means that the event input for Timer/Counter A cannot be used if any Timer/Counter B channel is using the prescaler. Perhaps Microchip will fix this with a future mask revision, but I wouldn’t get my hopes up.