PWM at 20KHZ with a DC motor - PWM library

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);
}

Here is my code

A link to the library where the real work is done seems to be in order.

Here is the library:

Arduino PWM Frequency Library v_05.rar (13.7 KB)

What kind of motor is it? How is it connected to the Arduino? DC motors don't generally need 20KHz PWM.

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

The maximum arduino mega current is 50mA. You need a motor shield module for more current. They can even give a 4A output.

Why are you replying to a 3 year old thread?