Lab 2 ESD
Lab 2 ESD
Date: 20th-Oct-2016
Section: BEE-5 Group 2
Group:12
Name
1 Muhammad Umer
5121
5041
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;
//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.