0% found this document useful (0 votes)
23 views

Lab 2 ESD

The document summarizes an embedded systems lab experiment on generating pulse width modulation (PWM) using an AVR microcontroller. The objective was to implement PWM on an ATMEGA16 microcontroller to vary the brightness of an LED. The lab tasks involved including a power-on reset circuit and generating a PWM signal with a timer to vary the duty cycle and brightness of the LED from 0% to 100% and back. The code defines functions to initialize PWM on a timer channel, set the output duty cycle, and delay. It implements an infinite loop that gradually increases then decreases the LED brightness by adjusting the duty cycle. The conclusion confirms that timers can be used for PWM to control power to a circuit by varying the duty cycle.

Uploaded by

Mahmood Sh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lab 2 ESD

The document summarizes an embedded systems lab experiment on generating pulse width modulation (PWM) using an AVR microcontroller. The objective was to implement PWM on an ATMEGA16 microcontroller to vary the brightness of an LED. The lab tasks involved including a power-on reset circuit and generating a PWM signal with a timer to vary the duty cycle and brightness of the LED from 0% to 100% and back. The code defines functions to initialize PWM on a timer channel, set the output duty cycle, and delay. It implements an infinite loop that gradually increases then decreases the LED brightness by adjusting the duty cycle. The conclusion confirms that timers can be used for PWM to control power to a circuit by varying the duty cycle.

Uploaded by

Mahmood Sh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Department of Electrical Engineering

Faculty Member: Dr. Awais Kamboh


Lab Engineer: Asma Majeed

Date: 20th-Oct-2016
Section: BEE-5 Group 2

EE-423: Embedded System Design


LAB2:PWM generation using AVR
Microcontroller

Group:12
Name

1 Muhammad Umer

Demo Report Viva


Marks Marks Marks
Reg No.
/5
/5
/10

5121

Syed Muhammad Hassan


Askari

5041

Syed Mohsin Abbas Kazmi

5715

4 Mahmood Shah

6715

Total
Marks / 20

OBJECTIVE:
In this lab, we learned how to implement Pulse width modulation in AVR
microcontroller ATMEGA16. We glowed an LED using Fast PWM
generated by using AVR timers.
LAB TASK:
1. To ensure that the micro-controller is reset when powered-on, you
need to include a small circuit, typically called Power-on-Reset
(POR). This POR circuit helps detect supply voltage drops as well
and ensures that your microcontroller does not power up in an
unknown state.
Given in the hardware Circuit
2. Vary the brightness of a LED using pulse width modulation (Fast
PWM with non-inverted output) generated by AVR timers (using
timer 2 will allow you to earn extra credit). Start with
minimum brightness and increase it gradually and then again
reduce it gradually to zero. Simulate in Proteus and burn on
microcontroller. (Hint: Generate PWM signal with duty cycle
varying from 0% to 100% and from 100% to 0 %.)

Code:
#include <avr/io.h>
#include <util/delay.h>
void PWMinitialized()
{
TCCR0|= (1<<WGM00)|(1<<WGM01)|(1<<COM01)|(1<<CS00);
DDRB|=(1<<PB3);
}
void OutputPWMset(uint8_t duty)
{
OCR0=duty;
}
void prolong()
{
_delay_loop_2(3200);
}
void main()
{

//BRIGHTNESS
uint8_t brgtns=0;

//initialize the PWM channel 0


PWMinitialized();
//Infinite Loop
while(1)
{
//Increasing brightness
for(brgtns=0;brgtns<255;brgtns++)
{
OutputPWMset(brgtns);
//Wait
prolong();
}

//Decreasing brightness
for(brgtns=255;brgtns>0;brgtns--)
{
OutputPWMset(brgtns);
//Wait
prolong();
}

Conclusion:

We demonstrated with the help of circuit that we can use timers for
implementing PWM in ATMEGA16. By controlling the duty cycle of a
signal, the power generated to your circuit load can be controlled.

You might also like