Professional Documents
Culture Documents
Lab Manual 10
Session Fall 22
Objectives
In this lab, we will.
To understand the concept and working of PWM.
To control the motor speed from 25% to 99% using full PWM.
Equipment/Software Used:
• Microcontroller (ATMEGA 328p/2560)
• Atmel Studio
• Breadboard
• Resistor
• LED
• Jumper wires
• Proteus
Introduction
PWM:
• Pulse Width Modulation (PWM) is a technique by which the width of a pulse is varied while
keeping the frequency constant.
• Pulse width modulation (PWM), or pulse-duration modulation (PDM), is a method of reducing the
average power delivered by an electrical signal, by effectively chopping it up into discrete parts.
Duty Cycle:
A period of a pulse consists of an ON cycle (+V) and an OFF cycle (0V). The fraction for which the
signal is ON over a period is known as the duty cycle.
Code:
#define F_CPU 16000000UL
#include "avr/io.h" #include
<util/delay.h>
int main (void)
{
DDRG=0xFF;
DDRC=0x00;
TCCR0A|=(1<<WGM00)|(1<<WGM01)|(1<<COM0B1)|(0<<COM0B0); //set fast PWM mode with non-inverted
output
TCCR0B =0x01;
while(1)
{
if(PINC==0X01)
{
OCR0B=64;
else if(PINC==0x02)
{
OCR0B=128; //motor speed = 50%
}
else if(PINC==0x04)
{
OCR0B=191; //motor speed = 75%
}
else if (PINC==0x08)
{
OCR0B=252; //motor speed = 99%
}
}
}
Procedure
Open proteus on your computer and place down Arduino Mega 2560, resistors, LED, Push Button,
motor and a ground as shown in the picture.
Copy the hex file from Atmel Software and paste the hex file in the Arduino Mega configuration in
Proteus.
Output (Proteus Simulation)
CONCLUSION
In this lab we basically studied the background process of PWM and how they can be implemented and
accessed beauty using if AVR studio. In this lab we studied how to access the specific register connected to the
particular PWM and how to store value for different types of operations which includes PWM, and we perform
the task to increase the speed of motor from 25% to 99% by using fast PWM and observe the duty cycle of
motor.