reprap: Steppers use proper logic
authorMichel Pollet <buserror@gmail.com>
Mon, 28 May 2012 09:18:20 +0000 (10:18 +0100)
committerMichel Pollet <buserror@gmail.com>
Mon, 28 May 2012 09:18:20 +0000 (10:18 +0100)
For underflow detection, instead of using a signed value

Signed-off-by: Michel Pollet <buserror@gmail.com>
examples/board_reprap/src/stepper.c
examples/board_reprap/src/stepper.h

index 23f6e7d..81acda6 100644 (file)
@@ -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)
index 14b0df1..9f450ac 100644 (file)
@@ -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;