You are on page 1of 15

Digital Implementation Of PWM using ATmega 2560

BIT, MESRA

18-04-2019 EE561:ECSPC 1
Presented by:
Table of Contents

 Introduction to Atmega
 Modes of Operation
 Fast PWM Mode
 16bit timer/counter control register
 Example

18-04-2019 EE561:ECSPC 2
Introduction to ATmega

 High performance ,low power AVR 8-bit micro-controller


 Flash Memory of : 256KB
 RAM/ROM of : 8KB
 General purpose I/O pin 86
 16bit PWM channel : 12
 Total no. of ADC : 16
 Total number of 32 x 8 general purpose registers

18-04-2019 EE561:ECSPC 3
Modes of Operations

The mode of operation, i.e., the behavior of the Timer/Counter


and the Output Compare pins, is defined by the combination of
the Waveform Generation mode and Compare Output mode
bits. Different modes of operation available :
 CTC Mode
 Fast PWM Mode
 Phase Correct Mode
 Phase and Frequency Correct Mode

18-04-2019 EE561:ECSPC 4
Fast PWM Mode

In this mode the Output Compare (OCnx) is set/reset on the


compare match between TCNTn and OCRnx, and cleared at
TOP. As shown in the fig below.

18-04-2019 EE561:ECSPC 5
Fast PWM Mode

COM bits for Fast PWM mode:

18-04-2019 EE561:ECSPC 6
Fast PWM Mode

WGM bits to select Fast PWM:

18-04-2019 EE561:ECSPC 7
Fast PWM Mode

CLK select bit to decide the pre-scaler for Fast PWM:

18-04-2019 EE561:ECSPC 8
16bit timer/counter control register
TCCR1A:

TCCR1B:

TCCR1C:

18-04-2019 EE561:ECSPC 9
Example

Objective: To generate 20KHz signal at 40% duty cycle using


Fast PWM Mode.

To generate 20KHz PWM :

1)Decide the pre scaler (for clkI/O/1 : CSn0=1)

2)Decide the WGM bits (for fast PWM mode where TOP=ICRn
WGMn3=1,WGMn2=1 ,WGMn1=1 )

3)Decide the COM bits(OCnX is reset on compare match and set


on TOP COMnX1=1, COMnX2=0)
18-04-2019 EE561:ECSPC 10
Example

4)Decide ICRn and and OcnX for 20KHz and 40% duty cycle

Total count = 216-1=65,535


Total time in count=(1/16MHz)*65,535=4.09ms
Total time for 20KHz=1/20KHz=0.005ms
Count for 20KHz=65,535*0.05/4.09=800
ICRn=800
OCnX=0.4*800

18-04-2019 EE561:ECSPC 11
Example

Program:

18-04-2019 EE561:ECSPC 12
Example

Output:

18-04-2019 EE561:ECSPC 13
Any Queries ……

18-04-2019 7EETR: PT & IV 14


Thank You……

18-04-2019 7EETR: PT & IV 15

You might also like