# Change Frequency arduino mega to 10kHz and 1khz

Hello,

I did many researchs on the subject and I didn't find how to changes the frequency to 10khz and 1khz with an arduino Mega 2560... Because when we use the prescaler, we don't have these values...

My project asks me to do 9 PWM Signals : 6 in 10hkz and 3 in 1khz

Timer 0 --> pin 4 and 13 (980 hz) Timer 1 --> pin 11 and 12 (490 hz) Timer 2 --> pin 9 and 10 (490 hz) Timer 3 --> pin 2, 3 and 4 (490 hz) Timer 4 --> pin 6, 7 and 8 (490 hz) Timer 5 --> pin 44, 45, and 46 (490 hz)

I think I will use timer 3, 4 and 5...

Need help please I am new on arduino programming XD

(deleted)

I have looked and, like I said I am a debutant. So I don't understand why it is not possible with this chip.

I found some possible operations : 16Mhz/prescaler/TOP

16Mhz/128/124 --> 1khz 16Mhz/8/199 --> 10khz

http://www.gammon.com.au/forum/?id=11504

I haven’t studied the data sheet so I don’t know whether this is possible. However I have a question and a suggestion.

How will you know if it works the way you want (or doesn’t)?

As with many Arduino projects, write a short sketch and try out your idea.

…R

// Timer 2 - gives us our 1 mS counting interval // 16 MHz clock (62.5 nS per tick) - prescaled by 128 counter increments every 8 µS. // So we count 125 of them, giving exactly 1000 µS (1 mS) --> 1khz

TCCR2A = bit (CS20) | bit (CS22) ; // prescaler of 128 OCR2A = 124; // count up to 125 (zero relative!!!!)

http://www.gammon.com.au/forum/?id=11504

I don't know if it will work like I wish or not but I have to make some resarch if it is possible or not before to buy the board. My problem is that I need 9 pwm and Arduino ADK Mega 2560 is the only one which proposes enough PWM output....

Do you already have an Uno? You could try the technique on that for 1 or 2 pwm outputs?

What will you do to get your project to work if you buy the Mega and it can't do what you want?

Those are low frequencies. Have you considered writing your own code to produce them without using the timers? Or using the lowest timer frequency in conjunction with your own code to bring it even lower?

Maybe if you write your own code it would work on an Uno?

You haven't explained what the project is or why it needs all those low frequency PWMs? Are you sure they are essential? Maybe someone here could suggest a better way.

...R

I didn't find an other way to have 9 PWM and a compatibility with Labview... Moreover the Arduino has good electrical carateristics for my project. I work on others solutions but I would like to be sure it is not possible.

I have to do : - 6 PWM signals at 10 khz - 3 PWM signals at 1khz They are all independant so I really need 9 differents PWM outputs. This is essential because it is my subject :)

I saw it is possible to up the frequency with a UNO ( http://forum.arduino.cc/index.php?topic=58757.0) so I believe it is possible with a mega too.

On the datasheet (http://www.atmel.com/Images/doc2549.pdf) we can calculate frequencies in differents modes of timers 1, 3,4 and 5. With one of them ( phase and frequency correct mode) I can have 10 khz and 1khz... If it is possible to fix the TOP number as we want

spycatcher2k: Please look at the data sheet for the 2560 chip and you will find the answer why you can't do this.

Well I can do it, perhaps you've less experience with Atmel timers? Timers 1,3,4,5 on the Mega are all identical to timer1 on the Uno, search for previous threads about setting PWM frequencies on timer1...

So I can use the solution for the Uno timer 1 ? (http://forum.arduino.cc/index.php?topic=58757.0) And of course adapt it to the Mega. But with the Uno, we usually speak about inverting or not-inverting mode and I didn't find these with the Mega... So I have to use an other mode ?

mcacj: So I can use the solution for the Uno timer 1 ? (http://forum.arduino.cc/index.php?topic=58757.0) And of course adapt it to the Mega. But with the Uno, we usually speak about inverting or not-inverting mode and I didn't find these with the Mega... So I have to use an other mode ?

They are the same timer module, just change the '1' to '3' or '4' or whatever in the register names. Inverting or not is controlled by the COM[1345][ABC][01] bits in TCCR[1345]A control register (where [abc] means "any of a, b, c")

Section 17.11 of the datasheet I have...

It works !

Thanks for your all responses !