One step forward 2 steps back.
The magnet and hallsensor are working like a charm now.
Stuck in the lookuptable again.
I cant figure out why.
Nothing in this part of the code has changed (as far as I can see).
**SpeedfinalValue never passes the switchpointYValue.**With endcurvepower set to 1.0 the speedfinale value should follow sensormapped value as in previous codes.
As usual it must be so simple I over look it.
// +++++++++++++++ regular speed - brake mode +++++++++++++++
// in regular mode control the outputs with output cross block function to prevent speed and brake to be ON together
sensorRawValue = analogRead(sensorspeedPin); // read the raw value from the linear hall sensor / potentiometer
sensorRawValue = constrain(sensorRawValue, sensorMin, sensorMax);
sensorValue = map(sensorRawValue, sensorMin, sensorMax, 0, 255);// map the calibration to the sensor reading from the hall sensor / potentiometer
sensormappedValue = map(sensorValue, 0, 255, speedstartValue, 255); // full linear control mapped with startspeed
// ++++ curve section +++++++
speedfinalValue = lookupTable[sensormappedValue];
// ++++ curve section +++++++
if (sensorValue > deadbandXvalue)
{
analogWrite(pwmoutspeedPin, speedfinalValue);
analogWrite(pwmoutbrakePin, 0);
digitalWrite(led8Pin, LOW);
digitalWrite(led7Pin, HIGH);
}
else
{
//speedValue = 0;
analogWrite(pwmoutspeedPin, 0);
analogWrite(pwmoutbrakePin, brakeNValue);
digitalWrite(led8Pin,HIGH);
digitalWrite(led7Pin, LOW);
}
endcurvepower is currently set to 10 so diveded by 10 will give 1 and so a linear powerline.
void fillLookupTable()
{
speedstartValueold = speedstartValue;
switchpointXValueold = switchpointXValue;
switchpointYValueold = switchpointYValue;
Serial.print("B,");
Serial.println(speedstartValue);
Serial.print("C,");
Serial.println(switchpointXValue);
Serial.print("D,");
Serial.println(switchpointYValue);
switchpointXValue = constrain (switchpointXValue,deadbandXvalue, 255);
switchpointYValue = constrain(switchpointYValue,speedstartValue, 255);
for (int i=0; i<256; i++)
if (i < deadbandXvalue)
{
lookupTable[i] = 0;
}
else
if (i < switchpointXValue)
{
lookupTable[i] = map(i, deadbandXvalue, switchpointXValue, speedstartValue, switchpointYValue);
}
else
{
lookupTable[i] = (int)(0.5 + switchpointYValue + (255-switchpointYValue) * ( 1.0 - pow( (255-x)/(255-switchpointXValue), endCurvePower/10) ));
}
for (int i=0; i<256; i++)
{
Serial.print(lookupTable[i]);
if (i<255)
{
Serial.print("|");
}
}
Serial.println();
Paco