Pages: [1]   Go Down
Author Topic: pwm at 31 Khz, on a mega 1280  (Read 465 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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,
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This may be of use: http://www.arduino.cc/playground/Main/TimerPWMCheatsheet
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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?
« Last Edit: February 29, 2012, 08:17:52 am by gazz » Logged

Pages: [1]   Go Up
Jump to: