diff --git a/software/firmware_module/module_rev0/src/main.c b/software/firmware_module/module_rev0/src/main.c index 7ebf512..3c0aa8d 100644 --- a/software/firmware_module/module_rev0/src/main.c +++ b/software/firmware_module/module_rev0/src/main.c @@ -173,7 +173,7 @@ int main() { initialSetup(); rs485_init(); - mctrl_init(); + mctrl_init(calib_offset); while (1 == 1) { diff --git a/software/firmware_module/module_rev0/src/mctrl.c b/software/firmware_module/module_rev0/src/mctrl.c index e4749c3..972ccd9 100644 --- a/software/firmware_module/module_rev0/src/mctrl.c +++ b/software/firmware_module/module_rev0/src/mctrl.c @@ -46,9 +46,15 @@ uint16_t currentVoltage = 0; // current ADC reading uint8_t currentFaultReadings = 0; // ticks with faulty readings (too many will // trip pwrdwn and sts_flag_fuse) +int STEPS_OFFSET = 0; // initialize motor controller -void mctrl_init() +void mctrl_init(int cal_offset) { + if (cal_offset < 800){ + STEPS_OFFSET = STEPS_OFFSET_DEF; + }else{ + STEPS_OFFSET = cal_offset; + } DDRC = 0x0F; // set all pins as outputs PORTC = 0x00; // set all to LOW diff --git a/software/firmware_module/module_rev0/src/mctrl.h b/software/firmware_module/module_rev0/src/mctrl.h index 03fc63d..07124d8 100644 --- a/software/firmware_module/module_rev0/src/mctrl.h +++ b/software/firmware_module/module_rev0/src/mctrl.h @@ -15,7 +15,7 @@ #define STEPS_PER_REV 2025 // steps per revolution #define STEPS_PER_FLAP 45 // steps per flap #define STEPS_ADJ 0 // added per flap to compensate for motor power down -#define STEPS_OFFSET 1400 // ansolute offset between home and first flap +#define STEPS_OFFSET_DEF 1400 // ansolute offset between home and first flap #define AMOUNTFLAPS 45 // amount of flaps installed in system #define STEPS_AFTERROT 255 // value to goto after current target flap is reached #define ERROR_DATASETS 8 // length of error array @@ -33,7 +33,7 @@ #ifdef __cplusplus extern "C" { #endif // __cplusplus -void mctrl_init(); +void mctrl_init(int cal_offset); void mctrl_step(); void mctrl_set(uint8_t flap, uint8_t fullRotation);