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() {
36
36
count = encoder_handle.Instance ->CNT ;
37
37
38
38
prev_timestamp = pulse_timestamp;
39
- pulse_timestamp = getCurrentMicros ();
39
+ pulse_timestamp = _micros (); // micros() rollover is handled in velocity calculation
40
40
41
41
prev_overflow_count = overflow_count;
42
42
if (prev_count > (ticks_per_overflow - overflow_margin) &&
@@ -76,6 +76,7 @@ int32_t STM32HWEncoder::getFullRotations() {
76
76
float STM32HWEncoder::getVelocity () {
77
77
// sampling time calculation
78
78
float dt = (pulse_timestamp - prev_timestamp) * 1e-6f ;
79
+ // this also handles the moment when micros() rolls over
79
80
if (dt < min_elapsed_time) return velocity; // don't update velocity if deltaT is too small
80
81
81
82
// time from last impulse
You can’t perform that action at this time.
0 commit comments