1
Dependencies: X-NUCLEO-IHM05A1
Example code to use L6208 stepper motor driver with nucleo evaluation shield
Explanation: Run a test to determine the maximum speed of the motor at given current and acceleration Run the motor in position mode with microstepping and slow decay
Revision 16:1dc772fba09f, committed 2018-12-07
- Comitter:
- gidiana
- Date:
- Fri Dec 07 17:40:15 2018 +0000
- Parent:
- 15:c781dda7e44c
- Child:
- 17:33c94534a440
- Commit message:
- end stop
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Dec 07 11:21:04 2018 +0000 +++ b/main.cpp Fri Dec 07 17:40:15 2018 +0000 @@ -28,6 +28,8 @@ /* Motor Control Component. */ L6208 *motor; DigitalIn button (USER_BUTTON); +DigitalIn end(PC_10); +DigitalOut led(LED1); /* Functions -----------------------------------------------------------------*/ /** @@ -84,7 +86,7 @@ /* Attaching an error handler */ motor->attach_error_handler(&my_error_handler); - motor->set_step_mode(StepperMotor::STEP_MODE_1_4); + motor->set_step_mode(StepperMotor::STEP_MODE_1_8); /* Set speed, acceleration and deceleration to scale with microstep mode */ //motor->set_max_speed(2000); @@ -93,17 +95,42 @@ motor->set_max_speed(motor->get_max_speed()<<2); motor->set_acceleration(motor->get_acceleration()<<2); motor->set_deceleration(motor->get_deceleration()<<2); + printf(" init\n\r"); + end.mode(PullUp); + /* Request to go position 9000 (quarter steps) */ + motor->run(StepperMotor::BWD); + while(1) + { + // motor->wait_while_active(); + printf("while"); + if(end) break; + } + motor->hard_stop(); + led=1; - /* Request to go position 9000 (quarter steps) */ + int pos=motor->get_position(); + printf("pos:%d\n\r", pos); + motor->go_to(pos+200); + motor->wait_while_active(); + led=0; + wait(0.5); + + motor->set_home(); + wait(1); + + motor->go_to(1000<<4); + motor->wait_while_active(); + while (true) { - motor->go_to(3000); + motor->go_to(500<<4); motor->wait_while_active(); motor->go_to(0); motor->wait_while_active(); while (button) { + } }