Faster PWM?

Hi,

please dont you know if it possible to make PWM faster? The normal rate is aprox 490Hz but I need at least 10times faster.

( The reason: I use led matrix with columm refresh rate cca 500Hz and the PWM drives the brightnes of each row. The rate of columms is similar as PWM and thats the problem. The slower columm rate is not possible - the whole matrix starts blinking and is possible to detect the steps...)

Thanks a lot :)

Changing PWM speed was discussed in this thread: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235060559

It would be interesting to hear if the information solves your problem.

Thanks. Looks quite complicated.... because I want all 6 PWMs get on the same rate cca 5khz or faster. I will read it today and check it (hopefully) :P

I don’t think you can change the PWM rate for the two Timer0 analogWrite pins unless you change the code to calculate millis.

Have you considered if there is a simple solution using some external hardware?

Hi,
I´ve used the solutuion of macegr (great help!):

Pins 5 and 6:
Setting Divisor Frequency
0x01 1 62500
0x02 8 7812.5
0x03 64 976.5625
0x04 256 244.140625
0x05 1024 61.03515625

TCCR0B = TCCR0B & 0b11111000 | ;

Pins 9 and 10:
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 64 488.28125
0x04 256 122.0703125
0x05 1024 30.517578125

TCCR1B = TCCR1B & 0b11111000 | ;

Pins 11 and 3:
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 32 976.5625
0x04 64 488.28125
0x05 128 244.140625
0x06 256 122.0703125
0x07 1024 30.517578125

TCCR2B = TCCR2B & 0b11111000 | ;

All frequencies are in Hz and assume a 16000000 Hz system clock.

…and it works!
Great. The PWM is now fast enough so the unwanted interferencies are lost away.

The timers changed, so also micros() are different - but I can manualy change the timing step rate from MAX/MSP so this is not problem.

BUT there is another problem :’( :
always when I send data from MAX/MSP through SimpleMessageSystem library the led stops shining for I while.
It looks like the data transfer always interrupt the PWM output for a while. It makes led blinking, when I am changing brightness values. And I want it smooth… :-/
I dont know how works the SimpleMessageSystem library, but for sure there are some Serial.read() functions. I run 9600baud, but the speed change doesnt solve the problem. Does Serial.read, interrupt the PWM output?

Please does anyone have any idea how to improve it?
Thanks a lot :slight_smile:

mem: I didnt find led matrix driver with fading effect for each led. There are many for just for on/off. So I decide to use ATMEGA168... Maybe there is somethung on the market, but i didn´t find it.

It looks like you are close to a software only solution so perhaps best to stick with that if you can solve the remaining issues.

If you do need hardware pwm support you could use the TI TLC5940 chip. Its probably overkill for what you want and have not used it myself, but the datasheet indicates it works up to 7khz or so.

good luck

mem: Oh shi... TI chips looks very good. I wish I knew it before I started. But now I am almost finished with ATMEGA168. It works fine - only problem is interrupting the PWM outputs, when I am sending data from MAX/MSP. ( I started new thread about it: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1237283565 )

Anyway, thanks for a very good tip ;) J.

hello!
I’m quite new to the Arduino but i’ve already done some small things.
The project i’m working now is that I’m using Max/Msp to control a motor which is connected to the arduino board. Everythings works fine except that i can hear the pwm frequency of 490Hz.
The solution of jura sounds quite nice but how can i include this into my arduino sketch or what do i have to do with this code:

Pins 5 and 6:
Setting Divisor Frequency
0x01 1 62500
0x02 8 7812.5
0x03 64 976.5625
0x04 256 244.140625
0x05 1024 61.03515625

TCCR0B = TCCR0B & 0b11111000 | ;

Pins 9 and 10:
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 64 488.28125
0x04 256 122.0703125
0x05 1024 30.517578125

TCCR1B = TCCR1B & 0b11111000 | ;

Pins 11 and 3:
Setting Divisor Frequency
0x01 1 31250
0x02 8 3906.25
0x03 32 976.5625
0x04 64 488.28125
0x05 128 244.140625
0x06 256 122.0703125
0x07 1024 30.517578125

TCCR2B = TCCR2B & 0b11111000 | ;

???

I need a freuquency which i can’t hear.
I’m using pin 11 for the pwm signal to the motor.
and pin 12 for the relais to switch the dc signal so that i can drive the motor in both directions.
I’ve a Arduino Diecimilia (Atmega 168) and a Arduino Duemilanove (Atmega 328)

here is my arduino sketch:

/* Motorcontrol for a rotary loudspeaker with MAX/MSP and Arduino
   Thomas Mayr
*/

int motor = 11;    //initialize the pin for the pwm signal
int relais = 12;   //initialize the pin for the relais pin
int val = 0;       //value for the serial signal from max/msp

void setup()
{
  Serial.begin(9600);
  pinMode(motor, OUTPUT);
  pinMode(relais, OUTPUT);
}
 
void loop()
{
  if(Serial.available())
  {
    val = Serial.read();
    
    if(val > 250)    //Under 250 the values are reserved for the pwm signal
    {
      if(val == 252) //this value is reserved to set the relais as HIGH
      {
        digitalWrite(relais, HIGH);
      }
      else if(val == 253)  //this value is reserved to set the relais as LOW
      {
        digitalWrite(relais, LOW);
      }
    }
    else
    {
      analogWrite(motor, val);
    }
  }
}

It would be really nice if anyone of you could help me out!
Many Many thanks!
moali

hello! Is there anyone in this forum who could help me out in changing the pwm frequency of my arduino board? I described my problem one post above! I would really appreciate that! thanks a lot! moali