5b-avr-timer(16-bit).pdf

39
3/12/2015 1 AVR Timer (16-bit Timer) Lecture 5A 2 / 78 16-bit Timer/Counter Following registers associated with the timer/counter1 are all 16 bit Timer/Counter1 Register TCNT1 (TCNT1H & TCNT1L) Output Compare Registers A OCR1A (OCR1AH & OCR1AL) Output Compare Registers B OCR1B (OCR1BH & OCR1BL) Input Capture Register ICR1 (ICR1H & ICR1L) The TCNT1, OCR1A, OCR1B, and ICR1 are 16-bit registers that can be accessed by the AVR CPU via the 8-bit data bus

Upload: zohaibshabir

Post on 17-Jan-2016

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 5b-AVR-Timer(16-bit).pdf

3/12/2015

1

AVR Timer (16-bit Timer)

Lecture 5A

2 / 78

16-bit Timer/CounterFollowing registers associated with the timer/counter1 are all 16 bit

Timer/Counter1 Register – TCNT1 (TCNT1H & TCNT1L)

Output Compare Registers A – OCR1A (OCR1AH & OCR1AL)

Output Compare Registers B – OCR1B (OCR1BH & OCR1BL)

Input Capture Register – ICR1 (ICR1H & ICR1L)

The TCNT1, OCR1A, OCR1B, and ICR1 are 16-bit registers that can be accessed by the AVR CPU via the 8-bit data bus

Page 2: 5b-AVR-Timer(16-bit).pdf

3/12/2015

2

3 / 78

16-bit Timer/CounterUnlike 8-bit timers/counters the 16-bit timer/counter1 has two 8-bit timer/counter control registers

Timer/Counter1 Control Register A – TCCR1ATimer/Counter1 Control Register B – TCCR1B

Just like 8-bit timers, 16-bit timer is also started by selecting the clock sourceThe bit which select the clock source for the timer are situated in TCCR1B

4 / 78

WRITE OPERATION16-bit timer has a single 8-bit register for temporary storing of the high byte of the 16-bit accessThe same temporary register is shared between all 16-bit registers within 16-bit timerFirst high byte is written, which is stored in the temporary registerWriting the low byte, triggers the 16-bit write operation to the actual registerWhen the low byte of a 16-bit register is written by the CPU, the high byte stored in the temporary register and the low byte written are both copied into the 16-bit register in the same clock cycle

Accessing 16-bit Registers

Page 3: 5b-AVR-Timer(16-bit).pdf

3/12/2015

3

5 / 78

READ OPERATIONWhen the low byte of a 16-bit register is read by the CPU, the high byte of the 16-bit register is copied into the temporary register in the same clock cycle as the low byte is readAnd then the high byte is read from the temporary register

Accessing 16-bit Registers (Contd.)

6 / 78

Accessing 16-bit Registers

Page 4: 5b-AVR-Timer(16-bit).pdf

3/12/2015

4

7 / 78

16-bit Register Read/Write SummaryTo write a 16-bit registerThe high byte must be written before the low byteTo read a 16-bit registerThe low byte must be read before the high byteNote:- While using “C”, the compiler handles

the 16-bit access, but if you want to write/read Low and high byte separately then above rules have to be followed

8 / 78

16-bit Register Read/Write - Assembly.include "M16def.inc"

ldi r16,0x80out tcnt1h, r16 ;Write TH ldi r17,0xc1out tcnt1l, r17 ; Write TL

in r18, tcnt1l ; Read TLin r19,tcnt1h ;Read TH

here: rjmp here

Page 5: 5b-AVR-Timer(16-bit).pdf

3/12/2015

5

9 / 78

16-bit Register Read/Write - Cint main(){ unsigned int x;

unsigned char high=0, low=0;TCNT1=0xC180;x= TCNT1;

// ********* Write - TH first then TL ******TCNT1H=0x80;TCNT1L=0xC1;

// *********** Read – TL first then TH ***** low=TCNT1L; high= TCNT1H;

}

10 / 78

Timers/Counter FunctionsThe Timers can be used for the following functions

Normal Mode (Delay generation or Measuring time)Clear timer on compare match (Delay generation or Measuring time)Count External eventsPWM generation

Phase correct PWMFast PWM Phase and Frequency Correct PWM

Waveform Generation

Page 6: 5b-AVR-Timer(16-bit).pdf

3/12/2015

6

11 / 78

Timer/Counter1 Control Register A – TCCR1A

Timer/Counter1 Control Register B – TCCR1B

Selects different modes and clock/prescaler to the timer.

Registers Associated with Timers

12 / 78

Timer/Counter1 – TCNT1H and TCNT1L

The two Timer/Counter I/O locations (TCNT1H and TCNT1L, combined TCNT1) give direct access, both for read and for write operations, to the Timer/Counter unit 16-bit counter

Registers Associated with Timers

Page 7: 5b-AVR-Timer(16-bit).pdf

3/12/2015

7

13 / 78

Output Compare Register 1 A – OCR1AH and OCR1AL

Output Compare Register 1 B – OCR1BH and OCR1BL

The Output Compare Registers contain a 16-bit value that is continuously compared with the counter value (TCNT1). A match can be used to generate an output compare interrupt, or to generate a waveform output on the OC1x pin.

Registers Associated with Timers

14 / 78

Timer/Counter Interrupt Flag Register – TIFR

Timer/Counter Interrupt Mask Register- TIMSK

Registers Associated with Timers

Page 8: 5b-AVR-Timer(16-bit).pdf

3/12/2015

8

15 / 78

PWM PINs of Timer 1

16 / 78

Timers/Counters in Atmega16

Page 9: 5b-AVR-Timer(16-bit).pdf

3/12/2015

9

17 / 78

Timers/Counters in Atmega16

18 / 78

Timer/Counter1 Control Register A – TCCR1A

Timer/Counter1 Control Register B – TCCR1B

Different Modes selected by these bits are shown in the table in next slide

Selecting the Required Mode

Page 10: 5b-AVR-Timer(16-bit).pdf

3/12/2015

10

19 / 78

Selecting the Required Mode

20 / 78

Normal ModeTCCR1A and TCCR1B(Timer/counter1 Control Registers)

WGM13 : WGM10 selects the mode of the timerFor Normal Mode

WGM13=0WGM12=0WGM11=0WGM10=0

Page 11: 5b-AVR-Timer(16-bit).pdf

3/12/2015

11

21 / 78

Normal Mode

22 / 78

Selecting the Required Mode

Page 12: 5b-AVR-Timer(16-bit).pdf

3/12/2015

12

23 / 78

Pre-Scaler

24 / 78

Normal Mode(WGM13:WGM10=0000)The simplest mode of operation is the normal modeIn this mode the counting direction is always up (incrementing)The counter simply overruns when it passes its maximum 16-bit value (TOP = 0xFFFF) and then restarts from the bottom (0x00)In normal operation the Timer/Counter Overflow Flag (TOV1) will be set in the same timer clock cycle as the TCNT1 becomes zeroThis mode can be used to create delays or measure time between two events.

Normal Mode

Page 13: 5b-AVR-Timer(16-bit).pdf

3/12/2015

13

25 / 78

Normal ModeAn interrupt can be generated each time the counter valueoverflows by using the TOV1 flagIf the interrupt is enabled, the interrupt handler routine canbe used for updating (reloading) the TCNT1 value

26 / 78

ProcedureNc = Time of delay (us) x Crystal freq (MHz)If Nc < 65536 use Timer1 without prescaler else use prescaler.Nr = 65536 – Nc (value to be loaded in TCNT0)

In case of PrescalerNp = Nc / prescaler Nr = 65536- Np

Calc No for TCNT1 Register

Page 14: 5b-AVR-Timer(16-bit).pdf

3/12/2015

14

27 / 78

Use Timer1 in normal mode to create a delay of 5ms. Controller frequency is 8mhz.

SolutionNc = 5000 x 8 = 40000Nc<65536, hence no prescaler is required.Nr = 65536-40000 = 25536

TCNT1=Nr=25536;

Example

28 / 78

Generate a delay of 0.5s using Timer1. Controller frequency is 8Mhz. Find Prescaler and TCNT1 valueSolution

Nc = Time of delay (us) x Crystal freq (MHz)Nc = 500,000x8 =40,00,000NC > 65536 use Timer1 with prescaler

Np = Nr / prescaler Np = 40,00,000 / 8=500,000Since, Np > 65536 we choose the next prescaler valueNp = 40,00,000 / 64=62500Nr = 65536-62500 = 3036

Example

Page 15: 5b-AVR-Timer(16-bit).pdf

3/12/2015

15

29 / 78

Generate a delay of 5ms using Timer0. Controller frequency is 8Mhz.Procedure

We assume that the timer is loaded with zero to generate the delay. From this assumption we then calculate the approximate timer periodApprox Timer period = delay/256 = TApprox Timer Frequency = 1/T = FApprox Prescaler = 8M/F =N

From the table we then choose the nearest value of prescaler greater than “N”

From this value of N we redo the calculations to calculate the value to be loaded in the Timer.

Example

30 / 78

SolutionApproximate timer period = 5m/256 = 19.53usApproximate Timer Frequency = 1/19.53u = 51.2kHzApproximate Prescaler = 8M/51.2k= 156.25

Hence presclaer of 256 or 1024 can be chosen. We choose 256.Timer Frequency = 8m/256 = 31.25kTimer Period = 1/31.25k = 32usTimer counts Req. = 5m/32u = 156TCNT0 = 256-156 = 100

Example

Page 16: 5b-AVR-Timer(16-bit).pdf

3/12/2015

16

31 / 78

Example

32 / 78

Example(using interrupt)#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRB=0xFF;TCNT1=0xC180; TIMSK=0x04;SREG|=0x80;TCCR1A=0x00;TCCR1B=0x01;while(1){}

}ISR(TIMER1_OVF_vect){ PORTB=PORTB^0x10;

TCNT1=0xC180;} AVR_16bit_normal_Int

Page 17: 5b-AVR-Timer(16-bit).pdf

3/12/2015

17

33 / 78

ExampleProgram Timer 1 to generate a square wave of frequency 3khz on pin PB4, using normal mode. Clk freq= 8Mhz.

34 / 78

Solution

Calculate value of TCNT1Tperiod = 1/f = 1/3k = 1/3 msHence required Delay :

d=(1/3)/2 = 1/6 ms

Nc = Time of delay (us) x Crystal freq (MHz)Nc = (1000/6)x8 = 1333.33Nr = 65536 – 1333 = 64203

Page 18: 5b-AVR-Timer(16-bit).pdf

3/12/2015

18

35 / 78

Code#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRB=0xFF;TCNT1=64203; TIMSK=0x04;TIFR|=0x04;SREG|=0x80;TCCR1A=0x00;TCCR1B=0x01;while(1){}

}ISR(TIMER1_OVF_vect){ PORTB=PORTB^0x10;

TCNT1=64203;}

36 / 78

Clear Timer on Compare MatchTCCR1A and TCCR1B(Timer/counter1 Control Registers)

WGM13 : WGM10 selects the mode of the timerWGM13 : WGM10 =0100 (Top value defined by OCR1A) WGM13 : WGM10 =1100 (Top value defined by ICR1A)

Page 19: 5b-AVR-Timer(16-bit).pdf

3/12/2015

19

37 / 78

Clear Timer on Compare MatchWGM13:WGM10=0100

WGM13:WGM10=1100

38 / 78

Selecting the Required Mode

Page 20: 5b-AVR-Timer(16-bit).pdf

3/12/2015

20

39 / 78

Clear Timer on Compare Match

40 / 78

In Clear Timer on Compare or CTC mode the OCR1A/ICR1 Register is used to manipulate the TIMER/COUNTER resolutionIn CTC mode the counter is cleared to zero when the counter value (TCNT1) matches the OCR1A or ICR1The OCR1A/ICR1 defines the top value for the counter, hence also its resolutionIf a frequency other than those available using the prescaler options is required, this mode can be used.The frequency is calculated by

Clear Timer on Compare Match

Page 21: 5b-AVR-Timer(16-bit).pdf

3/12/2015

21

41 / 78

Clear Timer on Compare Match(CTC)An interrupt can be generated each time the counter valuereaches the TOP value by using the OCF1A/ICF1 flagIf the interrupt is enabled, the interrupt handler routine can beused for updating the TOP valueChanging TOP to a value close to BOTTOM when the counteris running with none or a low prescaler value must be donewith care since the CTC mode does not have the doublebuffering feature. If the new value written to OCR1A/ICR1 islower than the current value of TCNT1, the counter will missthe compare match. The counter will then have to count to itsmaximum value (0xFFFF) and wrap around starting at 0x0000before the compare match can occur

42 / 78

ExampleWrite a C program to toggle only the PORTB.4 bitcontinuously every 2ms. Use Timer1, CTC mode and noPrescaler to create the delay. Assume XTAL= 8 MHz.

Page 22: 5b-AVR-Timer(16-bit).pdf

3/12/2015

22

43 / 78

Example(using interrupt)#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRB=0xFF;TCCR1A=0x00;TCCR1B=0x09;OCR1A=0x3E80;TIMSK=0x10;SREG|=0x80;while(1){}

}ISR(TIMER1_COMPA_vect){ PORTB=PORTB^0x10;}

#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRB=0xFF;TCCR1A=0x00;TCCR1B=0x01;TCNT1=0xC180; TIMSK=0x04;SREG|=0x80;while(1){}

}ISR(TIMER1_OVF_vect){ PORTB=PORTB^0x10;

TCNT1=0xC180;}

44 / 78

ExampleProgram Timer 1 to generate a square wave of frequency 20khz on pin PB4, using CTC mode. Clk freq= 8Mhz.

Calc OCR1A = ?Use N=1 (No prescaler)

Page 23: 5b-AVR-Timer(16-bit).pdf

3/12/2015

23

45 / 78

Solution

Using

We are given fclk-i/o = 8MHz, fpwm = 20KHz.N=1

OCR1A= 8000/(2*20) - 1OCR1A = 199

46 / 78

Code#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRB=0xFF;TCCR1A=0;TCCR1B=0x09;OCR1A=199;TIMSK=0x10;SREG|=0x80;while(1){}

}ISR(TIMER1_COMPA_vect){ PORTB=PORTB^0x10;

Page 24: 5b-AVR-Timer(16-bit).pdf

3/12/2015

24

47 / 78

Counter Mode

The above two modes are used to drive the timer from an external clock source.By using these options the timer can be used as a counter to count external events.

48 / 78

ExampleCount the number of cars passing on the road. A sensor is placed across the road, that sends a pulse when it senses a car, attached to pin PB1. Configure the timer so that it responds to the rising edge. Output the number of cars on PORTA and PORTC.Solution

For this we configure the timer to count on the rising edge of an external source. Hence, CS12=1,CS11=1,CS10=1.The number of cars that pass through the road will be equal to the value of TCNT1.

Page 25: 5b-AVR-Timer(16-bit).pdf

3/12/2015

25

49 / 78

ExampleCODE

#include<avr/io.h>#include<avr/interrupt.h>int main(){

DDRA=0xFF;DDRC=0xFF;DDRB=0x00;TCCR1A=0;TCCR1B=0x07;while(1){

PORTC=TCNT1L; PORTA=TCNT1H;

}} AVR_16Bit_Counter

Timer1 16 bit counter.isis

50 / 78

Phase Correct PWM ModeTCCR1A and TCCR1B(Timer/counter1 Control Registers)

WGM13 : WGM10 selects the mode of the timerWGM13 : WGM10 =0001 (Top value defined by 0x00FF)WGM13 : WGM10 =0010 (Top value defined by 0x01FF)WGM13 : WGM10 =0011 (Top value defined by 0x03FF)WGM13 : WGM10 =1010 (Top value defined by ICR1)WGM13 : WGM10 =1011 (Top value defined by OCR1A)

Page 26: 5b-AVR-Timer(16-bit).pdf

3/12/2015

26

51 / 78

Selecting the Required Mode

52 / 78

The phase correct PWM mode is based on a dual slope operationThe counter counts repeatedly from BOTTOM to TOP and then from TOP to BOTTOM

Phase Correct PWM Mode

Page 27: 5b-AVR-Timer(16-bit).pdf

3/12/2015

27

53 / 78

In non-inverting Compare Output mode (COM01=1&COM00=0)The Output Compare (OC1x) is cleared on the compare match between TCNT1 and OCR1x while upcounting, and set on the compare match while downcounting.

Phase Correct PWM Mode

54 / 78

In inverting Output Compare mode (COM01=1&COM00=1)The operation is inverted

Phase Correct PWM Mode

Page 28: 5b-AVR-Timer(16-bit).pdf

3/12/2015

28

55 / 78

The Timer/Counter Overflow Flag (TOV1) is set each time the counter reaches BOTTOMIf the interrupt is enabled, the interrupt handler routine can be used for updating the compare valueThe PWM resolution for the phase correct PWM mode can be fixed to 8-, 9-, or 10-bit or defined by OCR1A/ICR1The maximum resolution is 16-bit (OCR1A/ICR1 set to MAX)The PWM resolution in bits can be calculated by using the following equation

The PWM frequency for the output can be calculated by the following equation

Phase Correct PWM Mode

56 / 78

Generate a PWM waveform in the phase correct pwmmode. Frequency of the waveform should be approximately 2Khz. Assume controller frequency to be 8Mhz. Use 8-bit resolution.

Calculate the value of prescaler and the value to be loaded in TCCR1A and TCCR1B.For the above calculated prescaler, find the output frequency if 9-bit resolution is used.Write a C code generating the waveform with Duty cycle of 75% if PIN 3 of PORTC is set otherwise duty cycle should be 50%.

Example

Page 29: 5b-AVR-Timer(16-bit).pdf

3/12/2015

29

57 / 78

Timer/Counter1 Control Register A – TCCR1A

Timer/Counter1 Control Register B – TCCR1B

Selects different modes and clock/prescaler to the timer.

Registers Associated with Timers

58 / 78

Calc value of Prescaler and TCCR1A and TCCR1B

N= PreScalerWe are given fclk-i/o = 8MHz, fpwm = 2KHz.TOP= 8bit=255Hence the value of N is found to be =7.84 From the table we choose the nearest value of 8.Hence, CS12=0, CS11=1 and CS10=0.

TCCR1A=0xA1;TCCR1B=0x02;Value of Prescaler =8

Find Freq, if 9-bit Resolution is usedTop=9bit=511 N=8Focnx=1khz.

Solution

Page 30: 5b-AVR-Timer(16-bit).pdf

3/12/2015

30

59 / 78

C code for generating the waveform#include<avr/io.h>unsigned char x=0;void main(void){ DDRD|=0x30; //configure port D PIN 5 and PIN 6 (OC1A &OC1B) as output

DDRC&=0xfb; //Configures port C PIN 3 as inputTCCR1A=0b10100001; //PWM in phase correct modeTCCR1B=0b00000010; //Prescalar=8while(1){

x=PINC & 0x04;if(x==0x04)

{OCR1A=191; //PWM 1 – 75%OCR1B=191; //PWM 2

}else

{OCR1A=127; // 50%OCR1B=127;

}}

}

Solution

60 / 78

ExampleWrite a program to generate two independent PWMs dependent on the inputs from Port A and Port C. Use Timer 1 in 8-bit, Phase correct PWM mode

#include<avr/io.h>void main(void){ DDRA=0x00;

DDRC=0x00;DDRD=0b00110000;TCCR1A=0b10100001;TCCR1B=0b00000010;

while(1){

OCR1A=PINA;OCR1B=PINC;

}} AVR_PWM_16bit_2pwms

Page 31: 5b-AVR-Timer(16-bit).pdf

3/12/2015

31

61 / 78

Phase and Frequency Correct PWM Mode

TCCR1A and TCCR1B(Timer/counter1 Control Registers)

WGM13 : WGM10 selects the mode of the timerWGM13 : WGM10 =1000 (Top value defined by ICR1)WGM13 : WGM10 =1001 (Top value defined by OCR1A)

The phase correct, and the phase and frequency correct PWM mode are similar to each other. They differ in only one aspect, discussed on the next slide.

62 / 78

Phase and Frequency vs Phase correct

The main difference between the phase correct, and the phase and frequency correct PWM mode is the time the OCR1x Register is updated.In Phase correct mode the OCR1x registers are updated when the counter reaches the top value. In Phase and Frequency correct the OCR1x registers are updated when the counter reaches the bottom value.This ensures that both compare matches(during up counting and down counting) occur at the same point during each cycle, hence, the frequency will never change during a cycle in Phase and Frequency correct mode.

Page 32: 5b-AVR-Timer(16-bit).pdf

3/12/2015

32

63 / 78

Selecting the Required Mode

@ Dr Javaid, M.H Fidai

64 / 78

Fast PWM ModeTCCR1A and TCCR1B(Timer/counter1 Control Registers)

WGM13 : WGM10 selects the mode of the timerWGM13 : WGM10 =0101 (Top value defined by 0x00FF)WGM13 : WGM10 =0110 (Top value defined by 0x01FF)WGM13 : WGM10 =0111 (Top value defined by 0x03FF)WGM13 : WGM10 =1110 (Top value defined by ICR1)WGM13 : WGM10 =1111 (Top value defined by OCR1A)

Page 33: 5b-AVR-Timer(16-bit).pdf

3/12/2015

33

65 / 78

Selecting the Required Mode

66 / 78

The fast Pulse Width Modulation or fast PWM mode provides a high frequency PWM waveform generation optionThe counter counts from BOTTOM to TOP then restarts from BOTTOM. It is a single slope operation

Fast PWM Mode

Page 34: 5b-AVR-Timer(16-bit).pdf

3/12/2015

34

67 / 78

In non-inverting Compare Output mode (COM01x1=1&COM1x0=0)

The Output Compare (OC1x) is cleared on the compare match between TCNT1 and OCR1x and set at the TOP.

Fast PWM Mode

68 / 78

In inverting Output Compare mode (COM01x1=1&COM1x0=1)

The Output Compare (OC1) is set on the compare match between TCNT1 and OCR1x and cleared at the TOP.

Fast PWM Mode

Page 35: 5b-AVR-Timer(16-bit).pdf

3/12/2015

35

69 / 78

The Timer/Counter Overflow Flag (TOV1) is set each time the counter reaches TOPIf the interrupt is enabled, the interrupt handler routine can be used for updating the compare valueThe minimum resolution allowed is 2-bit (OCR1A set to 0x0003), and the maximum resolution is 16-bit (OCR1A set to MAX)The PWM resolution in bits can be calculated by using the following equation

The PWM frequency for the output can be calculated by the following equation

Fast PWM Mode

70 / 78

Generate a PWM waveform in the Fast PWM mode. Frequency of the waveform should be approximately 4Khz. Assume controller frequency to be 8Mhz. Use 8-bit resolution.

Calculate the value of prescaler and the value to be loaded in TCCR1A and TCCR1B.For the above calculated prescaler, find the output frequency if 10-bit resolution is used.Write a C code generating the waveform with Duty cycle of 75% if PIN 3 of PORTC is set otherwise duty cycle should be 50%.

Example

Page 36: 5b-AVR-Timer(16-bit).pdf

3/12/2015

36

71 / 78

Value of Prescaler

We are given fclk-i/o = 8MHz, fpwm = 4KHz.TOP= 8-bit=255Hence the value of N is found to be =7.8125 From the table we choose the nearest value of 8.Hence, CS12=0, CS11=1 and CS10=0.

TCCR1A=0xA1;TCCR1B=0x0A;Value of Prescaler = 8

10-bit ResolutionTop=10-bit=1023Focnx=1khz.

Solution

72 / 78

C code for generating the waveform#include<avr/io.h>unsigned char x=0;void main(void){ DDRD|=0x30; //configure port D PIN 5 and PIN 6 (OC1A &OC1B) as output

DDRC&=0xfb; //Configures port C PIN 3 as inputTCCR1A=0b10100001; //PWM in phase correct mode 8-BITTCCR1B=0b00001010; //Prescalar=8while(1){

x=PINC & 0x04;if(x==0x04)

{OCR1A=191;OCR1B=191;

}else

{OCR1A=127;OCR1B=127;

}}

}

Solution

Page 37: 5b-AVR-Timer(16-bit).pdf

3/12/2015

37

73 / 78

The AVR microcontroller can generate a waveform using the timer on the I/O pin associated with that timer.

The microcontroller compares the OCR1x and the TCNT1 register constantly. When they match the OCF1x (compare match Flag) is set. The user can program the microcontroller to generate a waveform in response to this compare match .The COM1x1 and COM1x0 bits in the TCCR0 register decide whether to generate a waveform or not and also its form.

Waveform Generation

74 / 78

Waveform Generation

Page 38: 5b-AVR-Timer(16-bit).pdf

3/12/2015

38

75 / 78

Normal or CTC mode (non-PWM)

Waveform Generation

76 / 78

Waveform generation Normal Mode

Page 39: 5b-AVR-Timer(16-bit).pdf

3/12/2015

39

77 / 78

Waveform Generation CTC Mode

78 / 78

Waveform GenerationFast PWM mode

Phase correct PWM mode