Can I increase the PWM speed for all 6 PWM pins

Newbie alert!

Is it possible to increase the PWM speed/frequency for all 6 PWM pins from the default 490hz to something like 2khz and how would this affect PWM resolution?

Thanks for any answers.

Two of the PWM outputs share the main arduino timer used to implement millis(), delay(), and so on, so THAT one would be relatively difficult to change.

I don't know about the other 4. (Note that there are two PWM outputs per timer, so whatever happens happens two outputs at a time...)

Hi
It depends what you want to do with them!
I have used an ATmega8 to drive 6 x RGB leds using PWM (i.e. 18 outputs).
I don't use the analogWrite functions, but instead intercept the timer 2 interrupt, which I program to run every 128uS (7.912kHz). Because so much time is spent in the interrupt service routine (because it runs so often), I wanted as little processing as possible in the ISR, so I have done all the "clever" processing in the main line code which just sets up RAM data arrays for the ISR to read and output.
I'm not sure whether this helps you to solve your problem, but it does show what is possible.

I'm trying to generate CV voltages for a music synthesizer and a filtered 490hz pwm isn't good enough.
If I can raise the frequency to around 2khz, I can get the response time to where I need it.

Take a look here http://usethearduino.blogspot.com/
it may be helpful

1 line of the code seems to be garbled but it is still looks like a good start

@ Wiz.

Thank you. That's exactly what I was looking for.

Something else I just thought of.
I did this ages ago as an experiment to do 10 bit pwm

#define ledPin  9

void setup()
{
  pinMode(ledPin, OUTPUT);
  
//  TCCR1B = 25;
//  TCCR1A = 242;

  
  TCCR1B |= (1<<WGM12) | (1<<WGM13) | (1<<CS10);

  TCCR1A |= (1<<WGM11) | (1<<COM1A1) | (1<<COM1A0);
  TCCR1A &= ~(1<<WGM10);

  ICR1 = 1023; 
}


void loop()
{
  int potVal;
  
  potVal = analogRead(0);
  OCR1A = potVal;  

}

WIZ;

I pasted your 10 bit PWM sketch into my Aurduino and it worked right off the bat, however I have a few questions:

  1. Using a pot when I have 0vdc on the analog input then pin 9 is high all the time and when putting 5vdc analog in then pin 9 is low all the time, and at 2.5vdc I get a 50% duty cycle. This apparent inversion is on purpose or can be inverted some way? The PWM frequency is around 250hz, is there a way to increase this?

  2. Very little comments in your code so I haven't a clue how it's working being new to C. Does this really use 10bits of resolution?

  3. Does this routine use any timers or resources that would conflict with other functions?

Thanks
Lefty

I also found this:-

http://www.societyofrobots.com/member_tutorials/files/ATMega168.pdf

All the info comes from reading the ATMega168 datasheet, it is hard work & takes a long time to absorb everything & understand which registers control which timers etc.
If you have the datasheet take a look at around page 109 which deals with 16 bit PWM. That is how I managed to write the very crude piece of code above.
It has very little to do with C and is really just writing values to the timer & compare registers necessary to change the PWM behaviour.
After a quick look it seems like inverting the output can be done by changing the last line of the code to

OCR1A = 1023 - potVal;

but it would be much nicer to write the proper values to the registers to achieve the same effect.

If I get time I will try and post a few more details about what the code above does.