diff --git a/lambda-test/.cproject b/lambda-test/.cproject index 7e18fec..eb7663a 100644 --- a/lambda-test/.cproject +++ b/lambda-test/.cproject @@ -25,7 +25,6 @@ diff --git a/lambda/airgate.c b/lambda/airgate.c index c84b745..0b0c267 100644 --- a/lambda/airgate.c +++ b/lambda/airgate.c @@ -17,8 +17,6 @@ #include "interrupts.h" #include "pins.h" -static const uint16_t SPEED_PROD = (uint16_t)MIN_SPEED * MAX_SPEED; - /* Direction */ static volatile int8_t dir = 0; /* Current position */ @@ -30,10 +28,10 @@ /* Acceleration profile ramp */ static volatile uint16_t ramp = 0; /* Speed */ -static volatile uint8_t speed = MIN_SPEED; +static volatile uint16_t speed = MIN_SPEED; /** - * Sets increased current for higher torque,sets the direction and initial + * Sets increased current for higher torque, sets the direction and initial * speed and starts the motor by starting the timer. */ static void start(void) { @@ -79,7 +77,7 @@ speed--; } // linearize an unfavourably increasing acceleration curve - OCR2A = SPEED_PROD / speed; + OCR2A = MIN(UINT16_MAX, SPEED_PROD / speed); } } else { PORT &= ~(1 << PIN_STEP); diff --git a/lambda/airgate.h b/lambda/airgate.h index bc6693c..5067773 100644 --- a/lambda/airgate.h +++ b/lambda/airgate.h @@ -12,9 +12,11 @@ #define AIRGATE_H_ /** Min value 1 */ -#define MIN_SPEED 200 +#define MIN_SPEED 200U /** Max value 255 for 8 bit timer and 65535 for 16 bit timer */ -#define MAX_SPEED 250 +#define MAX_SPEED 250U +/** Used to linearize the acceleration curve */ +#define SPEED_PROD (MIN_SPEED * MAX_SPEED) #define AIRGATE_CLOSE 0 #define AIRGATE_25 15