Hey guys, i am trying to control a dc motor with the pwm library (Arduino mega 2560) but the frequency that is generated it's too low because the motor doesn't move. I tried with 20KHZ frequency and didn't work. Here is my code:
#include<PWM.h>
int motor = 11 , valor_adc , tension;
int32_t frequency = 20000;
void setup(){
InitTimersSafe();
bool success = SetPinFrequencySafe(motor,frequency);
}
void loop(){
valor_adc=0;
valor_adc=analogRead(A0);
tension=valor_adc/4;
pwmWrite(motor,tension);
delay(30);
}
Its a DC motor 12 V - 10000 rpm, by the way when i measure the frecuency on proteus, it shows 2500 Hz (with the code i wrote above) so i think that's why the motor doesn't work, but with a led obviusly works. My image connection is attached (1.png).
First off you need to tell us exactly which motor and power supply - otherwise its guesswork.
"DC motor 12V 10000rpm" isn't much to go on. 1A? 100A?
Anyway you claim to be using an IRF830, which is not a logic level MOSFET, and needs
10V gate drive. You give it 5V gate drive. Obviously cannot work. Furthermore that
MOSFET is 1.5 ohms on resistance, which is way too high - something with a hundred
times lower on-resistance is more appropriate. No 500V MOSFET will have anything
like the specs needed to drive a high current load at 12V, a 20V or 30V MOSFET is
needed. Why did you choose a high voltage device?
So you need a logic-level MOSFET in the 20 to 50V range with an Rds(on) of
between 50 and 5 milliohms (depending on the motor's current rating which you
haven't told us). Don't confuse Vth (threshold voltage), that's irrelevant, you need
to see "logic level" of a value of Rds(on) quoted at "Vgs=4.5V"
You also haven't explain this clearly:
by the way when i measure the frecuency on proteus, it shows 2500 Hz (with the code i wrote above) so i think that's why the motor doesn't work