Thanks for getting back to me. The frequency I’m using on pin 9 of my ATmega2560 is the default frequency which is 490 Hz. I did some searching and found this thread which sounds good if I am understanding it correctly.
This URL is where I found the information below: http://forum.arduino.cc/index.php?topic=72092.0
According to what I read the PWM default frequency for the ATmega2560 is 490 Hz for all pins, with the exception of pins 13 and 4 which is 980 Hz.
According to valerio_sperati, I can change the prescaller for pins 10 and 9 to change to the different frequencies that are available. First I have to clear the 3 bits in the prescaller using:
int myEraser = 7;
TCCR2B &= ~myEraser;
now that the prescaller is cleared I can include these two lines of code below to write a new value:
int myPrescaler = 3; // 3 = 490 Hz (default value)
TCCR2B |= myPrescaler;
changing myPrescaler value above from 1 to 6 will change the frequencies to the ones listed below:
prescaler = 1 —> PWM frequency is 31000 Hz
prescaler = 2 —> PWM frequency is 4000 Hz
prescaler = 3 —> PWM frequency is 490 Hz (default value)
prescaler = 4 —> PWM frequency is 120 Hz
prescaler = 5 —> PWM frequency is 30 Hz
prescaler = 6 —> PWM frequency is <20 Hz
So am I correct in thinking that all I have to do is put these 4 lines of code above into the void setup() portion of my sketch and set to whatever frequency I want to try? I’m at home today but will be going to the shop tomorrow to try this new code. I should try it as you suggested at 31000 Hz which would be an ultrasonic frequency and above the frequency humans hear at and hopefully that’ll fix my noise problem. Any insights you have on this subject will be very appreciated especially to hear that I got the code deciphered right.
Also could you have a quick look at the schematics I just uploaded here to see what you think. If you have the time I’d really appreciate it if you could advise me of what optoisolator you would consider to be compatible to isolate the mosfet in the schematics? You had advised me in a previous post that I quoted below:
-48V is 48 volts below ground. You meant 0V, GND or 48V(-)
You can get opto-isolated gate drivers, standard opto-isolators may be too slow and weedy to switch
a MOSFET gate for high power use (the switch off time is dominated by the photo-transistor
charge-storage delay). Are you wanting PWM or just on/off?
How much power are you controlling BTW? In particular can vast currents flow in stall conditions
and risk popping the MOSFET? In those circumstances you would want more protection circuitry
(probably a gate driver chip with resitor/zener clamp on its logic input, or opto-isolated)
In that Post you suggested that I possibly needed a gate driver chip with resistor/zener clamp on its logic input, or opto-isolated. I managed to find a fairly inexpensive MOSFET gate drive optocoupler part #IX3180 and digikey has some in stock and they are fairly inexpensive. There are a lot of these opto isolators with specs I don’t understand out there and I’d really appreciate it if you could recommend a chip if this one I found isn’t suitable.
Arduino PWM motor speed controller code.txt (588 Bytes)