You Are Here: Home » AVR ATmega Projects » PWM Projects » Phase Correct PWM (Pulse Width Modulation) Mode of AVR microcontroller Timer

Phase Correct PWM (Pulse Width Modulation) Mode of AVR microcontroller Timer

Pulse Width Modulation is well known technique for controlling power electronics devices like SCR, IGBT etc. PWM is also used in motor speed controlling. Square wave generation by using AVR timers is explained in previous article. The AVR timers have feature of PWM wave generation as well .This article describes PWM generation capability of AVR timers.

There are four in-built PWM channels in ATmega16. The PWM outputs are received on pins OC0, OC1A, OC1B and OC2. Readers can refer the previous article which gives explanation of these pins. There are two modes of operation of AVR timer which are able to generate PWM signal.
            1. Phase correct PWM mode
            2. Fast PWM mode
 Phase Correct PWM (Pulse Width Modulation) Mode of AVR microcontroller Timer
PWM generation by Phase correct PWM mode:
The Phase correct PWM mode can be selected by assigning bits WGM0[1:0]=01. This mode is based on dual slope operation. In dual slope operation, TCNTn counts from bottom value to maximum value and maximum value to bottom value. The OCRn register compares the value with the TCNTn register constantly during up-counting and down-counting. On compare match PWM output pin (OCn) behaves according to inverting or non-inverting mode which can be selected by programming of COMn [1:0] bits. The following table shows bit setting of COM [1:0] bits:
Phase correction PWM mode is preferred for motor controlling because dual- slope operation provides symmetric wave generation. Duty cycle of pulse can be varied by writing the values to OCRn register. The OCRn value can be calculate by the following formula:
For example: if duty cycle is 75%
                    OCR value = (75÷100) × 256
Frequency of PWM output will be
Objective : Generate PWM signal of duty cycle 75% from timer 0.
 Phase Correct PWM (Pulse Width Modulation) Mode of AVR microcontroller Timer schematic
Circuit description:
The connection of ATmega16 is shown in circuit diagram. Since, Timer0 is used to generate PWM wave then output is taken on OC0 pin, so pin no.4 is connected to C.R.O to observe the waveform.

This free embedded project also found using:

  • atmega pwm explained
  • phase correct timer
  • PWM OC2 at mega32
  • using OC1A and OC1B simultaneously fastpwm mode bits value in AVR atmega32

About The Author

Number of Entries : 6710

Leave a Comment

You must be logged in to post a comment.

Read previous post:
Five ways to become a smaller target for ransomware hackers

Hacking for ransom is on the rise—on pace to beat out last year's figures—and hits people where it hurts, locking...

Scroll to top