diff options
-rw-r--r-- | tube-rotator/stepper.c | 52 | ||||
-rw-r--r-- | tube-rotator/stepper.h | 32 | ||||
-rw-r--r-- | tube-rotator/tube-rotator.c | 28 |
3 files changed, 55 insertions, 57 deletions
diff --git a/tube-rotator/stepper.c b/tube-rotator/stepper.c index 43e194f..ee8518f 100644 --- a/tube-rotator/stepper.c +++ b/tube-rotator/stepper.c @@ -93,9 +93,9 @@ static inline void stepper_handle(void) if(step_idx != 0 && step_idx % 8) { if(current_speed > target_speed) - OCR1A = --current_speed; + OCR1A = (uint16_t)(STEPPER_SPEED_CONVERT_VALUE/(--current_speed)); else if(current_speed < target_speed) - OCR1A = ++current_speed; + OCR1A = (uint16_t)(STEPPER_SPEED_CONVERT_VALUE/(++current_speed)); } } @@ -120,7 +120,7 @@ const char* stepper_state_to_string(stepper_state_t state) void stepper_set_speed(uint16_t new_speed) { - if(new_speed <= STEPPER_SPEED_MIN && new_speed >= STEPPER_SPEED_MAX) { + if(new_speed >= STEPPER_SPEED_MIN && new_speed <= STEPPER_SPEED_MAX) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { target_speed = new_speed; } @@ -130,14 +130,14 @@ void stepper_set_speed(uint16_t new_speed) void stepper_inc_speed(void) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { - target_speed = (target_speed <= STEPPER_SPEED_MAX) ? STEPPER_SPEED_MAX : target_speed - 1; + target_speed = (target_speed >= STEPPER_SPEED_MAX) ? STEPPER_SPEED_MAX : target_speed + 1; } } void stepper_dec_speed(void) { ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { - target_speed = (target_speed >= STEPPER_SPEED_MIN) ? STEPPER_SPEED_MIN : target_speed + 1; + target_speed = (target_speed <= STEPPER_SPEED_MIN) ? STEPPER_SPEED_MIN : target_speed - 1; } } @@ -146,24 +146,24 @@ uint16_t stepper_get_speed(void) return target_speed; } -void stepper_set_speed_rpm(uint8_t new_rpm) -{ - stepper_set_speed(( (uint16_t)lround( (double)(60.0 * F_CPU) / (double)(64.0 * 800.0 * (double)new_rpm) ) ) - 1); -} - -uint8_t stepper_get_speed_rpm(void) -{ - return (uint8_t)lround( ( (double)F_CPU / (double)(64.0 * 800.0 * (double)(target_speed + 1) ) ) * 60.0 ); -} - -void stepper_inc_speed_rpm(void) -{ - uint8_t rpm = stepper_get_speed_rpm(); - stepper_set_speed_rpm((rpm >= 255) ? 255 : rpm+1); -} - -void stepper_dec_speed_rpm(void) -{ - uint8_t rpm = stepper_get_speed_rpm(); - stepper_set_speed_rpm((rpm <= 1) ? 1 : rpm-1); -} +/* void stepper_set_speed_rpm(uint8_t new_rpm) */ +/* { */ +/* stepper_set_speed(( (uint16_t)lround( (double)(60.0 * F_CPU) / (double)(64.0 * 800.0 * (double)new_rpm) ) ) - 1); */ +/* } */ + +/* uint8_t stepper_get_speed_rpm(void) */ +/* { */ +/* return (uint8_t)lround( ( (double)F_CPU / (double)(64.0 * 800.0 * (double)(target_speed + 1) ) ) * 60.0 ); */ +/* } */ + +/* void stepper_inc_speed_rpm(void) */ +/* { */ +/* uint8_t rpm = stepper_get_speed_rpm(); */ +/* stepper_set_speed_rpm((rpm >= 255) ? 255 : rpm+1); */ +/* } */ + +/* void stepper_dec_speed_rpm(void) */ +/* { */ +/* uint8_t rpm = stepper_get_speed_rpm(); */ +/* stepper_set_speed_rpm((rpm <= 1) ? 1 : rpm-1); */ +/* } */ diff --git a/tube-rotator/stepper.h b/tube-rotator/stepper.h index 10f4900..7c0eaa3 100644 --- a/tube-rotator/stepper.h +++ b/tube-rotator/stepper.h @@ -23,18 +23,18 @@ #ifndef R3TUBE_stepper_h_INCLUDED #define R3TUBE_stepper_h_INCLUDED -#define STEPPER_SPEED_MIN 699 -#define STEPPER_SPEED_MAX 149 -//#define STEPPER_SPEED_MAX 74 - -#define STEPPER_SPEED_30RPM 624 -#define STEPPER_SPEED_40RPM 468 -#define STEPPER_SPEED_50RPM 374 -#define STEPPER_SPEED_60RPM 312 -#define STEPPER_SPEED_70RPM 267 -#define STEPPER_SPEED_80RPM 233 -#define STEPPER_SPEED_90RPM 207 -#define STEPPER_SPEED_100RPM 187 +#define STEPPER_SPEED_MIN 150 +#define STEPPER_SPEED_MAX 700 +#define STEPPER_SPEED_CONVERT_VALUE (uint32_t)(105000) + +#define STEPPER_SPEED_30RPM 168 +#define STEPPER_SPEED_40RPM 224 +#define STEPPER_SPEED_50RPM 281 +#define STEPPER_SPEED_60RPM 336 +#define STEPPER_SPEED_70RPM 393 +#define STEPPER_SPEED_80RPM 451 +#define STEPPER_SPEED_90RPM 507 +#define STEPPER_SPEED_100RPM 561 #define STEPPER_SPEED_DEFAULT STEPPER_SPEED_60RPM @@ -51,9 +51,9 @@ void stepper_inc_speed(void); void stepper_dec_speed(void); uint16_t stepper_get_speed(void); -void stepper_set_speed_rpm(uint8_t new_rpm); -uint8_t stepper_get_speed_rpm(void); -void stepper_inc_speed_rpm(void); -void stepper_dec_speed_rpm(void); +//void stepper_set_speed_rpm(uint8_t new_rpm); +//uint8_t stepper_get_speed_rpm(void); +//void stepper_inc_speed_rpm(void); +//void stepper_dec_speed_rpm(void); #endif diff --git a/tube-rotator/tube-rotator.c b/tube-rotator/tube-rotator.c index 065dd2f..416e077 100644 --- a/tube-rotator/tube-rotator.c +++ b/tube-rotator/tube-rotator.c @@ -40,22 +40,20 @@ void handle_cmd(uint8_t cmd) case '!': reset2bootloader(); break; case 'r': led_on(); stepper_start(); break; case 's': stepper_stop(); led_off(); break; - case '*': stepper_inc_speed(); break; - case '+': stepper_inc_speed_rpm(); break; - case '-': stepper_dec_speed_rpm(); break; - case '_': stepper_dec_speed(); break; - case '3': stepper_set_speed_rpm(30); break; - case '4': stepper_set_speed_rpm(40); break; - case '5': stepper_set_speed_rpm(50); break; - case '6': stepper_set_speed_rpm(60); break; - case '7': stepper_set_speed_rpm(70); break; - case '8': stepper_set_speed_rpm(80); break; - case '9': stepper_set_speed_rpm(90); break; - case '0': stepper_set_speed_rpm(100); break; - case '1': stepper_set_speed_rpm(110); break; - case '2': stepper_set_speed_rpm(120); break; + case '+': stepper_inc_speed(); break; +// case '+': stepper_inc_speed_rpm(); break; +// case '-': stepper_dec_speed_rpm(); break; + case '-': stepper_dec_speed(); break; + case '3': stepper_set_speed(STEPPER_SPEED_30RPM); break; + case '4': stepper_set_speed(STEPPER_SPEED_40RPM); break; + case '5': stepper_set_speed(STEPPER_SPEED_50RPM); break; + case '6': stepper_set_speed(STEPPER_SPEED_60RPM); break; + case '7': stepper_set_speed(STEPPER_SPEED_70RPM); break; + case '8': stepper_set_speed(STEPPER_SPEED_80RPM); break; + case '9': stepper_set_speed(STEPPER_SPEED_90RPM); break; + case '0': stepper_set_speed(STEPPER_SPEED_100RPM); break; } - printf("state: %s, %3d rpm\r", stepper_state_to_string(stepper_get_state()), stepper_get_speed_rpm()); + printf("state: %s, %3d rpm\r", stepper_state_to_string(stepper_get_state()), stepper_get_speed()); } int main(void) |