21.08.2013 Views

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

Embedded Systems Design with the Atmel AVR Microcontroller Part II

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Motor Velocity<br />

Acceleration<br />

Period<br />

Pulse Width Modulated Signal<br />

Speed Profile<br />

Constant Speed<br />

Period<br />

6.5. OVERVIEW OF THE ATMEL TIMERS 145<br />

GND<br />

Deceleration<br />

Period<br />

Time<br />

Figure 6.4: The figure shows <strong>the</strong> speed profile of a DC motor over time when a pulse-width-modulated<br />

signal is applied to <strong>the</strong> motor.<br />

to continue to generate a 25% duty cycle signal, <strong>the</strong>n we must repeat <strong>the</strong> process indefinitely. Note<br />

that we are using <strong>the</strong> time for a free running counter to count from $0000 to $FFFF as one period.<br />

Now suppose we want to increase <strong>the</strong> duty cycle to 50% over 1 sec and that <strong>the</strong> clock is<br />

running at 2 MHz. This means that <strong>the</strong> free running counter counts from $0000 to $FFFF every<br />

32.768-milliseconds, and <strong>the</strong> free running counter will count from $0000 to $FFFF, approximately<br />

30.51 times over <strong>the</strong> period of one second. That is, we need to increase <strong>the</strong> pulse width from $4000<br />

to $8000 in approximately 30 turns, or approximately 546 clock counts every turn.<br />

6.5 OVERVIEW OF THE ATMEL TIMERS<br />

The <strong>Atmel</strong> ATmega164 is equipped <strong>with</strong> a flexible and powerful three channel timing system. The<br />

timer channels are designated Timer 0,Timer 1, and Timer 2. In this section, we review <strong>the</strong> operation<br />

of <strong>the</strong> timing system in detail. We begin <strong>with</strong> an overview of <strong>the</strong> timing system features followed by a<br />

detailed discussion of timer channel 0. Space does not permit a complete discussion of <strong>the</strong> o<strong>the</strong>r two<br />

timing channels; we review <strong>the</strong>ir complement of registers and highlight <strong>the</strong>ir features not contained

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!