Hello!
I'm making an electric go-cart with a friend using an Arduino nano to control a MOSFET as the speed control.
The issue we're having is that the hall-effect throttle we're using has an offset depending on the amount of power going through it.
Currently, we have a sequence that calibrates by getting the lowest value for the throttle, then the highest value, but we really don't have any idea on how to actually use this.
My current idea is to use OCR2A as a way to set a custom low point and high point for the PWM, but I really don't understand the stuff i've read about it.
If anyone could give me some idea for the right direction that would be great ![]()
The current code is this (calibration gets called in setup) :
#define Throttle_IN A7
#define Brake_ON 12
void calibration()
{
Serial.print("Entering Calibration");
Serial.print("\n * Brake_ON is:");
Serial.print(digitalRead(Brake_ON));
Serial.println("\n\n Set throttle to LOW point then press and hold brake");
while(digitalRead(Brake_ON) == false) {} // Do nothing while brake remains high (brake off)
// First brake press. To get to this point, brake must have been pressed.
throttleLow = analogRead(Throttle_IN); // Read the throttle low point and save it in 'throttleLow'
Serial.print("\nThrottle Low = ");
Serial.print(analogRead(Throttle_IN));
// First brake release
Serial.print("\n\n Release the brake!");
while(digitalRead(Brake_ON) == true){}//while brake is on, do nothing
Serial.print("\n\n Brake release detected.");
Serial.println("\n\n Set throttle to HIGH point then press and hold brake");
while(digitalRead(Brake_ON) == false) {} // Do nothing while brake remains high (brake off)
// Second brake press. To get to this point, brake must have been pressed.
Serial.print("\n * Second brake press detected");
throttleHigh = analogRead(Throttle_IN);
Serial.print("\nThrottle High = ");
Serial.print(analogRead(Throttle_IN));
Serial.print("\n *** Calibration complete! ***");
Serial.print("\n Throttle Low offset = ");
Serial.print(throttleLow);
Serial.print("\n Throttle High offset = ");
Serial.println(throttleHigh);
}