#delete this post need help increasing frequency of pwm for motor (noob i am)

need help increasing frequency of pwm for motor (noob i am) outside of human hearing range

i have an UNO R3 MEGA2560 clone(smraza seem crap clone)

motor make aweful lot of noise specialy at low throttle
this code is for using with ebike (already working)
with make the acceleration slow and you can tune the acceleration curve on the go with a POT

if you can help i greatly apreciate

the kind of help is like do it for me :S can't implement whatever i read about prescale or something :S
not like i didn't google how todo this

everything in the code bellow work as intended

/* PWM pour moteur à courant continu avec réglage de la souplesse de conduite (2 potentiomètres).
  Version 1.4, Incroyables Expériences */

void setup() // Boucle d'initialisation.
{
    pinMode(5, OUTPUT);  // Broche 3 réglée comme sortie numérique.
}
float r=0; // Initialisation du rapport cyclique réel à 0.
float s=30; // Initialisation de la souplesse de conduite.
int a=0; // Initialisation du rapport cyclique demandé à 0.
int b=0; // Initialisation de la mémoire du rapport cyclique demandé.
int c=700; // default 70 safety if the throttle  is floored too fast


void loop() { // Boucle principale
  int analogOutputValue = constrain(map(r, 110, 1222, -22, 380), 0,255);
  analogWrite(5, analogOutputValue);
  /*analogWrite(5,r/1023*254); // Création du PWM.*/
  a=analogRead(0); // Lecture du rapport cyclique demandé.
  s=analogRead(1); // Lecture de la souplesse de conduite demandée.

  if(a>b+c){ // Vérification d'une accélération trop brutale (d'origine volontaire ou non).
    digitalWrite(5,LOW); // Arrêt immédiat du moteur.
    while(a>c){ // Attente d'un rapport cyclique très faible pour redémarrer.
      a=analogRead(0); // Lecture continue du rapport cyclique demandé.
    }
  }
  b=a; // Mémorisation du rapport cyclique demandé.

  if(a>r){ // Vérification de la croissance du rapport cyclique demandé.
    delay(20); // Délai responsable de la souplesse de conduite.
    r=r+s/20+2; // Calibrage empirique de la souplesse de conduite.
  }
   if(a<r){ // Vérification de la décroissance du rapport cyclique demandé.
    r=a; // Diminution immédiate du rapport cyclique réel le cas échéant.
  }
  
}

disclamer i didn't make the code its on youtube by some french youtuber
and modded to included some throttle range adjuster

i have an arduino uno atmega358

A what?

seem i dont remember my stuff its an UNO R3 MEGA2560

buder5:
seem i dont remember my stuff its an UNO R3 MEGA2560

Have another guess

cannot be other guess since its taken directly from the selling page

spec say 16Mghz should be plenty if i get to know how to use that freqency
hope i don't need to use pin 9 at all cost i already soldered the wire :S

Edit1:more google search say i should be able todo 900,000hz (ish) on pin 5 that i use

You're saying you have a Uno with a 2560 processor?

That's a lot of wasted pins.

probably i burn pin 3 and was on sale since i didn<t know what good from bad i got the big guy
i got a nano that i didnt tried yet

whatever at 3/14/2020
here the frequency fixed at 30khertz
copy at your will
aslo it was a barebone arduino une r3 with atmega328p

/* PWM pour moteur à courant continu avec réglage de la souplesse de conduite (2 potentiomètres).
  Version 1.4, Incroyables Expériences */
  /*its now in v1.7 from buder :D*/

#include <PWM.h>

            
float THRint =0;              //THRint     requested throttle when thumb removed from throttle                                           // Initialisation du rapport cyclique réel à 0.
float ACCpot=30;              //before was (S) base Accel Initialisation              // Initialisation de la souplesse de conduite.
int THRpot=0;                 //Throttle poteniometer                                 // Initialisation du rapport cyclique demandé à 0.
int THRmem=0;                 //THRmem                                                // Initialisation de la mémoire du rapport cyclique demandé.
int Safety=700; // default 70 safety if the throttle  is floored too fast increase number to disable/lower the safety  sensibility (at 700 is clearly disabled)
int32_t frequency= 32000; 
int Motor = 9;  //THRout is throttle to connect to transistor/driver/led/ebike controller

void setup()                  //setup loop                                           // Boucle d'initialisation.
{
    Serial.begin(9600);
      InitTimersSafe(); 
    pinMode(Motor, OUTPUT);  // pin5 set as THRout  (throttle out)                   
}


void loop() {           // main loop  // Boucle principale
  int insideTHR = constrain(map(THRint, 110, 1200, -22, 340), 0,255);  //custom  hall effect sensor range and output value for use with system(can't explain each number so fiddle with it  it adjust the input range from the hall sensor and the output to the internal code) //  int analogOutputValue = constrain(map(THRint, 110, 980, 0, 340), 0,255); 
  /*analogWrite(5,r/1023*254); // Création du PWM.*/
 /*  analogWrite(THRout, insideTHR);   //writing to pin 5 the throttle sent to a ebike controller or motor driver */

  THRpot=analogRead(A0);               //throttle pot reading                                                      // Lecture du rapport cyclique demandé.
  ACCpot=analogRead(A1);               //acceleration threshold pot reading                                        // Lecture de la souplesse de conduite demandée.

  if(THRpot>THRmem+Safety){            //check for  brutale THRpot request (aka flooring the throttle too fast)    // Vérification d'une accélération trop brutale (d'origine volontaire ou non).
    digitalWrite(Motor,LOW);          //imediatly stop if THRout above Safety                                     // Arrêt immédiat du moteur.
    while(THRpot>Safety){              //waiting for THRpot to be lower than safety to restart                     // Attente d'un rapport cyclique très faible pour redémarrer.
      THRpot=analogRead(0);            // Lecture continue du rapport cyclique demandé.
    }
  }
  THRmem=THRpot; // Mémorisation du rapport cyclique demandé.

  if(THRpot>THRint){ // Vérification de la croissance du rapport cyclique demandé.
    delay(20); // Délai responsable de la souplesse de conduite.
    THRint=THRint+ACCpot/20+2; // Calibrage empirique de la souplesse de conduite.
  }
   if(THRpot<THRint){ //checking if you removed your thumb from the throttle                  // Vérification de la décroissance du rapport cyclique demandé.
    THRint=THRpot; //stop power being sent if above true(aka thumb removed from throttle)    // Diminution immédiate du rapport cyclique réel le cas échéant.
  }
  Serial.println(insideTHR);
      SetPinFrequencySafe(Motor, frequency);   //set frequency and speed 

        pwmWrite(Motor, insideTHR); 
  
}