stancecoke said:
I had a closer look to you code now. As far as I understand, you are averaging the torque-signal over four AD-conversions, in the fixed frequency of the slow loop. So you have no reference to the pedal position.
Seems you missed my new code -- you can see on the commits diffs:
- https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/commit/3d6a958e917db19eb90e1dc56382ab90a6b4db90
- https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/commit/aa5989ea3015eeef40ca5013536c3e42905c8609
The new code I added to PAS code, at every signal change:
Code:
if (ui8_pas_state != ui8_pas_state_old) // PAS signal did change
{
ui8_pas_state_old = ui8_pas_state;
(...)
ui8_torque_sensor_throttle_value = UI8_ADC_THROTTLE;
ui8_torque_sensor_pas_signal_change_counter++;
if (ui8_torque_sensor_pas_signal_change_counter > (PAS_NUMBER_MAGNETS << 1)) // ui8_pas_signal_change_counter = (PAS_NUMBER_MAGNETS*2) means 1 pedal rotation
{
ui8_torque_sensor_pas_signal_change_counter = 1; // this is the first cycle
ui8_torque_sensor_throttle_processed_value = ui8_torque_sensor_throttle_max_value; // store the max value on the output variable of this algorithm
ui8_torque_sensor_throttle_max_value = 0; // reset the max value
}
else
{
// store the max value
if (ui8_torque_sensor_throttle_value > ui8_torque_sensor_throttle_max_value)
{
ui8_torque_sensor_throttle_max_value = ui8_torque_sensor_throttle_value;
}
}
}
As you can see, it reads the max value of the signal every 1 pedal rotation and outputs that value to the global variable
ui8_torque_sensor_throttle_processed_value.
Then on ebike_app.c, running at 10Hz:
Code:
void read_torque_sensor_throttle (void)
{
read_throttle (); // so we get regular processing of throttle signal
// if cadence is over 15 RPM, use the processed torque sensor value, otherwise, use ui8_throttle_value_filtered
if (ui8_pas_cadence_rpm <= 15)
{
ui8_throttle_value_filtered = ui8_throttle_value;
}
else
{
ui8_throttle_value_filtered = (uint8_t) (map (
ui8_torque_sensor_throttle_processed_value,
(uint8_t) ADC_THROTTLE_MIN_VALUE,
(uint8_t) ADC_THROTTLE_MAX_VALUE,
(uint8_t) THROTTLE_MIN_VALUE,
(uint8_t) THROTTLE_MAX_VALUE));
}
}
ui8_throttle_value (unfiltered value!!) is used when cadence <= 15 and when over, ui8_torque_sensor_throttle_processed_value is used instead, as I did show before with real values on the graph.
Note that
Code:
ui8_throttle_value_filtered
is the same variable with output value from either:
- read_throttle (); (used for thumb throttle and PAS)
- read_torque_sensor_throttle (); (used for torque sensor)
I am using the S06S Bluetooth version and I think I will stick with that version, for later use with our mobile app. This means I connected the torque sensor signals to the thumb throttle connector and PAS and so I can't use in parallel a thumb throttle with this controller.