Theis Rotating Platform Demo code
Dependencies: X_NUCLEO_IHM01A1_Demo_Code mbed
Fork of Demo_IHM01A1_3-Motors by
main.cpp
00001 //////////////////////////////////////// 00002 // Rotating Platform Demo Code // 00003 // Arkadiraf@gmail.com - 24/05/2017 // 00004 //////////////////////////////////////// 00005 00006 /* 00007 Parts: 00008 Nucleo STM32F401RE 00009 X-NUCLEO-IHM01A1 - 3 Stepper motor controller 00010 */ 00011 00012 /* 00013 Pinout: 00014 Nucleo STM32F401RE 00015 PA_5 --> led (DigitalOut) 00016 00017 PC - Serial 2 00018 PA_2 (Tx) --> STLINK 00019 PA_3 (Rx) --> STLINK 00020 00021 X-NUCLEO-IHM01A1 (http://www.st.com/content/ccc/resource/technical/document/data_brief/59/ff/d0/16/94/ff/49/85/DM00122463.pdf/files/DM00122463.pdf/jcr:content/translations/en.DM00122463.pdf) 00022 SPI: 00023 PA_7 (D11) --> mosi 00024 PA_9 (D12) --> miso 00025 PA_8 (D13) --> sclk 00026 00027 Motor 1 00028 PA_10(D2) --> flag_irq (DigitalOut) 00029 PA_9 (D8) --> Standby (DigitalOut) 00030 PA_8 (D7) --> MOT1Dir (DigitalOut) 00031 PC_7 (D9) --> MOT1Step (PWM) 00032 PB_6 (D10)--> ssel (DigitalOut) 00033 00034 Motor 2 00035 PA_10(D2) --> flag_irq (DigitalOut) 00036 PA_9 (D8) --> Standby (DigitalOut) 00037 PB_5 (D4) --> MOT2Dir (DigitalOut) 00038 PB_3 (D3) --> MOT2Step (PWM) 00039 PB_6 (D10)--> ssel (DigitalOut) 00040 00041 Motor 3 00042 PA_10(D2) --> flag_irq (DigitalOut) 00043 PA_9 (D8) --> Standby (DigitalOut) 00044 PB_4 (D5) --> MOT3Dir (DigitalOut) 00045 PB_10(D6) --> MOT3Step (PWM) 00046 PB_6 (D10)--> ssel (DigitalOut) 00047 00048 00049 */ 00050 00051 /* Includes ------------------------------------------------------------------*/ 00052 00053 /* mbed specific header files. */ 00054 #include "mbed.h" 00055 00056 /* Helper header files. */ 00057 #include "DevSPI.h" 00058 00059 /* Component specific header files. */ 00060 #include "l6474_class.h" 00061 00062 00063 /* Definitions ---------------------------------------------------------------*/ 00064 00065 /* Number of steps to move. */ 00066 #define STEPS 3200 00067 00068 00069 /* Variables -----------------------------------------------------------------*/ 00070 00071 /* Motor Control Component. */ 00072 L6474 *motor1; 00073 L6474 *motor2; 00074 L6474 *motor3; 00075 00076 /* Main ----------------------------------------------------------------------*/ 00077 00078 int main() 00079 { 00080 /*----- Initialization. -----*/ 00081 00082 /* Initializing SPI bus. */ 00083 DevSPI dev_spi(D11, D12, D13); 00084 00085 /* Initializing Motor Control Components. */ 00086 motor1 = new L6474(D2, D8, D7, D9, D10, dev_spi); 00087 motor2 = new L6474(D2, D8, D4, D3, D10, dev_spi); 00088 motor3 = new L6474(D2, D8, D5, D6, D10, dev_spi); 00089 if (motor1->Init() != COMPONENT_OK) 00090 exit(EXIT_FAILURE); 00091 if (motor2->Init() != COMPONENT_OK) 00092 exit(EXIT_FAILURE); 00093 if (motor3->Init() != COMPONENT_OK) 00094 exit(EXIT_FAILURE); 00095 00096 00097 00098 /*----- Changing motor setting. -----*/ 00099 00100 /* Setting High Impedance State to update L6474's registers. */ 00101 motor1->SoftHiZ(); 00102 motor2->SoftHiZ(); 00103 motor3->SoftHiZ(); 00104 // Disabling motor 00105 motor1->Disable(); 00106 motor2->Disable(); 00107 motor3->Disable(); 00108 /* Changing step mode. */ 00109 motor1->SetStepMode(STEP_MODE_1_16); 00110 motor2->SetStepMode(STEP_MODE_1_16); 00111 motor3->SetStepMode(STEP_MODE_1_16); 00112 00113 /* Increasing the torque regulation current. */ 00114 motor1->SetParameter(L6474_TVAL, 1250); // Limit 2.0A 00115 motor2->SetParameter(L6474_TVAL, 1650); // Limit 1.7A 00116 motor3->SetParameter(L6474_TVAL, 300); // Limit 0.28A 00117 00118 /* Max speed to 2400 step/s. */ 00119 motor1->SetMaxSpeed(750); 00120 motor2->SetMaxSpeed(750); 00121 motor3->SetMaxSpeed(750); 00122 00123 /* Min speed to 200 step/s. */ 00124 motor1->SetMinSpeed(100); 00125 motor2->SetMinSpeed(100); 00126 motor3->SetMinSpeed(100); 00127 00128 /* set accelerations */ 00129 motor1->SetAcceleration(250); 00130 motor2->SetAcceleration(250); 00131 motor3->SetAcceleration(250); 00132 motor1->SetDeceleration(250); 00133 motor2->SetDeceleration(250); 00134 motor3->SetDeceleration(250); 00135 00136 // Enabling motor 00137 motor1->Enable(); 00138 motor2->Enable(); 00139 motor3->Enable(); 00140 00141 00142 /* Printing to the console. */ 00143 printf("Motor Control Application Example for 3 Motors\r\n\n"); 00144 00145 /*----- Moving. -----*/ 00146 00147 /* Moving N steps in the forward direction. */ 00148 motor1->Move(StepperMotor::FWD, STEPS); 00149 motor2->Move(StepperMotor::FWD, STEPS); 00150 motor3->Move(StepperMotor::FWD, STEPS); 00151 /* Waiting while the motor is active. */ 00152 motor1->WaitWhileActive(); 00153 motor2->WaitWhileActive(); 00154 motor3->WaitWhileActive(); 00155 00156 /* Waiting 2 seconds. */ 00157 wait_ms(2000); 00158 00159 00160 /* Moving N steps in the backward direction. */ 00161 motor1->Move(StepperMotor::BWD, STEPS); 00162 motor2->Move(StepperMotor::BWD, STEPS); 00163 motor3->Move(StepperMotor::BWD, STEPS); 00164 /* Waiting while the motor is active. */ 00165 motor1->WaitWhileActive(); 00166 motor2->WaitWhileActive(); 00167 motor3->WaitWhileActive(); 00168 00169 /* Waiting 2 seconds. */ 00170 wait_ms(2000); 00171 00172 /* Infinite Loop. */ 00173 while(1) 00174 { 00175 /*----- Moving. -----*/ 00176 00177 /* Moving N steps in the forward direction. */ 00178 motor1->Move(StepperMotor::FWD, STEPS); 00179 motor2->Move(StepperMotor::FWD, STEPS); 00180 motor3->Move(StepperMotor::FWD, STEPS); 00181 /* Waiting while the motor is active. */ 00182 motor1->WaitWhileActive(); 00183 motor2->WaitWhileActive(); 00184 motor3->WaitWhileActive(); 00185 00186 /* Moving N steps in the backward direction. */ 00187 motor1->Move(StepperMotor::BWD, STEPS); 00188 motor2->Move(StepperMotor::BWD, STEPS); 00189 motor3->Move(StepperMotor::BWD, STEPS); 00190 /* Waiting while the motor is active. */ 00191 motor1->WaitWhileActive(); 00192 motor2->WaitWhileActive(); 00193 motor3->WaitWhileActive(); 00194 00195 /* Waiting 2 seconds. */ 00196 wait_ms(2000); 00197 } 00198 }
Generated on Fri Jul 15 2022 02:35:46 by 1.7.2