From cf20e213f39fb24f15e0ac94307c2d138fcadecb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 24 Aug 2017 16:45:54 -0700 Subject: altos: Perform time comparisons using 16-bit arithmetic to handle wrap Subtracting two 16-bit unsigned values to perform time comparisons yields mystic results unless we carefully cast that to int16_t. Signed-off-by: Keith Packard --- src/kernel/ao_sample.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/kernel/ao_sample.c') diff --git a/src/kernel/ao_sample.c b/src/kernel/ao_sample.c index 90ea07ad..f0ab0169 100644 --- a/src/kernel/ao_sample.c +++ b/src/kernel/ao_sample.c @@ -180,7 +180,7 @@ static void ao_sample_rotate(void) { #ifdef AO_FLIGHT_TEST - float dt = (ao_sample_tick - ao_sample_prev_tick) / TIME_DIV; + float dt = (int16_t) (ao_sample_tick - ao_sample_prev_tick) / TIME_DIV; #else static const float dt = 1/TIME_DIV; #endif -- cgit v1.2.3