From linear to exponential PWM output

Techylah,

Appreciate your guidance effort highly.

If you see what they try to achieve at JayGee they exchange probably eeproms with software curves.
Why would you do that if you just can do it by software and the arduino. :slight_smile:
This way you can make ONE universal controller. 24 bands/steps for the jayGee or 255 steps for our version :cold_sweat:.
And later no contact vurnable sensors to be used.

Some more explanation.
The trigger I use is currently coupled to a potentiometer which has some play around the zero point.
The whole trigger movement is around 45 degrees from 0 to full.
The raw value of the sensor is mapped from 0 to 255.
With this base value we go further and control deathband and speed.

If the trigger is at the mechanical 0 position due to the play the sensor value can be higher as 0.
In real world the sensor value can vary around the zero point upto 5.
So what I have done is create a deathband which is user adjustable from 0 to 15.
So if the trigger is in zero/deathband position there is no activity possible at the speed output.
In this zero/deathband zone the brakes are always activated and the PWM break output is adjustable from 0 to 255 (0 to 100%).

As soon as the trigger leaves the zero/deathband zone the PWM speed output is activated and the brakes switched OFF.
From this point on the value is mapped from 0 to 255 and linear.
If we add speedstart then the pwm starts at a higher point and not at 0.
So if speedstart is set at 45 then the trigger regulates the output from 45 to 255 in linear fashion.

If the speedstart is set to 0 and we like to curve the linear line we call this speedcurve and this is the exponential curve we like to create.
This will run then from 0 to 255.
The speedcurve should be able to be adjusted upper or lower then the linear line.
If we add speedstart and speedcurve then from 45 to 255 the curve should be exponential.
See the previous graphs I added to the responses.

I assume your parameter 1 Bias is what I call startspeed(speedstart) and parameter 2 Curvature the speedcurve.
The softtouch of the JayGee controller is a curve with startspeed intergrated.
I like to see them both as seperate adjustable parameters.

Do not fully understand the purpose of the look up table and the benefit of it.
I know that is my problem due to the lack of knowledge.
Does my code do the same or is the look up table an easier way to achieve the same?
Is not using a look up table slowing down the controller reaction.
Do I see it wrong but 16 Mhz should be enough with the code I have or is calculating slowing down the reaction of the trigger compared to the speed dramaticly. Are we talking about micro seconds or milliseconds delays?

Please let me know your valuable opinion.

Current code... for the speed brake section.
Not optimized just for the knowledge I have gained sofar.

//     +++++++++++++++ regular speed - brake mode +++++++++++++++
      speedstartValue= constrain (speedstartValue,0,255);
      speedcurveValue= constrain (speedcurveValue,0,255);
      brakeValue= constrain (brakeValue,0,255);
      modelNumber= constrain (modelNumber,1,10);
      
      // control the outputs with output cross block function to prevent speed and brake to be ON together 
      sensorValue = analogRead(sensorspeedPin); // read the raw value from the linear hall sensor/potentiometer:
      sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);// apply the calibration to the sensor reading from the hall sensor/potentiometer
      // sensorMin and sensorMax are stored in the EEPROM during calibration.
      sensormappedValue = constrain (sensorValue,0,255); // keep value in range
      speedValue = map(sensormappedValue, 0, 255, speedstartValue, 255); //speedstart added to the speed
      //speedcurveValue = speedvalue with the quotation to calculate the exponential power curve // added speedcurve value
      //speedfinalValue = speedcurveValue
      if (speedfinalValue > 250) {speedfinalValue= 255;} //make sure we reache full speed due to play.
      speedfinalValue = speedValue;
      
      if (sensormappedValue > deathbandValue){analogWrite(pwmoutspeedPin, speedfinalValue); analogWrite(pwmoutbrakePin, 0); digitalWrite(led13Pin, LOW);} 
       else  
      {analogWrite(pwmoutspeedPin, 0); (speedfinalValue, 0);analogWrite(pwmoutbrakePin, brakeValue);digitalWrite (led13Pin,HIGH);} // startspeed and curve included
      
      if (speedfinalValue < speedfinalValueold){analogWrite(pwmoutspeedPin, 0); (speedfinalValue, 0);analogWrite(pwmoutbrakePin, brakeValue);digitalWrite (led30Pin,HIGH);} // regenerative breaking
       else
      {digitalWrite(led30Pin, LOW);}