You are on page 1of 2

MPI LAB

LAB 6
Generating PWM on Atmega 32

Name : Burhan Ahmed Satti


Enrollment No. : 01-134172-065
Class : BSCS 4-A
Subject : MPI Lab
Lab Assistant : Muhammad Atif

Objectives
•Learning the use of timers
•Learning basics of Atmel studio
•Learning use of timers

Tools Used
•Proteus 8.0
•Atmel Studio 7.0
BSCS 4-A Burhan Ahmed Satti 01-134172-065

Task No. 6.1


Assuming Xtal=1MHz write a program that will generates the square wave of 37.5% duty
cycle, of frequency 3906.25Hz on OC0 pin of ATmega32 using the PWM feature of AVR. We
would use Fast PWM mode of complete this task.
Solution
#include <avr/io.h>
#include <avr/interrupt.h>
# include <util/delay.h>
double dutycyle=37.5;
int main(void)
{
DDRB=1<<PORTB3; // oc0 pin for out put
TCCR0=(1<<WGM01)|(1<<WGM00)|(1<<COM01);//Fast PWM mode and set zero on caparison

OCR0=(dutycyle/100)*255;// assigning duty cycle to ocr0 register

TCCR0|=(1<<CS00); // start timer with one prescale


while(1)
{}
}

Result

Conclusion
The wave has on time for 37.5 percent of the time

MPI Lab Page 2 of 2

You might also like