diff options
author | Keith Packard <keithp@keithp.com> | 2014-05-09 00:05:39 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2014-05-09 00:05:39 -0700 |
commit | 8d9c79f5c162e07d57d42c6ba5825a3327a911d5 (patch) | |
tree | 3e97ed6affaa5f864522c4d73a80842f90a9599c /src/stm/ao_fast_timer.c | |
parent | ef48e1bb73c791d731b0d2c0e5beef1539103049 (diff) |
altos: Simplify quadrature tracking
Set the timer to 200Hz for a 5ms debounce interval. Then, simply look
for transitions ending in both bits in the encoder being off, which
indicates the the encoder is resting in a detent. If bit '2' is
turning off, the encoder was rotated clockwise, otherwise the encoder
was rotated counter clockwise.
This is a lot more reliable, although still not perfect.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/stm/ao_fast_timer.c')
-rw-r--r-- | src/stm/ao_fast_timer.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/stm/ao_fast_timer.c b/src/stm/ao_fast_timer.c index d61b40c9..9a73eb51 100644 --- a/src/stm/ao_fast_timer.c +++ b/src/stm/ao_fast_timer.c @@ -88,7 +88,11 @@ void stm_tim6_isr(void) #define TIMER_23467_SCALER 1 #endif -#define TIMER_10kHz ((AO_PCLK1 * TIMER_23467_SCALER) / 10000) +#ifndef FAST_TIMER_FREQ +#define FAST_TIMER_FREQ 10000 +#endif + +#define TIMER_FAST ((AO_PCLK1 * TIMER_23467_SCALER) / FAST_TIMER_FREQ) void ao_fast_timer_init(void) @@ -100,7 +104,7 @@ ao_fast_timer_init(void) /* Turn on timer 6 */ stm_rcc.apb1enr |= (1 << STM_RCC_APB1ENR_TIM6EN); - stm_tim6.psc = TIMER_10kHz; + stm_tim6.psc = TIMER_FAST; stm_tim6.arr = 9; stm_tim6.cnt = 0; |