From 60d62d42dc3bd3e1b9344ab76ed0930afcf88f9b Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Mon, 28 May 2012 10:18:20 +0100 Subject: [PATCH] reprap: Steppers use proper logic For underflow detection, instead of using a signed value Signed-off-by: Michel Pollet --- examples/board_reprap/src/stepper.c | 4 +--- examples/board_reprap/src/stepper.h | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/board_reprap/src/stepper.c b/examples/board_reprap/src/stepper.c index 23f6e7d..81acda6 100644 --- a/examples/board_reprap/src/stepper.c +++ b/examples/board_reprap/src/stepper.c @@ -79,9 +79,7 @@ stepper_step_hook( return; if (value) return; - p->position += p->dir ? 1 : -1; - if (p->position < 0) - p->position = 0; + p->position += !p->dir && p->position == 0 ? 0 : p->dir ? 1 : -1; if (p->endstop && p->position < p->endstop) p->position = p->endstop; if (p->max_position > 0 && p->position > p->max_position) diff --git a/examples/board_reprap/src/stepper.h b/examples/board_reprap/src/stepper.h index 14b0df1..9f450ac 100644 --- a/examples/board_reprap/src/stepper.h +++ b/examples/board_reprap/src/stepper.h @@ -40,7 +40,7 @@ typedef struct stepper_t { char name[32]; int enable : 1, dir : 1, trace : 1; double steps_per_mm; - int64_t position; // in steps + uint64_t position; // in steps uint64_t max_position; uint64_t endstop; avr_cycle_count_t timer_period; -- 2.39.5