Getting Started

(lily) #1

Chapter 7: Microcontroller Interrupts and Timers


he reason we usually see Timer/Counter hooked together is that the
Timer/Counter peripheral keeps time by counting pulses. The pulses can come
from a synchronous periodic source providing an accurate time count, or the
nous non-periodic source providing an accurate
unt of the input pulses. In the first case we could be counting pulses from the
32.768 kHz watch crystal and keep accurate time. In the second case we could be
n ght beam interrupter circuit and keep an accurate count
entering a door and breaking the light beam.


he AT hree Timer/Counters, two 8 bit and one 16 bit. A timer
overflows when it counts up to its maximum value (255 for the 8 bit and 65535
for the 16 bit devices) and resets to 0. We can get the Timer to overflow at lower
values by putting a value in the OCR, Output Compare Register, for the specified
value with the count and when they match it
ill set a flag or throw an interrupt. It can also be set to overflow to 0 on a match.


capture events, where a change on a pin
mer to save the count when the event occurred. This input capture
ount c easure the width of external pulse. If the external pulses are
periodic, we have a frequency counter.


independent of program execution and there are three
ays fo ram to monitor and react to Timer/Counter events.


  1. the level of output pins.


The clo
ock and the multiplexer selects which of the


the system clock.

T

pulses can come from an asynchro
co


counti g pulses from a li
of the number of people


T mega169 has t


timer and that timer will compare the
w


The tim
will cause the ti


ers can be configured for input

c an be used to m


The Timer/Counter runs
w r the prog



  1. Poll the overflow flags.

  2. Break program execution with an interrupt.
    Let the timer automatically change


ck of the Timer/Counters uses a prescaler connected to a multiplexer The
prescaler is used to divide the input cl
divided signals is used as the input clock. The clock source for the prescaler can
be an external clock such as the 32.768 kHz crystal or it can use

Free download pdf