RPM to Speedometer Help Thanks

Hi i have a working ebike speedo that i can control with a motor speed control sketch
and i aslo have a hertz to rpm sketch ready
Thanks for any help you can give me
Disclaimer i am still a beginner i have lot to learn

i would like to know how to convert this signal into action on the speedo
when i give these signal to the speedo it = that on the speedo

254-255 = 35km/h
217-218 = 30km/h
187-188 = 25km/h
146-147 = 20km/h
126-127 = 15km/h
87-88 = 10km/h
59-60 = 5km/h

additional info
Arduino uno r3 with atmega328p the non SMD variant
Hall Effect Sensor 3144 was used

my electric scooter is capable of 35km/h when the wheel spin in the air for a total RPM(730-735)wich = 35km/h ish with calculator
i will be using 2 magnet on the wheel maybe 4 in the future

my plan if no help given
i will use alot of IF argument for each km/h with is inefficient for my taste hehe

motor sketch i used for the speedo testing
i will aslo merge the rpm sometime

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

Hertz to RPM sketch
i didn’t make it i just added the part that make hertz to rpm readable for me

/* 
 *  Frequency Measurement Using Arduino
 *  Inpout is given to Pin 2
 *  Uses Interrupt to get pulse duration
 *  F = 1 / pulse duration
*/

#define MainPeriod 100

long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

void setup()
{
  Serial.begin(9600); 
  attachInterrupt(0, myinthandler, RISING);
}

void loop()
{
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.println("Hz"); 
    int RPMmulti = Freq*30;
    Serial.print("RPM: ");
    Serial.print(RPMmulti);

  }
}


void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

for the speedo in action controlled with the motor sketch

Why not just take each pulse as a given distance from the wheel.

the only pusle i get is the rpm and or the Hertz
no idea what you mean though o.0

the speedo is not linear i kind of see a curve with the number
i need a chart to see but no idea how to make 1(googling how to)

maybe its linear

then i need to convert 0-735 to 0-255

i think i saw that in the arduino tutorial revisiting time

well im stuck now

the part
messup the rpm reading
i reading the fan speed with is around 1000-1300 rpm (for testing)
when i activate this code part it become 8000+
and speedo going back and forth unstable

there difinitly something i dont understand

/*
Speedo = (255./1300.)*RPMmulti;
Serial.print(" Speedo ");
Serial.print(Speedo);
//analogWrite(10,Speedo);
pwmWrite(10, Speedo);
*/

merged rpm+motor controller

/* 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*/
/* 
 *  Frequency Measurement Using Arduino
 *  Inpout is given to Pin 2
 *  Uses Interrupt to get pulse duration
 *  F = 1 / pulse duration
*/


#include <PWM.h>
#define MainPeriod 100

long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

float Speedo;            
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); 
  attachInterrupt(0, myinthandler, RISING);
      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 
      SetPinFrequencySafe(10, frequency); 
      
        pwmWrite(Motor, insideTHR); 
          unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.println("Hz"); 
    int RPMmulti = Freq*30;
    Serial.print("RPM: ");
    Serial.print(RPMmulti);
/*    
Speedo = (255./1300.)*RPMmulti;
    Serial.print(" Speedo ");
    Serial.print(Speedo);
//analogWrite(10,Speedo);    
pwmWrite(10, Speedo); 
*/
  }
  
}
void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

Edit1: yeah i dont understand why RPMmulti because something between actual rpm and 8000+
everytime i activate the part
Speedo = (255./1200.)*RPMmulti;
1200 is max rpm range of the fan motor (for testing)

buder5:
the only pusle i get is the rpm and or the Hertz
no idea what you mean though o.0

You said it is an ebike so take a pulse off the wheel and re-read my previous reply.

Hi,
Please explain how and where you get the "hertz" signal from?
How have you got the Arduino connected to measure this frequency?

Have you googled

Arduino tachometer

This will give you the basics, turning RPM to kph will then be straight forward.

Tom.. :slight_smile:

i use hall sensor and magnet on fan

read the sketch Hertz to RPM sketch

what i need is convert a 0-735RPM to a signal from 0-255
and write it to pin10

and everything about googling tachometer are useless mostly
none of them fit what i need

but for whatever reason if i put the signal to be between 0-1200rpm (because i test on a fan and go to 1200rpm)
well the rpm number jump all over the place up to 8000+

2 pot connected to A0,A1
hall sensor connected to D2
speedo conected to D10
Motor speed connected to D9 (unused but there no problem)

what i need is convert a 0-735RPM to a signal from 0-255

pwmWrite(Motor, insideTHR);

Ok, so it looks like you want to get insideTHR to a value between 0-255.

See the reference documentation on constrain.constrain() - Arduino Reference

"avoid using other functions inside the brackets, it may lead to incorrect results."

This is likely a problem.

int insideTHR = constrain(map(THRint, 110, 1200, -22, 340), 0,255);

Separate the mapping from the constraining. I would also advise a review of the map documentation. map() - Arduino Reference

What is the circumference of the scooter wheel?

32"
the wheel roughtly 11"
and the constrain map thing is working as intended but i will still review those thing
the insideTHR is part of the motor controller with work #1
i will still review those and come back in a few day

32/pi = 10.1859163579 (according to Google :slight_smile: )

Will make a difference over miles per hour.

It would be interesting to know the cause of the non-linearity.

I have been using a HE sensor on my car's wheel drive shaft feeding a Nano which converts it to speed.

The code is almost trivial. The device works perfectly. The relationship between the time between pulses and rpm and speed is linear.

John.

now im piss the autosave just screwed all my backup and have to redo everything >_>
autosave now disabled

now i added the inside thr and speedo
but now the SpeedoPin allway output a value of 10 when the Speedo work properly between 0-255 based on rpm
where did i screwed up ?

/* 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>
#define MainPeriod 400


long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

int Speedo;
int RPMmulti;
            
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=7000; // 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
int SpeedoPin = 10; //Speedo Pin

void setup()                  //setup loop                                           // Boucle d'initialisation.
{
    Serial.begin(9600);
      attachInterrupt(0, myinthandler, RISING);
      InitTimersSafe(); 
    pinMode(Motor, OUTPUT);  // pin5 set as THRout  (throttle out)      
     pinMode(SpeedoPin, OUTPUT);  // pin10 set as to speedo mosfet      
}


void loop() {           // main loop  // Boucle principale

int MapTHRint = map(THRint, 110, 1200, -22, 340);
int insideTHR = constrain(MapTHRint,0,255);


  

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

        
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.print("Hz "); 
    int RPMmulti = Freq*30;
    Serial.print(" RPM: ");
    Serial.print(RPMmulti); 



int MapRPMmulti = map(RPMmulti, 0, 2600, 0, 340);
int Speedo = constrain(MapRPMmulti,0,255);




    Serial.print(" Speedo: ");
    Serial.print(Speedo);
    
    Serial.print(" SpeedoPin: ");
    Serial.println(SpeedoPin);
    
    digitalWrite(SpeedoPin,Speedo);
 
}


}



void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

but now the SpeedoPin allway output a value of 10 when the Speedo work properly between 0-255 based on rpm
where did i screwed up ?

int SpeedoPin = 10; //Speedo Pin
pinMode(SpeedoPin, OUTPUT);  // pin10 set as to speedo mosfet

SpeedoPin is a pin number which is connected to a timer pwm output. It is not an output value, and this next code will always print "10"

Serial.print(" SpeedoPin: ");
         Serial.println(SpeedoPin);

If you want pwm output on the SpeedoPin you need to change this

//digitalWrite(SpeedoPin,Speedo);
analogWrite(SpeedoPin, Speedo);

oh it was jsut that >_> lol

now new set of problem
1 as soon as i try to analogwrite the speedo to pin 10
the speedo value is inconsitent the rpm aslo sky rocket to double of what should be

and when i try to slow down the fan the speedo stay maxed at 255
only way to get it working is max the motor part to be maxed and then apply friction to the metered fan

at this point i think i have to use 2 arduino because something refuse to work when i try to merge them together

/* 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>
#define MainPeriod 1000


long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

//int Speedo;
//int RPMmulti;
            
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=7000; // 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
//int SpeedoPin = 10; //Speedo Pin

void setup()                  //setup loop                                           // Boucle d'initialisation.
{
    Serial.begin(9600);
      attachInterrupt(0, myinthandler, RISING);
      InitTimersSafe(); 
    pinMode(Motor, OUTPUT);  // pin5 set as THRout  (throttle out)      
//     pinMode(SpeedoPin, OUTPUT);  // pin10 set as to speedo mosfet      
}


void loop() {           // main loop  // Boucle principale

int MapTHRint = map(THRint, 110, 1200, -22, 340);
int insideTHR = constrain(MapTHRint,0,255);


  

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

        
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.print("Hz "); 
    int RPMmulti = Freq*30;
    Serial.print(" RPM: ");
    Serial.print(RPMmulti); 



int MapRPMmulti = map(RPMmulti, 0, 1800, 0, 255);
int Speedo = constrain(MapRPMmulti,0,255);




    Serial.print(" Speedo: ");
    Serial.println(Speedo);
    

//    analogWrite(10,Speedo);
 
}


}



void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

Edit1: it seem to be tied with the set frequency line
if i disable it // the rpm work properly
is that a internal timer conflict thing i heard a few time ?

Edit1.1:
if i make the speedo write as pwmWrite it work better than analogWrite since analogue dosent work at all
so since higher frequency made this way is impossible how to i make higher frequency pwm so i dont hear the noise none stop ?
i need to google more way todo higher pwm

Edit1: it seem to be tied with the set frequency line
if i disable it // the rom work properly
is that a internal timer conflict thing i heard a few time ?

Pin9 for the motor pwm and Pin10 for the speedometer pwm are both on Timer 1. I have not studied PWM.h in detail, so I'm not sure how the 32Khz value is set, and if both pins are available at that frequency. There may be a conflict.

You want to drive the motor on pin 9 with 32KHz pwm. You use the library command pwmWrite()

What frequency do you want to drive the SpeedoPin? Does it work properly at 32Khz? If so, pwmWrite(SpeedoPin, xxx) should work at 32Khz if both outputs are enabled by the library at that frequency.

Can the speedometer work at the standard unmodified pwm frequency of 490 Hz?

If so, I would try moving the SpeedoPin to a Timer 2 output (pin3 or pin11) and use analogWrite().

yeah it somewhat work better if i change the speedo to pin 3

but now the rpm (RPMmulti) sky rocket all over the place making the reading false

i have to run both in analog or pwmWrite without frequency set
if i set the pwm freq to motor the RPMmulti read false
if i set the speedo with a pwm the RPMmulti read false

the freq is set at Keyword Beta FREQ in the code for easier search (ctrl F)

physicaly the speedo work better with a highter freq pwm at low freq i hear some noise that i hate
i want to use this in my ebike so i need higter freq

Thanks for helping

Edit1: i have to use pwmWrite for the motor even without frequency set or the speed dosent change on potentiometer request

/* 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>
#define MainPeriod 100


long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;

            
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=7000; // 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; 
int32_t frequency2= 20000;
int Motor = 9;  //THRout is throttle to connect to transistor/driver/led/ebike controller
int SpeedoPin = 3; //Speedo Pin

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

     pinMode(SpeedoPin, OUTPUT);  // pin10 set as to speedo mosfet      
}


void loop() {           // main loop  // Boucle principale

int MapTHRint = map(THRint, 110, 1200, -22, 340);
int insideTHR = constrain(MapTHRint,0,255);


  

  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){ //checking for throttle increase                                        // 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.
  }

 //Beta FREQ 
//    SetPinFrequencySafe(Motor, frequency);   //set frequency and speed 
//   SetPinFrequencySafe(SpeedoPin, frequency2);   //set frequency and speed 
 

        
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= MainPeriod) 
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.print("Hz "); 
    int RPMmulti = Freq*30;   //converter from 1 magnet to 2 magnet  1 magnet is 60
    Serial.print(" RPM: ");
    Serial.print(RPMmulti); 



int MapRPMmulti = map(RPMmulti, 0, 2100, 0, 255);
int Speedo = constrain(MapRPMmulti,0,255);




    Serial.print(" Speedo: ");
    Serial.println(Speedo);
      //  analogWrite(10,Speedo);
  analogWrite(SpeedoPin,Speedo);
  pwmWrite(Motor, insideTHR); 
 
}


}



void myinthandler() // interrupt handler
{
  unsigned long currentMicros = micros();
  duration += currentMicros - previousMicros;
  previousMicros = currentMicros;
  pulsecount++;
}

but now the rpm (RPMmulti) sky rocket all over the place making the reading false

Changing the sample period from 1000 to 100 may be an issue.

You need to better protect the reading of the variables from the isr by making sure they can not be changing while being read.

if (currentMillis - previousMillis >= MainPeriod)
  {
    previousMillis = currentMillis;   
    // need to bufferize to avoid glitches

    noInterrupts();
    unsigned long _duration = duration;
    unsigned long _pulsecount = pulsecount;
    duration = 0; // clear counters
    pulsecount = 0;
    interrupts();

    float Freq = 1e6 / float(_duration);    //Duration is in uSecond so it is 1e6 / T

    Freq *= _pulsecount; // calculate F
    // output time and frequency data to RS232
    Serial.print(" Frequency: ");
    Serial.print(Freq);
    Serial.print("Hz ");
    int RPMmulti = Freq*30;   //converter from 1 magnet to 2 magnet  1 magnet is 60
    Serial.print(" RPM: ");
    Serial.print(RPMmulti);

You may also want to simplify the calculations by using the fixed sample time of MainPeriod to determine frequency instead of summing a duration from within the isr.

long previousMillis = 0; // will store last time of the cycle end

This may not be the cause of your current issue, but this needs to be unsigned long to keep from overflowing before millis().

i guess i will be using 2 arduino then since i cannot get higher frequency with 1 arduino

so just to make sure how do i make the second arduino read the pwm digitalWrite signal?
do i read it from an Analog pin ? digital to analog ?

i will figure out the rest after

Thanks for all the help