Go Down

Topic: frequense modification of PWM signal (Read 1 time) previous topic - next topic

Mikkel_Callesen

Hi

I have a project where i whant to make a PWM signal between 2 kHz and 10 kHz, but the standart is 490-500hz. how do i modify the frequense?

MarkT

Ideally there should be a library for more advanced driving of the timer/counter/pwm hardware - but it seems not.

You can look at the description in the ATmega datasheet.  Its fairly complex as there are 16 different modes and three different timers.
 
I've an attempt at a tutorial for this stuff at http://www.mythic-beasts.com/~markt/ATmega-timers.html but it may not be very readable, its a first stab at it and incomplete.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Grumpy_Mike

This might help:

//Gestione PWMmode con frequenza base di 25K0Hz.

void setup(void){
//impostazione TIMER3 per PWMmode
TCCR3A=0b00110010;
TCCR3B=0b00010001;
ICR3=32;
OCR3B=16;
}

Mikkel_Callesen

what does the code do?  sets the PWM frequnse to 25 kHz??  in that case how would I change it to lets say 2 kHz??
Code: [Select]

//Gestione PWMmode con frequenza base di 25K0Hz.

void setup(void){
//impostazione TIMER3 per PWMmode
TCCR3A=0b00110010;
TCCR3B=0b00010001;
ICR3=32;
OCR3B=16;
}


I would like to know so  I have an idea of what every part of my program does..

Grumpy_Mike

It sets the values in the counters. See the processor data sheet for a full explanation of what they do.

Go Up