0% found this document useful (0 votes)
112 views89 pages

PDF Motion Control With Variable Velocity Using PWM PDF

The document discusses pulse width modulation (PWM) and its use in controlling motors. PWM involves generating pulses of varying widths to encode information. The duty cycle is defined as the ratio of pulse width to period and determines the amount of power delivered to a load like a motor. Timers in AVR microcontrollers like the ATmega2560 can be used to generate PWM signals to control the speed of motors connected to the Firebird robotics platform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
112 views89 pages

PDF Motion Control With Variable Velocity Using PWM PDF

The document discusses pulse width modulation (PWM) and its use in controlling motors. PWM involves generating pulses of varying widths to encode information. The duty cycle is defined as the ratio of pulse width to period and determines the amount of power delivered to a load like a motor. Timers in AVR microcontrollers like the ATmega2560 can be used to generate PWM signals to control the speed of motors connected to the Firebird robotics platform.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 89

outline

Introduction
PWM Generation in AVR
PWM Generation in Firebird V

DC Motor Velocity Control


Using Pulse Width Modulation (PWM)

E-Yantra Team

Embedded Real-Time Systems Lab


Indian Institute of Technology-Bombay

IIT Bombay
October 20, 2012

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 1/22


outline
Introduction
PWM Generation in AVR
PWM Generation in Firebird V

Agenda for Discussion


1 Introduction
Pulse Width Modulation
Duty Cycle
2 PWM Generation in AVR
Timer in AVR
Timer for PWM generation in Firebird
3 PWM Generation in Firebird V
Registers
TCCR5A
TCCR5B
TCNT5
OCR5
Block Diagram
Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 2/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

1 Pulse Width Modulation (PWM), is a method of transmitting


information on a series of pulses

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

1 Pulse Width Modulation (PWM), is a method of transmitting


information on a series of pulses

2 The data that is being transmitted is encoded on the width of these


pulses to control the amount of power being sent to a load

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

1 Pulse Width Modulation (PWM), is a method of transmitting


information on a series of pulses

2 The data that is being transmitted is encoded on the width of these


pulses to control the amount of power being sent to a load

3 Examples: Electric stoves, Lamp dimmers, and Robotic Servos

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

1 Pulse Width Modulation (PWM), is a method of transmitting


information on a series of pulses

2 The data that is being transmitted is encoded on the width of these


pulses to control the amount of power being sent to a load

3 Examples: Electric stoves, Lamp dimmers, and Robotic Servos

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Pulse Width Modulation

1 Pulse Width Modulation (PWM), is a method of transmitting


information on a series of pulses

2 The data that is being transmitted is encoded on the width of these


pulses to control the amount of power being sent to a load

3 Examples: Electric stoves, Lamp dimmers, and Robotic Servos

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 3/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.
X When output is high the voltage is 5v

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.
X When output is high the voltage is 5v
X When output is low the voltage is 0v

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.
X When output is high the voltage is 5v
X When output is low the voltage is 0v
X Time Period(T) = Ton + Toff

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.
X When output is high the voltage is 5v
X When output is low the voltage is 0v
X Time Period(T) = Ton + Toff
X Duty Cycle = Ton/(Ton + Toff)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle

X The signal remains ”ON” for some time and ”OFF” for some time.
X Ton = Time the output remains high.
X Toff = Time the output remains Low.
X When output is high the voltage is 5v
X When output is low the voltage is 0v
X Time Period(T) = Ton + Toff
X Duty Cycle = Ton/(Ton + Toff)
X Duty Cycle = 50%
www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 4/22
outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 1


X Toff = Time the output remains Low = 7

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 1


X Toff = Time the output remains Low = 7
X Duty Cycle = 12.5%
www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 5/22
outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 6

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 6


X Toff = Time the output remains Low = 2

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/22


outline
Introduction Pulse Width Modulation
PWM Generation in AVR Duty Cycle
PWM Generation in Firebird V

Duty Cycle (Contd..)

X Ton = Time the output remains high = 6


X Toff = Time the output remains Low = 2
X Duty Cycle = 75%
www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 6/22
outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

two 8-bit timers (Timer0 and Timer2) and

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

two 8-bit timers (Timer0 and Timer2) and

four 16-bit timers (Timer 1, 3, 4 and 5)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

two 8-bit timers (Timer0 and Timer2) and

four 16-bit timers (Timer 1, 3, 4 and 5)

2 When the counter reaches its maximum count, it rolls over and
executes from the start

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

two 8-bit timers (Timer0 and Timer2) and

four 16-bit timers (Timer 1, 3, 4 and 5)

2 When the counter reaches its maximum count, it rolls over and
executes from the start

For 8-bit counter, roll over occurs at 255 count and

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer in AVR

1 The AVR microcontroller ATmega2560 has

two 8-bit timers (Timer0 and Timer2) and

four 16-bit timers (Timer 1, 3, 4 and 5)

2 When the counter reaches its maximum count, it rolls over and
executes from the start

For 8-bit counter, roll over occurs at 255 count and

For 16-bit counter it occurs at 65535 count

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 7/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer for PWM generation in Firebird

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer for PWM generation in Firebird

1 Timer 5 can be used for PWM generation for controlling speed of


motors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer for PWM generation in Firebird

1 Timer 5 can be used for PWM generation for controlling speed of


motors

2 The duty cycle of square wave generated by the Timer5 can be


varied to produce different average DC values for motors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/22


outline
Introduction Timer in AVR
PWM Generation in AVR Timer for PWM generation in Firebird
PWM Generation in Firebird V

Timer for PWM generation in Firebird

1 Timer 5 can be used for PWM generation for controlling speed of


motors

2 The duty cycle of square wave generated by the Timer5 can be


varied to produce different average DC values for motors

3 Using FAST PWM mode to vary speed of motors

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 8/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

2 Four registers are:

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

2 Four registers are:

TCCR5A

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

2 Four registers are:

TCCR5A

TCCR5B

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

2 Four registers are:

TCCR5A

TCCR5B

TCNT5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timer for PWM generation in Firebird

1 To Program PWM, we have to initialize some register before use it

2 Four registers are:

TCCR5A

TCCR5B

TCNT5

OCR5n

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 9/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5A- Timer Counter Control Register A


This register is Used to Configure Timer for PWM generation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5A- Timer Counter Control Register A


This register is Used to Configure Timer for PWM generation

Bit Symbol Description Bit Value


7 COM5A1 Compare Output Mode for Channel A bit 1 1
6 COM5A0 Compare Output Mode for Channel A bit 0 0
5 COM5B1 Compare Output Mode for Channel B bit 1 1
4 COM5B0 Compare Output Mode for Channel B bit 0 0
3 COM5C1 Compare Output Mode for Channel C bit 1 1
2 COM5C0 Compare Output Mode for Channel C bit 0 0
1 WGM11 Waveform Generation Mode bit 1 0
0 WGM10 Waveform Generation Mode bit 0 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5A- Timer Counter Control Register A


This register is Used to Configure Timer for PWM generation

Bit Symbol Description Bit Value


7 COM5A1 Compare Output Mode for Channel A bit 1 1
6 COM5A0 Compare Output Mode for Channel A bit 0 0
5 COM5B1 Compare Output Mode for Channel B bit 1 1
4 COM5B0 Compare Output Mode for Channel B bit 0 0
3 COM5C1 Compare Output Mode for Channel C bit 1 1
2 COM5C0 Compare Output Mode for Channel C bit 0 0
1 WGM11 Waveform Generation Mode bit 1 0
0 WGM10 Waveform Generation Mode bit 0 1

TCCR5A = 0xA9

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 10/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Compare Output Mode Fast PWM

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Compare Output Mode Fast PWM

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 11/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Waveform Generation Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Waveform Generation Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 12/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5B- Timer Counter Control Register B


This register is Used to Configure Timer for PWM generation

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5B- Timer Counter Control Register B


This register is Used to Configure Timer for PWM generation

Bit Symbol Description Bit Value


7 ICNC5 Input Capture Noise Canceller 0
6 ICES5 Input Capture Edge Select 0
5 – Reserved Bit 0
4 WGM53 Waveform Generation Mode bit 3 0
3 WGM52 Waveform Generation Mode bit 2 1
2 CS52 Clock Select 0
1 CS51 Clock Select 1
0 CS50 Clock Select 1

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCCR5B- Timer Counter Control Register B


This register is Used to Configure Timer for PWM generation

Bit Symbol Description Bit Value


7 ICNC5 Input Capture Noise Canceller 0
6 ICES5 Input Capture Edge Select 0
5 – Reserved Bit 0
4 WGM53 Waveform Generation Mode bit 3 0
3 WGM52 Waveform Generation Mode bit 2 1
2 CS52 Clock Select 0
1 CS51 Clock Select 1
0 CS50 Clock Select 1

TCCR5B = 0x0B

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 13/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Clock Select Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Clock Select Bit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 14/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCNT5 : Timer/Counter5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCNT5 : Timer/Counter5

Purpose: Counts Up/down according to clock frequency

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCNT5 : Timer/Counter5

Purpose: Counts Up/down according to clock frequency

TCNT5 is a 16-bit Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCNT5 : Timer/Counter5

Purpose: Counts Up/down according to clock frequency

TCNT5 is a 16-bit Register

Counts from 0 to 255 if used in 8-Bit Mode

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

TCNT5 : Timer/Counter5

Purpose: Counts Up/down according to clock frequency

TCNT5 is a 16-bit Register

Counts from 0 to 255 if used in 8-Bit Mode

Counts from 0 to 65535 if used in 16-Bit Mode

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 15/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

Each can be used individually as separate PWM channel

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

Each can be used individually as separate PWM channel

OCR5n is represented as two 8-bit register as OCR5nL and OCR5nH

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

Each can be used individually as separate PWM channel

OCR5n is represented as two 8-bit register as OCR5nL and OCR5nH

PWM generated is 8-bit, so only lower register is used

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

Each can be used individually as separate PWM channel

OCR5n is represented as two 8-bit register as OCR5nL and OCR5nH

PWM generated is 8-bit, so only lower register is used

OCR5AL (PortL3) is connected to Left Motor

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5


Purpose: Compares itself from TCNT counter and set flags when
match occurs

OCR5n: where n=A/B/C are three different 16-bit Register

Each can be used individually as separate PWM channel

OCR5n is represented as two 8-bit register as OCR5nL and OCR5nH

PWM generated is 8-bit, so only lower register is used

OCR5AL (PortL3) is connected to Left Motor

OCR5BL (PortL4) is connected to Right Motor

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 16/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5 (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5 (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Output Compare Register 5 (Contd..)

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 17/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Block Diagram - Output Compare Unit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Block Diagram - Output Compare Unit

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 18/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timing Diagram Fast PWM

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 19/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Timing Diagram Fast PWM

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 19/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


PWM Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 20/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


PWM Initialization

Port Pin Config

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 20/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


PWM Initialization

Port Pin Config


void motion_pin_config (void) //Configure Pins as Output
{

Port A for motion control and Port L for Velocity Control must be defined Output

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 20/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


PWM Initialization

Port Pin Config


void motion_pin_config (void) //Configure Pins as Output
{

Port A for motion control and Port L for Velocity Control must be defined Output

PWM Initialization

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 20/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


PWM Initialization

Port Pin Config


void motion_pin_config (void) //Configure Pins as Output
{

Port A for motion control and Port L for Velocity Control must be defined Output

PWM Initialization
void timer5_init() //Set Register Values for starting Fast 8-bit PWM
{

TCCR5A =
TCCR5B =
TCNT5H = 0xFF;
TCNT5L = 0x00;
OCR5AH = 0x00;
OCR5AL = 0xFF;
OCR5BH = 0x00;
OCR5BL = 0xFF;
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 20/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 21/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


Program

Main Program

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 21/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
forward();
while(1)
{
velocity(100,100);
_delay_ms(500);
velocity(0,255);
_delay_ms(500);
}
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 21/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
forward();
while(1)
{
velocity(100,100);
_delay_ms(500);
velocity(0,255);
_delay_ms(500);
}
}

Velocity Function

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 21/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Syntax for C-Program


Program

Main Program
int main(void)
{
init_devices();
forward();
while(1)
{
velocity(100,100);
_delay_ms(500);
velocity(0,255);
_delay_ms(500);
}
}

Velocity Function
void velocity (unsigned char left_motor, unsigned char right_motor)
{

OCR5AL = (unsigned char)left_motor;


OCR5BL = (unsigned char)right_motor;
}

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 21/22


Registers
TCCR5A
outline
TCCR5B
Introduction
TCNT5
PWM Generation in AVR
OCR5
PWM Generation in Firebird V
Block Diagram
Program

Thank You!
Post your queries on: http://qa.e-yantra.org/

www.e-yantra.org Firebird ATmega2560 Robotics Research Platform 22/22

You might also like