Generating 4 PWM with 10Khz freq

Hi friends,
I am making a project in which I need 4 PWM waveform (with Timer 0 and Timer 1 as I am using Timer 2 for generating different interrupt!)
Can any one could guide me how to generate this freq?

// For Arduino Uno, Nano, Micro Magician, Mini Driver, Lilly Pad and any other board using ATmega 8, 168 or 328**

//---------------------------------------------- Set PWM frequency for D5 & D6 -------------------------------

//TCCR0B = TCCR0B & B11111000 | B00000001; // set timer 0 divisor to 1 for PWM frequency of 62500.00 Hz
//TCCR0B = TCCR0B & B11111000 | B00000010; // set timer 0 divisor to 8 for PWM frequency of 7812.50 Hz
TCCR0B = TCCR0B & B11111000 | B00000011; // set timer 0 divisor to 64 for PWM frequency of 976.56 Hz (The DEFAULT)
//TCCR0B = TCCR0B & B11111000 | B00000100; // set timer 0 divisor to 256 for PWM frequency of 244.14 Hz
//TCCR0B = TCCR0B & B11111000 | B00000101; // set timer 0 divisor to 1024 for PWM frequency of 61.04 Hz

//---------------------------------------------- Set PWM frequency for D9 & D10 ------------------------------

//TCCR1B = TCCR1B & B11111000 | B00000001; // set timer 1 divisor to 1 for PWM frequency of 31372.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000010; // set timer 1 divisor to 8 for PWM frequency of 3921.16 Hz
TCCR1B = TCCR1B & B11111000 | B00000011; // set timer 1 divisor to 64 for PWM frequency of 490.20 Hz (The DEFAULT)
//TCCR1B = TCCR1B & B11111000 | B00000100; // set timer 1 divisor to 256 for PWM frequency of 122.55 Hz
//TCCR1B = TCCR1B & B11111000 | B00000101; // set timer 1 divisor to 1024 for PWM frequency of 30.64 Hz

//---------------------------------------------- Set PWM frequency for D3 & D11 ------------------------------

//TCCR2B = TCCR2B & B11111000 | B00000001; // set timer 2 divisor to 1 for PWM frequency of 31372.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000010; // set timer 2 divisor to 8 for PWM frequency of 3921.16 Hz
//TCCR2B = TCCR2B & B11111000 | B00000011; // set timer 2 divisor to 32 for PWM frequency of 980.39 Hz
TCCR2B = TCCR2B & B11111000 | B00000100; // set timer 2 divisor to 64 for PWM frequency of 490.20 Hz (The DEFAULT)
//TCCR2B = TCCR2B & B11111000 | B00000101; // set timer 2 divisor to 128 for PWM frequency of 245.10 Hz
//TCCR2B = TCCR2B & B11111000 | B00000110; // set timer 2 divisor to 256 for PWM frequency of 122.55 Hz
//TCCR2B = TCCR2B & B11111000 | B00000111; // set timer 2 divisor to 1024 for PWM frequency of 30.64 Hz

with the help of this setting I know how to make these freq PWM signal but I am not getting on how I can generate that 10kHz freq!
If needed I can give up little resolution to make this pwm freq too!
Can any one could guide me on it?

Hi Yatin. Unfortunately you cannot do it.

To get 10 kHz you need to be able to vary the top count of the timers, otherwise you only get the fixed frequencies as per the comments in the code you quoted (or double those values if you use fast PWM mode instead of phase correct PWM).

Timer1 can do it (and still have two PWM outputs) but unfortunately timer0 or timer2 cannot. Timer1 has an adjustable top count via register ICR1, so you can set that register (and appropriate mode) to get 10 kHz.

Timer0 and Timer2 however can only adjust the top count by using their OCRA register for that purpose. This means that one of the compare registers is no longer available for PWM, so you can only have one PWM output if attempting to use any frequency other than the ones listed above.

If you need to get two PWM outputs from either Timer0 or Timer2, the closest you can get to 10kHz is 7.8KHz (using fast PWM mode and a prescaler of 8 ).

You can get 200 steps of fast-PWM or 100 steps of phase-correct PWM at 10000 Hz by using a prescale of 8.

Ok so with only 3 timers available I cant Make 4 10 kHz Pwm with One timer use to make an interrupt?
(2PWM on timer 1 and 1 PWM on timer 0 Interrupt on timer 2 so get short for 1 PWM!)
Is there any other way to make it happen?

yatin:
so get short for 1 PWM!

Yes. Unless of course you can still use timer2 for the unspecified interrupt while also using it for one of the PWM waveforms. The PWM usage will require the use of both of the timer's "on compare registers", so I don't see much flexibility remaining for you to also use it as an interrupt source.

Anyway, tell us the nature of the interrupt that you need to generate.

yatin:
Is there any other way to make it happen?

You could switch to an Arduino MEGA 2560 which has fifteen PWM output pins. That way you could leave Timer0 alone and keep the millis() and micros() functions that you or a library might depend on.

Cant Switch On MEGA due to product cost limitation!
I am generating a interrupt for 332 times a Second in wich I have to generate Some Sequence which I want for BLDC motor to drive!

yatin:
Cant Switch On MEGA due to product cost limitation!
I am generating a interrupt for 332 times a Second in wich I have to generate Some Sequence which I want for BLDC motor to drive!

Ok, then you should be able to synchronize that reasonably well with one of the PWM timers. At 10KHz then every 30th cycle gets you to 333.3 times per second. Is that close enough?

If the above is not close enough then you can get 9.950kHz for the PWM (by increasing the top count from 200 to 201), and this gets you to about 331.7 times per second using every 30th PWM cycle.

Are either of those options close enough for what you need?