From 05923d2e343371075607f0240e7db2c04f5080c9 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 19 Mar 2011 18:16:06 +0100 Subject: digital/{asserv,mimot}: fix counter shift The shift should be done on a signed value or else there is a problem on overflow. --- digital/mimot/src/dirty/counter_ext.avr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'digital/mimot') diff --git a/digital/mimot/src/dirty/counter_ext.avr.c b/digital/mimot/src/dirty/counter_ext.avr.c index a3ddb003..e99d9dc0 100644 --- a/digital/mimot/src/dirty/counter_ext.avr.c +++ b/digital/mimot/src/dirty/counter_ext.avr.c @@ -149,21 +149,23 @@ counter_update (void) /* Wants fresh data. */ counter_update_step (); /* First auxiliary counter. */ - uint16_t aux0 = counter_aux_new_step[0] >> COUNTER_AUX0_SHIFT; + uint16_t aux0 = counter_aux_new_step[0]; #if !COUNTER_AUX0_REVERSE counter_aux_diff[0] = (int16_t) (aux0 - counter_aux_old[0]); #else counter_aux_diff[0] = (int16_t) (counter_aux_old[0] - aux0); #endif + counter_aux_diff[0] >>= COUNTER_AUX0_SHIFT; counter_aux_old[0] = aux0; counter_aux[0] += counter_aux_diff[0]; /* Second auxiliary counter. */ - uint16_t aux1 = counter_aux_new_step[1] >> COUNTER_AUX1_SHIFT; + uint16_t aux1 = counter_aux_new_step[1]; #if !COUNTER_AUX1_REVERSE counter_aux_diff[1] = (int16_t) (aux1 - counter_aux_old[1]); #else counter_aux_diff[1] = (int16_t) (counter_aux_old[1] - aux1); #endif + counter_aux_diff[1] >>= COUNTER_AUX1_SHIFT; counter_aux_old[1] = aux1; counter_aux[1] += counter_aux_diff[1]; } -- cgit v1.2.3