|
|
|
|
@@ -76,6 +76,10 @@ void by_stepper_set_position_millimeter(float distance)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (distance > 170) {
|
|
|
|
|
distance = 170;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
|
|
|
|
position_aim = (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
|
|
|
|
position_offset = position_aim - position;
|
|
|
|
|
@@ -87,7 +91,10 @@ void by_stepper_add_position_millimeter(float distance)
|
|
|
|
|
{
|
|
|
|
|
if (!running_flag) {
|
|
|
|
|
gpio_bits_write(GPIOA, GPIO_PINS_9, FALSE); // EN
|
|
|
|
|
position_aim = position + (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
|
|
|
|
position_aim = position + (int64_t)(distance * ENCODER_PULSE_PER_MILLIMETER);
|
|
|
|
|
if (position_aim > 170 * ENCODER_PULSE_PER_MILLIMETER) {
|
|
|
|
|
position_aim = 170 * ENCODER_PULSE_PER_MILLIMETER;
|
|
|
|
|
}
|
|
|
|
|
position_offset = position_aim - position;
|
|
|
|
|
running_flag = 1;
|
|
|
|
|
}
|
|
|
|
|
@@ -108,20 +115,20 @@ void by_stepper_init(void)
|
|
|
|
|
gpio_bits_write(GPIOB, GPIO_PINS_15, FALSE); // CLK
|
|
|
|
|
|
|
|
|
|
by_stepper_set_dir(0);
|
|
|
|
|
by_stepper_set_speed(STEPPER_SPEED_DIV2);
|
|
|
|
|
// by_stepper_set_speed(STEPPER_SPEED_DIV2);
|
|
|
|
|
|
|
|
|
|
while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET && slow_start_cnt--) {
|
|
|
|
|
gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
|
|
|
|
gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
|
|
|
|
DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
|
|
|
|
}
|
|
|
|
|
// while (gpio_input_data_bit_read(GPIOB, GPIO_PINS_10) == SET && slow_start_cnt--) {
|
|
|
|
|
// gpio_bits_write(GPIOA, GPIO_PINS_8, by_stepper.dir ? TRUE : FALSE); // DIR
|
|
|
|
|
// gpio_bits_write(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
|
|
|
|
// DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
by_stepper_set_speed(STEPPER_SPEED_DIV4);
|
|
|
|
|
by_stepper_set_speed(STEPPER_SPEED_DIV1);
|
|
|
|
|
|
|
|
|
|
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(GPIOB, GPIO_PINS_15, !gpio_output_data_bit_read(GPIOB, GPIO_PINS_15)); // CLK
|
|
|
|
|
DWT_Delay(40U * (uint16_t)by_stepper.speed);
|
|
|
|
|
DWT_Delay(30U * (uint16_t)by_stepper.speed);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
position = 0; // 位置归零
|
|
|
|
|
@@ -130,6 +137,8 @@ void by_stepper_init(void)
|
|
|
|
|
tmr_counter_value_set(TMR3, 0);
|
|
|
|
|
|
|
|
|
|
LOGD("by_stepper init ok");
|
|
|
|
|
|
|
|
|
|
by_stepper_set_position_millimeter(160.0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void by_stepper_loop(void)
|
|
|
|
|
|