Skip to content

Commit 51e5254

Browse files
author
Richard Unger
committed
use _micros()
1 parent 03391c2 commit 51e5254

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/encoders/stm32hwencoder/STM32HWEncoder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff 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() {
7676
float 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

0 commit comments

Comments
 (0)