File tree Expand file tree Collapse file tree 1 file changed +2
-1
lines changed
src/encoders/stm32hwencoder Expand file tree Collapse file tree 1 file changed +2
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ void STM32HWEncoder::update() {
3636 count = encoder_handle.Instance ->CNT ;
3737
3838 prev_timestamp = pulse_timestamp;
39- pulse_timestamp = getCurrentMicros ();
39+ pulse_timestamp = _micros (); // micros() rollover is handled in velocity calculation
4040
4141 prev_overflow_count = overflow_count;
4242 if (prev_count > (ticks_per_overflow - overflow_margin) &&
@@ -76,6 +76,7 @@ int32_t STM32HWEncoder::getFullRotations() {
7676float STM32HWEncoder::getVelocity () {
7777 // sampling time calculation
7878 float dt = (pulse_timestamp - prev_timestamp) * 1e-6f ;
79+ // this also handles the moment when micros() rolls over
7980 if (dt < min_elapsed_time) return velocity; // don't update velocity if deltaT is too small
8081
8182 // time from last impulse
You can’t perform that action at this time.
0 commit comments