CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register...

147
Timers and Counters CP316 Timers and Counters Terry Sturtevant Wilfrid Laurier University December 10, 2019 Terry Sturtevant CP316 Timers and Counters

Transcript of CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register...

Page 1: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

CP316Timers and Counters

Terry Sturtevant

Wilfrid Laurier University

December 10, 2019

Terry Sturtevant CP316 Timers and Counters

Page 2: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pinsprescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 3: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. counters

A timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pinsprescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 4: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external events

size (i.e. number of bits)output pinsprescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 5: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)

output pinsprescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 6: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pins

prescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 7: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pinsprescaler

start/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 8: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pinsprescalerstart/stop

interrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 9: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timers and Counters

timers vs. countersA timer counts clock pulses; a counter counts external eventssize (i.e. number of bits)output pinsprescalerstart/stopinterrupt flag

Terry Sturtevant CP316 Timers and Counters

Page 10: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAXmaximum value the timer can reachTOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 11: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOM

value from which the timer startsMAXmaximum value the timer can reachTOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 12: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer starts

MAXmaximum value the timer can reachTOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 13: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAX

maximum value the timer can reachTOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 14: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAXmaximum value the timer can reach

TOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 15: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAXmaximum value the timer can reachTOP

highest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 16: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAXmaximum value the timer can reachTOPhighest value in the timer count sequence

depending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 17: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Definitions

BOTTOMvalue from which the timer startsMAXmaximum value the timer can reachTOPhighest value in the timer count sequencedepending on mode, can be less than or equal to MAX

Terry Sturtevant CP316 Timers and Counters

Page 18: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n inputOCnxOutput compare pin x for timer nICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 19: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

Tn

Timer n inputOCnxOutput compare pin x for timer nICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 20: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n input

OCnxOutput compare pin x for timer nICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 21: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n inputOCnx

Output compare pin x for timer nICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 22: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n inputOCnxOutput compare pin x for timer n

ICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 23: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n inputOCnxOutput compare pin x for timer nICPn

Input capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 24: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Pins

TnTimer n inputOCnxOutput compare pin x for timer nICPnInput capture pin for timer n

Terry Sturtevant CP316 Timers and Counters

Page 25: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow nOCFnxOutput compare match x for timer nICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 26: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVn

Timer overflow nOCFnxOutput compare match x for timer nICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 27: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow n

OCFnxOutput compare match x for timer nICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 28: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow nOCFnx

Output compare match x for timer nICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 29: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow nOCFnxOutput compare match x for timer n

ICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 30: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow nOCFnxOutput compare match x for timer nICFn

Input capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 31: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Flags

TOVnTimer overflow nOCFnxOutput compare match x for timer nICFnInput capture for timer n

Terry Sturtevant CP316 Timers and Counters

Page 32: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 33: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normal

rolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 34: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOP

CTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 35: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)

returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 36: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reached

Fast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 37: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWM

rolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 38: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOP

output OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 39: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 40: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes

Normalrolls over at TOPCTC (Clear Timer on Compare Match)returns to zero when OCRnx (or ICRn) reachedFast PWMrolls over at TOPoutput OCnx set when compare matches TCNTx and OCRnx

Terry Sturtevant CP316 Timers and Counters

Page 41: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 42: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWM

counts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 43: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOM

output OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 44: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnx

Phase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 45: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWM

counts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 46: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOM

output set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 47: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 48: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer modes (continued)

Phase correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput OCnx cleared on upcount, set on downcount whencompare matches TCNTx and OCRnxPhase and frequency correct PWMcounts BOTTOM to TOP then TOP to BOTTOMoutput set when ????????? compare matches TCNTx andOCRnx ???

Terry Sturtevant CP316 Timers and Counters

Page 49: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 50: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0

counter?

size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 51: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0

counter?size?

prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 52: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0

counter?size?prescaler?

Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 53: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 54: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 55: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM

0x00MAX0xFFmaximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 56: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00

MAX0xFFmaximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 57: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX

0xFFmaximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 58: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX0xFF

maximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 59: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX0xFFmaximum value the timer can reach

TOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 60: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOP

MAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 61: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer0 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOPMAX or value in OCR0A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 62: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0

Timer 0

Terry Sturtevant CP316 Timers and Counters

Page 63: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0

Timer 0

Terry Sturtevant CP316 Timers and Counters

Page 64: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0

Timer 0Terry Sturtevant CP316 Timers and Counters

Page 65: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0A register

Bits in TCCR0A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 66: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0A register

Bits in TCCR0A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 67: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0A register

Bits in TCCR0A register

COM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 68: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0A register

Bits in TCCR0A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 69: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0B register

Bits in TCCR0B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 70: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0B register

Bits in TCCR0B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 71: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0B register

Bits in TCCR0B register

FOC Force output compare bitsWGM Waveform generation mode bits

CS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 72: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR0B register

Bits in TCCR0B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 73: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR0 register

Bits in TIFR0 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 74: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR0 register

Bits in TIFR0 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 75: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR0 register

Bits in TIFR0 register

OCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 76: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR0 register

Bits in TIFR0 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 77: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 78: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1

counter?

size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 79: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1

counter?size?

prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 80: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1

counter?size?prescaler?

Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 81: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 82: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX0xFFFFmaximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 83: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM

0x0000MAX0xFFFFmaximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 84: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000

MAX0xFFFFmaximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 85: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX

0xFFFFmaximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 86: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX0xFFFF

maximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 87: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX0xFFFFmaximum value the timer can reach

TOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 88: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX0xFFFFmaximum value the timer can reachTOP

0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 89: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer1 details

BOTTOM0x0000MAX0xFFFFmaximum value the timer can reachTOP0x00FF, 0x01FF,or 0x03FF, or to the value stored in theOCR1A or ICR1, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 90: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 1

Timer 1

Terry Sturtevant CP316 Timers and Counters

Page 91: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 1

Timer 1

Terry Sturtevant CP316 Timers and Counters

Page 92: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 1

Timer 1Terry Sturtevant CP316 Timers and Counters

Page 93: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1A register

Bits in TCCR1A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 94: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1A register

Bits in TCCR1A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 95: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1A register

Bits in TCCR1A register

COM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 96: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1A register

Bits in TCCR1A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 97: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1B register

Bits in TCCR1B registerICNC Input capture noise canceler bitICES Input capture edge select bit

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 98: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1B register

Bits in TCCR1B registerICNC Input capture noise canceler bitICES Input capture edge select bit

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 99: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1B register

Bits in TCCR1B register

ICNC Input capture noise canceler bitICES Input capture edge select bit

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 100: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1B register

Bits in TCCR1B registerICNC Input capture noise canceler bitICES Input capture edge select bit

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 101: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1C register

Bits in TCCR1C registerFOC Force output compare bits

Terry Sturtevant CP316 Timers and Counters

Page 102: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1C register

Bits in TCCR1C registerFOC Force output compare bits

Terry Sturtevant CP316 Timers and Counters

Page 103: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1C register

Bits in TCCR1C register

FOC Force output compare bits

Terry Sturtevant CP316 Timers and Counters

Page 104: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR1C register

Bits in TCCR1C registerFOC Force output compare bits

Terry Sturtevant CP316 Timers and Counters

Page 105: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR1 register

Bits in TIFR1 registerICF Input capture flag bit

OCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 106: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR1 register

Bits in TIFR1 registerICF Input capture flag bit

OCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 107: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR1 register

Bits in TIFR1 register

ICF Input capture flag bitOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 108: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR1 register

Bits in TIFR1 registerICF Input capture flag bit

OCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 109: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 110: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2

counter?

size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 111: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2

counter?size?

prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 112: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2

counter?size?prescaler?

Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 113: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2

counter?size?prescaler?Arduino connections

Terry Sturtevant CP316 Timers and Counters

Page 114: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 115: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM

0x00MAX0xFFmaximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 116: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00

MAX0xFFmaximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 117: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX

0xFFmaximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 118: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX0xFF

maximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 119: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX0xFFmaximum value the timer can reach

TOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 120: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOP

MAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 121: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer2 details

BOTTOM0x00MAX0xFFmaximum value the timer can reachTOPMAX or the value stored in the OCR2A, depending on mode

Terry Sturtevant CP316 Timers and Counters

Page 122: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2

Timer 2

Terry Sturtevant CP316 Timers and Counters

Page 123: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2

Timer 2

Terry Sturtevant CP316 Timers and Counters

Page 124: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2

Timer 2Terry Sturtevant CP316 Timers and Counters

Page 125: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2A register

Bits in TCCR2A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 126: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2A register

Bits in TCCR2A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 127: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2A register

Bits in TCCR2A register

COM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 128: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2A register

Bits in TCCR2A registerCOM Output compare bitsWGM Waveform generation mode bits

Terry Sturtevant CP316 Timers and Counters

Page 129: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2B register

Bits in TCCR2B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 130: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2B register

Bits in TCCR2B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 131: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2B register

Bits in TCCR2B register

FOC Force output compare bitsWGM Waveform generation mode bits

CS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 132: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TCCR2B register

Bits in TCCR2B registerFOC Force output compare bits

WGM Waveform generation mode bitsCS Clock select bits

Terry Sturtevant CP316 Timers and Counters

Page 133: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR2 register

Bits in TIFR2 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 134: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR2 register

Bits in TIFR2 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 135: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR2 register

Bits in TIFR2 register

OCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 136: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

TIFR2 register

Bits in TIFR2 registerOCF Output compare flag bitsTOV Timer overflow flag bits

Terry Sturtevant CP316 Timers and Counters

Page 137: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0-1 prescaler

Timer 0-1 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 138: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0-1 prescaler

Timer 0-1 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 139: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 0-1 prescaler

Timer 0-1 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 140: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2 prescaler

Timer 2 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 141: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2 prescaler

Timer 2 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 142: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

Timer 2 prescaler

Timer 2 prescaler

Terry Sturtevant CP316 Timers and Counters

Page 143: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

16 bit register access

LOW HIGH

TMP

WRRD

DATA

16 bit register access

Terry Sturtevant CP316 Timers and Counters

Page 144: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

16 bit register access

LOW HIGH

TMP

WRRD

DATA

Reading LOW byte latches HIGH byte

Terry Sturtevant CP316 Timers and Counters

Page 145: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

16 bit register access

LOW HIGH

TMP

WRRD

DATA

Reading HIGH byte gets value from latch

Terry Sturtevant CP316 Timers and Counters

Page 146: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

16 bit register access

LOW HIGH

TMP

WRRD

DATA

Writing HIGH byte places value in latch

Terry Sturtevant CP316 Timers and Counters

Page 147: CP316- Timers and Countersdenethor.wlu.ca/cp316/lectures/timerbeam.pdf · Timer2 16 bit register access Timers and Counters timers vs. counters A timer counts clock pulses; a counter

Timers and Counters

DetailsTimer0Timer1Timer216 bit register access

16 bit register access

LOW HIGH

TMP

WRRD

DATA

Writing LOW byte transfers value from latch

Terry Sturtevant CP316 Timers and Counters