Go Down

Topic: Change PWM frequency (Read 350 times) previous topic - next topic

cagnarrogna

Hi everybody!

In my program I need a very slow PWM signal where I can change the duty cycle, and since in the meanwhile I want to keep reading serial data I was planning to use the PWM function of the atmega.

I've been reading around how to do it
http://www.electronicsblog.net/atmega8-pwm-controlfrequencypolarityduty-cycle-example-tutorial-with-program/
http://www.nunoalves.com/classes/spring_2012_cpe355/cpe355-02-f.pdf

and so far I succeed in changing PWM duty cycle by changing OCR2 but I had no success in shifting down the frequency.
I have an arduino ng with atmega8, the pwm signal is on pin 9 and below there's the code for changing the PWM timing options

thanks!


Code: [Select]


void setup()
{
  TCCR2=0x6F; //1024 prescaler
  OCR2=0x1A; // 10% duty cycle -> 256/10=25,6 26 in hex = 1A;
}


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy