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

Atmega8 Uc: Timer1 - PWM !!!

PWM is a technique used in microcontrollers to generate intermediate voltages between 0V and 5V by varying the pulse width of a digital signal. It is defined by the duty cycle, which is the ratio of active time (ON time) to the total time period. In AVR microcontrollers like the ATmega8, Timer1 can be used to generate PWM signals using registers like TCNT1, OCR1A, and ICR1 in fast PWM mode. This involves counting up from a bottom value to a top value set in ICR1, and outputting pulses on pin matches to OCR1A while resetting on reaching the top count.

Uploaded by

malhiavtarsingh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
116 views

Atmega8 Uc: Timer1 - PWM !!!

PWM is a technique used in microcontrollers to generate intermediate voltages between 0V and 5V by varying the pulse width of a digital signal. It is defined by the duty cycle, which is the ratio of active time (ON time) to the total time period. In AVR microcontrollers like the ATmega8, Timer1 can be used to generate PWM signals using registers like TCNT1, OCR1A, and ICR1 in fast PWM mode. This involves counting up from a bottom value to a top value set in ICR1, and outputting pulses on pin matches to OCR1A while resetting on reaching the top count.

Uploaded by

malhiavtarsingh
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

ATMega8 uC

Timer1_PWM !!!

WHAT IS PWM?

In this modulation technique, the width of the modulated signal is varied in accordance with input.

Why it is used in Microcontroller?


Pulse Width Modulation (PWM) is a method of getting intermediate voltage between 0V and 5V for e.g. 3.6V

Intermediate voltage is achieved decreasing the width of digital pulse

by

increasing

and

PWM is defined by Duty Cycle of the pulse

DUTY CYCLE
It is the ratio of active time(ON time) to the total time period of the clock cycle

total time period= ON time(TON) + OFF time(TOFF) For e.g.- If an CPU Clock pulse is ON or HIGH for half time period of the pulse so duty cycle is 50%.

FORMULA OF DUTY CYCLE

% DUTY CYCLE=

100

Where Total Time Period= TON + TOFF

PWM GENERATION in AVR


AVR contains separate hardware
PWM can be generated by Timer1 in ATmega8 microcontroller TCNTx, OCR1 A/B, ICR1 registers generates PWM

FAST PWM GENERATION USING TIMER1


In this mode TCNTx register count its value from BOTTOM to TOP Reset to BOTTOM as it reaches TOP to count again While counting up when TCNT1 matched with compare register (OCRxx) an output pin associated with output compare register pulled HIGH When TCNT1 reset to Bottom that pin pulled LOW

FAST PWM MODE


For this mode, we have to set TCNT1 (Timer Counter Register) OCR1A (Output Compare Register) ICR1 (Input Compare Register) TCCR1B & TCCR1A (Timer/Counter Control Register) TIMSK (Timer Interrupt Mask Register)

Program to make PWM of 20ms time period using Fast PWM mode of TIMER1
#include<avr/io.h> #include<avr/interrupt.h> #include<util/delay.h> int count =1; void main()
{

DDRB=0xFF; //DIRECTION OF PORT B AS OUTPUT TCCR1B=0b00011001; //Bit 0-2 for CLOCK SELECT(NO PRESCALING) bit 3-4 for fast PWM //WAVEFORM GENERATION MODE
TCNT1=0; //for initializing timer1 count TCCR1A=0b10100010; //bit 0-1 for fast PWMWAVEFORM GENERATION MODE bit 4-5 for //COM1B1:0, bit 6-7 for COM1A1:0 (10 for both) ICR1=20000; // setting upper limit for count register (Input compare register)

TIMSK=0b00000000; //Timer Interrupt mask set register sei(); //Set Interrupt Enable OCR1A=0x0000; //initiating output compare register from 0 While(1) { if(OCR1A==20000) //checking if OCR1A==ICR1 { OCR1A=0x0000; //resetting OCR1A to 0 value again Count=1; //resetting count value to 1 again } else { OCR1A=(100*count); _delay_ms(10); count++; } } // while close } //main close

THANK YOU!!!

You might also like