Casainho, here is the description and the source code, I hope it is also useful for the main project
I hope that after the automatic translation it is still understandable.
The code to calculate and activate the PWM deceleration ramp is in the ebike_app.c file, this introduces a significant delay when you stop pedaling.
I added other code for this function in motor.c, (PWM frequency).
I tried to do it in a simple way by minimizing the lines of code.
The added code works in parallel with the existing one that has not been deleted.
added code:
variable declaration:
"ui8_cadence_sensor_stop_flag" state of the pedals stopped.
"ui16_cadence_sensor_ticks_stop" number of pulses of the tick counter beyond which the pedals are considered stationary.
Added direct activation of the PWM deceleration ramp with "ui8_cadence_sensor_stop_flag", previously activated in ebike_app.c due to the absence of assistance.
With the pedals stopped "ui8_cadence_sensor_stop_flag", direct assignment ui16_controller_duty_cycle_ramp_down_inverse_step = PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_MIN. Previously the value was calculated as a function of the speed in ebike.c.
The PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_MIN value was used by the brake sensors but always in ebike_app.c. For this I also added "OR ui8_brake_state".
The PWM_DUTY_CYCLE_RAMP_DOWN_INVERSE_STEP_MIN value in main.h has not changed.
Calculation of the value of "ui16_cadence_sensor_ticks_stop", in standard and advanced cadence sensor mode. They are different values.
The optimal values were obtained experimentally.
Increasing them increases the overrun time, decreasing them lacks assistance at the start.
Check the state of the pedals.
When "ui16_cadence_sensor_ticks" has a valid value and "ui16_cadence_sensor_ticks_counter" exceeds the value of "ui16_cadence_sensor_ticks_stop", the pedals are considered stationary.
View attachment motor.c
motor.c source code TSDZ2 20 beta 1 version only for LCD3, with overrun modification.