diff --git a/Inc/stepper.h b/Inc/stepper.h index 73cfb16..c65683b 100644 --- a/Inc/stepper.h +++ b/Inc/stepper.h @@ -11,12 +11,14 @@ typedef struct { uint8_t home_pin; uint8_t homed:1; uint8_t trigger_step:1; - int16_t pos; - int16_t speed; - int16_t ramp_to_speed; + int32_t pos; + int32_t speed; + int32_t ramp_to_speed; uint32_t next_step; } stepper_T; +#define STEPPERS_MAX_SPEED 300 + void Timer1_Init(void); void stepper_gpio_init(); void do_steps(); diff --git a/Makefile b/Makefile index 4270395..a487317 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ TARGET = Parafraktor # debug build? DEBUG = 1 # optimization -OPT = -Og +OPT = -O0 ####################################### diff --git a/Src/stepper.c b/Src/stepper.c index 1198469..637dd4d 100644 --- a/Src/stepper.c +++ b/Src/stepper.c @@ -89,10 +89,10 @@ void do_steps(){ steppers[i].speed--; /* limit max speed */ - if(steppers[i].speed >= 100) - steppers[i].speed=100; - if(steppers[i].speed <= -100) - steppers[i].speed=-100; + if(steppers[i].speed >= STEPPERS_MAX_SPEED) + steppers[i].speed=STEPPERS_MAX_SPEED; + if(steppers[i].speed <= -STEPPERS_MAX_SPEED) + steppers[i].speed=-STEPPERS_MAX_SPEED; /* get direction from sign */ if(steppers[i].speed>0) @@ -122,16 +122,15 @@ void do_steps(){ steppers[i].next_step = timer + 1; } - printf("pos %d\tspeed %d\n", steppers[i].pos, steppers[i].speed); + printf("motor[%d]: pos %ld\tspeed %d\n", i, steppers[i].pos, steppers[i].speed); } if(steppers[i].homed){ static uint16_t old_ramp_to_speed; old_ramp_to_speed = steppers[i].ramp_to_speed; - uint16_t *p = (uint16_t*)&rxBuffer[1]; - - steppers[i].ramp_to_speed = __builtin_bswap16(*p) - steppers[i].pos; + int32_t swapped_val = rxBuffer[2*i+1]<<8 | (rxBuffer[2*i+2]&0xFF); + steppers[i].ramp_to_speed = swapped_val - steppers[i].pos; if(old_ramp_to_speed == 0 && steppers[i].ramp_to_speed != 0) steppers[i].trigger_step = 1; diff --git a/compile_flags.txt b/compile_flags.txt index 92d6f97..9edb108 100644 --- a/compile_flags.txt +++ b/compile_flags.txt @@ -12,7 +12,7 @@ -IDrivers/SystemView/Config -IDrivers/SystemView/SEGGER -IDrivers/SystemView/SYSVIEW --Og +-O0 -Wall -fdata-sections -ffunction-sections