__
Dependencies: X_NUCLEO_IHM04A1
Diff: main.cpp
- Revision:
- 13:08617f604d55
- Parent:
- 10:9d908db05638
- Child:
- 14:1b70207bf922
--- a/main.cpp Thu Dec 06 16:33:09 2018 +0000 +++ b/main.cpp Thu Dec 06 20:19:20 2018 +0000 @@ -1,35 +1,21 @@ /* Includes ------------------------------------------------------------------*/ - /* mbed specific header files. */ #include "mbed.h" - /* Component specific header files. */ #include "L6208.h" - - /* Definitions ---------------------------------------------------------------*/ -#ifdef TARGET_NUCLEO_F334R8 -#define VREFA_PWM_PIN D11 -#define VREFB_PWM_PIN D9 -#elif TARGET_NUCLEO_F302R8 -#define VREFA_PWM_PIN D11 -#define VREFB_PWM_PIN D15 /* HW mandatory patch: bridge manually D9 with D15 */ -#else #define VREFA_PWM_PIN D3 #define VREFB_PWM_PIN D9 -#endif - /* Variables -----------------------------------------------------------------*/ - /* Initialization parameters of the motor connected to the expansion board. */ l6208_init_t init = { - 1500, //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes - 50, //Acceleration current torque in % (from 0 to 100) - 1000, //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes - 50, //Deceleration current torque in % (from 0 to 100) - 1500, //Running speed in step/s or (1/16)th step/s for microstep modes + 150, //Acceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes + 80, //Acceleration current torque in % (from 0 to 100) + 150, //Deceleration rate in step/s^2 or (1/16)th step/s^2 for microstep modes + 80, //Deceleration current torque in % (from 0 to 100) + 1000, //Running speed in step/s or (1/16)th step/s for microstep modes 50, //Running current torque in % (from 0 to 100) 30, //Holding current torque in % (from 0 to 100) STEP_MODE_1_16, //Step mode via enum motorStepMode_t @@ -96,35 +82,7 @@ /* Attaching an error handler */ motor->attach_error_handler(&my_error_handler); - //----- run the motor BACKWARD - printf("--> Running the motor backward.\r\n"); - motor->run(StepperMotor::BWD); - - while (motor->get_status()!=STEADY) { - /* Print reached speed to the console in step/s or microsteps/s */ - printf(" Reached Speed: %d microstep/s.\r\n", motor->get_speed()); - wait_ms(50); - } - printf(" Reached Speed: %d microstep/s.\r\n", motor->get_speed()); - - /* Wait for 1 second */ - wait_ms(1000); - -//----- Decrease speed while running to one quarter of the previous speed - motor->set_max_speed(motor->get_speed()>>2); - - /* Wait until the motor starts decelerating */ - while (motor->get_status()==STEADY); - /* Wait and print speed while the motor is not steady running */ - while (motor->get_status()!=STEADY) { - /* Print reached speed to the console in step/s or microsteps/s */ - printf(" Reached Speed: %d microstep/s.\r\n", motor->get_speed()); - wait_ms(50); - } - printf(" Reached Speed: %d microstep/s.\r\n", motor->get_speed()); - - /* Wait for 5 seconds */ - wait_ms(5000); + //----- Change step mode to 1/4 microstepping mode motor->set_step_mode(StepperMotor::STEP_MODE_1_4); @@ -134,31 +92,23 @@ motor->set_acceleration(motor->get_acceleration()<<4); motor->set_deceleration(motor->get_deceleration()<<4); - /* Request to go position 800 (quarter steps) */ + /* Request to go position 9000 (quarter steps) */ + while (true) +{ motor->go_to(9000); - - /* Wait for the motor ends moving */ motor->wait_while_active(); -motor->go_to(-9000); - - /* Wait for the motor ends moving */ - motor->wait_while_active(); - /* Wait for 2 seconds */ - wait_ms(2000); -int i; - for (i = 0; i < 4; i++) { - /* Request device to go position -3200 */ - motor->go_to(3200); - + + motor->go_to(0); + motor->wait_while_active(); + while (button) + { + } +} + + /* Waiting while the motor is active. */ motor->wait_while_active(); - - /* Request device to go position 3200 */ - motor->go_to(-3200); - - /* Waiting while the motor is active. */ - motor->wait_while_active(); - } + wait_ms(5000); motor->disable(); }