This commit is contained in:
bmy
2024-06-10 17:43:28 +08:00

View File

@@ -116,7 +116,7 @@ void by_stepper_init(void)
// DWT_Delay(40U * (uint16_t)by_stepper.speed); // DWT_Delay(40U * (uint16_t)by_stepper.speed);
// } // }
by_stepper_set_speed(STEPPER_SPEED_DIV1); by_stepper_set_speed(STEPPER_SPEED_DIV4);
while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET) { while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET) {
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
@@ -138,7 +138,7 @@ void by_stepper_init(void)
void by_stepper_loop(void) void by_stepper_loop(void)
{ {
int16_t temp = (int16_t)tmr_counter_value_get(TMR3); int16_t temp = (int16_t)tmr_counter_value_get(TMR3);
position += (int64_t)temp; position -= (int64_t)temp;
tmr_counter_value_set(TMR3, 0); tmr_counter_value_set(TMR3, 0);
if (running_flag) { if (running_flag) {
@@ -151,10 +151,10 @@ void by_stepper_loop(void)
} else // 正常模式 } else // 正常模式
{ {
if (position_offset > 0) { if (position_offset > 0) {
by_stepper_set_dir(0); by_stepper_set_dir(1);
by_stepper_run(); by_stepper_run();
} else if (position_offset < 0) { } else if (position_offset < 0) {
by_stepper_set_dir(1); by_stepper_set_dir(0);
by_stepper_run(); by_stepper_run();
} }