On Paper: Timers and Counters for AVR Microcontrollers Explained
There is an internal clock in the microcontroller. By default, this clock ticks one million times per second (1 megahertz or 1 MHz). The AVR microcontroller that you see in these videos actually ticks 8 million times per second (8 MHz), but the fuses in the microcontroller are set for an 8 prescaler to this clock. So, for every 8 ticks, the clock ticks by one.
TCNT1 is the 16-bit counter. TCNT0 is the 8-bit counter. TCNT counts with the internal clock. Of course, since these are 8 and 16 bits, TCNT cannot count up to one million, but can count up to 255 for 8 bit and 65535 for 16 bit.
You can have the timer/counter react with a signal coming in from a pin, or have it send a signal to a pin at ever set interval.
The internal clock can also be omitted and two other pins of the microcontroller XTAL can be connected to another clock source, like a crystal or a ceramic resonator. This is usually done to get a more precise clock since the internal clock has a + or - 10% error.
Comments and Additional Information
Have some code to share? Or additional information? Respond here:
You need to be logged in to save a response on this page. The response must be constructive, helpful, supplimentary or to correct the existing video, code or narrative content.