Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help needed in generating pwm signal using atmega8

Status
Not open for further replies.

pepakpan

Newbie level 6
Joined
Jun 17, 2009
Messages
14
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,391
atmega8 pwm

Hi guys,

I am using atmega8 µc. I want to generate a pwm of 1MHz frequency.
So can any one help me in programing in assembler.

thankyou
 

pwm atmega

Hello nandhu015,

thankyou for the reply. But the thing is i need 1MHz as output frequency. I am not able to generate it. If you can help me it will be greatfull.
 

pwm signal programming using atmega8

Hi pepakpan.
You can use the Timer0, if you just need a simple pwm signal.

Supose you want a pwm in steps of 255 values (8 bits), with a duty cycle betwen 0% and 100%. You first set a counter variable in 0 (for example count), and in other variable store the desired pwm value (for example pwm_value).

Initialize the Timer0 Counter with an apropiate value, and turn it on. (You must make some calculations to get the correct value, it involves the crystal frecuency, the clock source of timer0, and the desired frecuency of the pwm signal)
Turn on a pin port (for example C0) and turn on the Timer0 (set a clock source)

Each time the Timer0 generates an overflow interrupt you must do some things:
if (count>pwm_value) then (turn off C0)
increase the variable count (count=count+1)
if count =255, then (count=0 and turn on C0).

This is the basic idea, and I'm using it to make nice colors with an RGB led.
Regards.

(I hope this image helps with the idea. Maybe there are some errors with the values, but it is just to show you the main idea, and I'm at work right now :wink: .)
 

pwm programming using atmega8

hai pepakpan

I think with atmega 8 it is impossible, because the max frequency is 16MHz. You can generate 1MHz base frequency for pwm, but variying pwm is not possible.

Regards
Nandhu
 

atmega8

hey guys,
thankyou for the response. By the way I got the requires frquency PWM this is how I made it:

#include <avr/io.h>
int main()
{
//Set up the PWM signal (page 118-119, ATmega8(L))
//The PWM signal is triggered when Timer/Counter register = Output Compare register. (TCNT2 = OCR2)
//attemtp to make the signal 1MHz
// Clk/(2*Dividor*(1+OCR2))
// 3.6MHz/(2*1*(1+1)) = 1MHz
OCR2 = 0x01; //set OCR2 to overflow at 1
// FOC2 = 0;
// WGM20 = 0; //CTC mode. Reset the timer each overflow of OC2 and toggle the PWM value
// COM21 = 0; //
// COM20 = 1; //Toggle on overflow
// WGM21 = 1; //
// CS22 = 0; //
// CS21 = 0; //
// CS20 = 1; //clk/(no prescaling)
TCCR2= 0x19; //set TCCR2 to the above values (0x00011001b)
DDRB = 0x08; //as of right now, only enable the PWM pin as output
while(1);
return 0;
}

Thankyou once again.

pepakpan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top