Go Down

Topic: pwm at 31 Khz, on a mega 1280 (Read 558 times) previous topic - next topic


i'm using my arduino mega 1280 as the interface between x-sim and vehicle gauges,

i will be running 3 gauges with a pwm signal, (fuel, water and oil) which in the vehicle would be a variable resistance to earth to move the needle,

i'm using the standard 'analogWrite' function, the gauges work, but the coils in the gauge sing,

Someone said a good way to stop the noisy gauges is to change the pwm frequency to 31Khz,

But i'm getting confused by googleing, and especially the problems with certain counters being messed up when you alter the frequency of certian timers,

I believe there is a timer on the mega that runs 3 of the pwm pins,
can someone please show me how i change the frequency to 31Khz for these pins, idealy with some code in the script, so i can upload other scripts and have it back to normal.

i'm using the serial port (usb) as the connection to x-sim, and the tone lib. to feed the variable frequency to the rev counter and speedo, and will be driving 4 servo's as well,



Feb 29, 2012, 02:08 pm Last Edit: Feb 29, 2012, 02:17 pm by gazz Reason: 1
From what i've read, i should leave timer 0 alone as that's the one that affects the milli's timing,

timer 1 affects some other importiant stuff, and one of the timers is used by the servo lib. so i need to avoid them,

Thinking timer 4 is best??
works pins 6, 7 and 8,

So adding :
Code: [Select]
TCCR4B = TCCR4B 0b11111000 | 0x01
somewhere sets timer 5 to 31.250Khz?

Any other code i need to add? and do i add it in the setup part?

Go Up