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.

Generating fast PWM signal

Status
Not open for further replies.

nzkunal

Member level 2
Joined
Mar 11, 2004
Messages
52
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
377
Hi,

I am trying to write some code to generate a fast PWM signal (8-bit Timer). I am using an Atmel ATMEGA48 and for simplicity have chosen port D6 that corresponds to OCR0A.

I have read the data sheet and am trying to figure out what code I need to operate this channel.

Initialization
TCCR0A=ox83 so COM0A=2 for non-inverting and WGM0[2:0]=3 for TOP=MAX
Is this the only initialization I need to perform

Controlling duty cycle
Change OCR0A i.e. if OCR0A=0x7F will give 50% duty cycle

Does this code look correct?

Thanks
 

Hi!
Try this code. It is working for me. The external clock is 4MHz.

void timer0_init(void)
{
TCCR0B = 0x00; //stop timer
TCNT0 = 0x00; //clear count
OCR0A = 200; //set pwm frequency
OCR0B = 20; //set duty cycle (for 50% duty set it to 100)
TCCR0A = 0x33; //start timer

}

In addition to this it has been clearly mentioned in the data sheet that the output will be visible on the corresponding output pin (OC0x) if and only if its direction is set as an output pin.

Hope this solves your problem.
Regards.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top