Setting custom PWM Low-High points?

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 :slight_smile:

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

}

I would recommend the following links first off then you at least know how this forum works.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.

pwm = constrain(pwm, throttleLow, throttleHigh);

No timer fiddling needed.

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.

A sensor shouldn't have "power going through it" - it will require a constant supply voltage though - are
you saying the supply voltage isn't constant?