Example program for library X-NUCLEO-IHM12A1 using two low voltage dual brush DC motors
Dependencies: X_NUCLEO_IHM12A1 mbed
Fork of HelloWorld_IHM12A1 by
This application provides a simple example of usage of the X-NUCLEO-IHM12A1 Dual Brush DC Motor Control Expansion Board.
It shows how to use 2 bidirectional brush DC motors connected to the board by executing a 13 steps loop:
- Step 0) Motor 0 runs in forward at 100% of max speed, Motor 1 is inactive
- Step 1) Motor 0 runs in forward at 75% of max speed, Motor 1 runs in backward at 100% of max speed
- Step 2) Motor 0 runs in forward at 50% of max speed, Motor 1 runs in backward at 75% of max speed
- Step 3) Motor 0 runs in forward at 25% of max speed, Motor 1 runs in backward at 50% of max speed
- Step 4) Motor 0 is stopped, Motor 1 runs in backward at 25% of max speed
- Step 5) Motor 0 runs in backward at 25% of max speed, Motor 1 is stopped
- Step 6) Motor 0 runs in backward at 50% of max speed, Motor 1 runs in forward at 25% of max speed
- Step 7) Motor 0 runs in backward at 75% of max speed, Motor 1 runs in forward at 50% of max speed
- Step 8) Motor 0 runs in backward at 100% of max speed, Motor 1 runs in forward at 75% of max speed
- Step 9) Motor 0 runs in backward at 100% of max speed, Motor 1 runs in forward at 100% of max speed
- Step 10) Stop both motors and disable bridges
- Step 11) Motor 0 runs in forward at 100% of max speed, Motor 1 runs in forward at 100% of max speed
- Step 12) Stop both motors and enter standby mode
For the hardware configuration of the expansion board, please refer to the X_NUCLEO_IHM12A1 library web page.
main.cpp@6:bd2fa888c101, 2017-03-24 (annotated)
- Committer:
- Davidroid
- Date:
- Fri Mar 24 14:13:53 2017 +0000
- Revision:
- 6:bd2fa888c101
- Parent:
- 5:7517162fb2b9
- Child:
- 8:7dccd03ea2bc
With the new version of the library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Manu_L | 0:773e2a2be16f | 1 | /** |
Manu_L | 0:773e2a2be16f | 2 | ****************************************************************************** |
Manu_L | 0:773e2a2be16f | 3 | * @file main.cpp |
Manu_L | 0:773e2a2be16f | 4 | * @author IPC Rennes |
Manu_L | 0:773e2a2be16f | 5 | * @version V1.0.0 |
Manu_L | 0:773e2a2be16f | 6 | * @date April 25th, 2016 |
Manu_L | 0:773e2a2be16f | 7 | * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM12A1 |
Manu_L | 0:773e2a2be16f | 8 | * Motor Control Expansion Board: control of 2 Brush DC motors. |
Manu_L | 0:773e2a2be16f | 9 | ****************************************************************************** |
Manu_L | 0:773e2a2be16f | 10 | * @attention |
Manu_L | 0:773e2a2be16f | 11 | * |
Manu_L | 0:773e2a2be16f | 12 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
Manu_L | 0:773e2a2be16f | 13 | * |
Manu_L | 0:773e2a2be16f | 14 | * Redistribution and use in source and binary forms, with or without modification, |
Manu_L | 0:773e2a2be16f | 15 | * are permitted provided that the following conditions are met: |
Manu_L | 0:773e2a2be16f | 16 | * 1. Redistributions of source code must retain the above copyright notice, |
Manu_L | 0:773e2a2be16f | 17 | * this list of conditions and the following disclaimer. |
Manu_L | 0:773e2a2be16f | 18 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Manu_L | 0:773e2a2be16f | 19 | * this list of conditions and the following disclaimer in the documentation |
Manu_L | 0:773e2a2be16f | 20 | * and/or other materials provided with the distribution. |
Manu_L | 0:773e2a2be16f | 21 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Manu_L | 0:773e2a2be16f | 22 | * may be used to endorse or promote products derived from this software |
Manu_L | 0:773e2a2be16f | 23 | * without specific prior written permission. |
Manu_L | 0:773e2a2be16f | 24 | * |
Manu_L | 0:773e2a2be16f | 25 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Manu_L | 0:773e2a2be16f | 26 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Manu_L | 0:773e2a2be16f | 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Manu_L | 0:773e2a2be16f | 28 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Manu_L | 0:773e2a2be16f | 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Manu_L | 0:773e2a2be16f | 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Manu_L | 0:773e2a2be16f | 31 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Manu_L | 0:773e2a2be16f | 32 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Manu_L | 0:773e2a2be16f | 33 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Manu_L | 0:773e2a2be16f | 34 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Manu_L | 0:773e2a2be16f | 35 | * |
Manu_L | 0:773e2a2be16f | 36 | ****************************************************************************** |
Manu_L | 0:773e2a2be16f | 37 | */ |
Manu_L | 0:773e2a2be16f | 38 | |
Manu_L | 0:773e2a2be16f | 39 | /* Includes ------------------------------------------------------------------*/ |
Manu_L | 0:773e2a2be16f | 40 | |
Manu_L | 0:773e2a2be16f | 41 | /* mbed specific header files. */ |
Manu_L | 0:773e2a2be16f | 42 | #include "mbed.h" |
Manu_L | 0:773e2a2be16f | 43 | |
Manu_L | 0:773e2a2be16f | 44 | /* Component specific header files. */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 45 | #include "STSpin240_250.h" |
Manu_L | 0:773e2a2be16f | 46 | |
Manu_L | 0:773e2a2be16f | 47 | /* Variables -----------------------------------------------------------------*/ |
Manu_L | 0:773e2a2be16f | 48 | |
Manu_L | 0:773e2a2be16f | 49 | /* Initialization parameters of the motor connected to the expansion board. */ |
Davidroid | 6:bd2fa888c101 | 50 | STSpin240_250_init_t init = |
Manu_L | 0:773e2a2be16f | 51 | { |
Manu_L | 0:773e2a2be16f | 52 | 20000, /* Frequency of PWM of Input Bridge A in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 53 | 20000, /* Frequency of PWM of Input Bridge B in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 54 | 20000, /* Frequency of PWM used for Ref pin in Hz up to 100000Hz */ |
Manu_L | 0:773e2a2be16f | 55 | 50, /* Duty cycle of PWM used for Ref pin (from 0 to 100) */ |
Manu_L | 0:773e2a2be16f | 56 | TRUE /* Dual Bridge configuration (FALSE for mono, TRUE for dual brush dc) */ |
Manu_L | 0:773e2a2be16f | 57 | }; |
Manu_L | 0:773e2a2be16f | 58 | |
Manu_L | 0:773e2a2be16f | 59 | /* Motor Control Component. */ |
Davidroid | 6:bd2fa888c101 | 60 | STSpin240_250 *motor; |
Manu_L | 0:773e2a2be16f | 61 | |
Manu_L | 0:773e2a2be16f | 62 | /* Functions -----------------------------------------------------------------*/ |
Manu_L | 0:773e2a2be16f | 63 | |
Manu_L | 0:773e2a2be16f | 64 | /** |
Manu_L | 0:773e2a2be16f | 65 | * @brief This is an example of error handler. |
Manu_L | 0:773e2a2be16f | 66 | * @param[in] error Number of the error |
Manu_L | 0:773e2a2be16f | 67 | * @retval None |
Manu_L | 0:773e2a2be16f | 68 | * @note If needed, implement it, and then attach it: |
davide.aliprandi@st.com | 5:7517162fb2b9 | 69 | * + motor->attach_error_handler(&my_error_handler); |
Manu_L | 0:773e2a2be16f | 70 | */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 71 | void my_error_handler(uint16_t error) |
Manu_L | 0:773e2a2be16f | 72 | { |
Manu_L | 0:773e2a2be16f | 73 | /* Printing to the console. */ |
Manu_L | 0:773e2a2be16f | 74 | printf("Error %d detected\r\n\n", error); |
Manu_L | 0:773e2a2be16f | 75 | |
Manu_L | 0:773e2a2be16f | 76 | /* Infinite loop */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 77 | while (true) { |
Manu_L | 0:773e2a2be16f | 78 | } |
Manu_L | 0:773e2a2be16f | 79 | } |
Manu_L | 0:773e2a2be16f | 80 | |
Manu_L | 0:773e2a2be16f | 81 | /** |
Manu_L | 0:773e2a2be16f | 82 | * @brief This is an example of user handler for the flag interrupt. |
Manu_L | 0:773e2a2be16f | 83 | * @param None |
Manu_L | 0:773e2a2be16f | 84 | * @retval None |
Manu_L | 0:773e2a2be16f | 85 | * @note If needed, implement it, and then attach and enable it: |
davide.aliprandi@st.com | 5:7517162fb2b9 | 86 | * + motor->attach_flag_irq(&my_flag_irq_handler); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 87 | * + motor->enable_flag_irq(); |
Manu_L | 0:773e2a2be16f | 88 | * To disable it: |
Manu_L | 0:773e2a2be16f | 89 | * + motor->DisbleFlagIRQ(); |
Manu_L | 0:773e2a2be16f | 90 | */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 91 | void my_flag_irq_handler(void) |
Manu_L | 0:773e2a2be16f | 92 | { |
Manu_L | 0:773e2a2be16f | 93 | /* Code to be customised */ |
Manu_L | 0:773e2a2be16f | 94 | /************************/ |
Manu_L | 0:773e2a2be16f | 95 | |
Manu_L | 0:773e2a2be16f | 96 | printf(" WARNING: \"FLAG\" interrupt triggered.\r\n"); |
Manu_L | 0:773e2a2be16f | 97 | |
Manu_L | 0:773e2a2be16f | 98 | /* Get the state of bridge A */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 99 | uint16_t bridgeState = motor->get_bridge_status(0); |
Manu_L | 0:773e2a2be16f | 100 | |
davide.aliprandi@st.com | 5:7517162fb2b9 | 101 | if (bridgeState == 0) { |
davide.aliprandi@st.com | 5:7517162fb2b9 | 102 | if (motor->get_device_state(0) != INACTIVE) { |
Manu_L | 0:773e2a2be16f | 103 | /* Bridges were disabled due to overcurrent or over temperature */ |
Manu_L | 0:773e2a2be16f | 104 | /* When motor was running */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 105 | my_error_handler(0XBAD0); |
Manu_L | 0:773e2a2be16f | 106 | } |
Manu_L | 0:773e2a2be16f | 107 | } |
Manu_L | 0:773e2a2be16f | 108 | } |
Manu_L | 0:773e2a2be16f | 109 | |
Manu_L | 0:773e2a2be16f | 110 | /* Main ----------------------------------------------------------------------*/ |
Manu_L | 0:773e2a2be16f | 111 | |
Manu_L | 0:773e2a2be16f | 112 | int main() |
Manu_L | 0:773e2a2be16f | 113 | { |
Manu_L | 0:773e2a2be16f | 114 | uint8_t demoStep = 0; |
Manu_L | 0:773e2a2be16f | 115 | |
Manu_L | 0:773e2a2be16f | 116 | /* Printing to the console. */ |
Manu_L | 0:773e2a2be16f | 117 | printf("STARTING MAIN PROGRAM\r\n"); |
Manu_L | 0:773e2a2be16f | 118 | |
Manu_L | 0:773e2a2be16f | 119 | //----- Initialization |
Manu_L | 0:773e2a2be16f | 120 | |
Manu_L | 0:773e2a2be16f | 121 | /* Initializing Motor Control Component. */ |
Manu_L | 0:773e2a2be16f | 122 | #if (defined TARGET_NUCLEO_F030R8)||(defined TARGET_NUCLEO_F334R8) |
Davidroid | 6:bd2fa888c101 | 123 | motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A2); |
Manu_L | 0:773e2a2be16f | 124 | #elif (defined TARGET_NUCLEO_L152RE) |
Davidroid | 6:bd2fa888c101 | 125 | motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A3); |
Manu_L | 0:773e2a2be16f | 126 | #else |
Davidroid | 6:bd2fa888c101 | 127 | motor = new STSpin240_250(D2, D9, D6, D7, D5, D4, A0); |
Manu_L | 0:773e2a2be16f | 128 | #endif |
davide.aliprandi@st.com | 5:7517162fb2b9 | 129 | if (motor->init(&init) != COMPONENT_OK) exit(EXIT_FAILURE); |
Manu_L | 0:773e2a2be16f | 130 | |
Manu_L | 0:773e2a2be16f | 131 | /* Set dual bridge enabled as two motors are used*/ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 132 | motor->set_dual_full_bridge_config(1); |
Manu_L | 0:773e2a2be16f | 133 | |
Manu_L | 0:773e2a2be16f | 134 | /* Attaching and enabling an interrupt handler. */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 135 | motor->attach_flag_irq(&my_flag_irq_handler); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 136 | motor->enable_flag_irq(); |
Manu_L | 0:773e2a2be16f | 137 | |
Manu_L | 0:773e2a2be16f | 138 | /* Attaching an error handler */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 139 | motor->attach_error_handler(&my_error_handler); |
Manu_L | 0:773e2a2be16f | 140 | |
Manu_L | 0:773e2a2be16f | 141 | /* Printing to the console. */ |
Manu_L | 0:773e2a2be16f | 142 | printf("Motor Control Application Example for 2 brush DC motors\r\n"); |
Manu_L | 0:773e2a2be16f | 143 | |
Manu_L | 0:773e2a2be16f | 144 | /* Set PWM Frequency of Ref to 15000 Hz */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 145 | motor->set_ref_pwm_freq(0, 15000); |
Manu_L | 0:773e2a2be16f | 146 | |
Manu_L | 0:773e2a2be16f | 147 | /* Set PWM duty cycle of Ref to 60% */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 148 | motor->set_ref_pwm_dc(0, 60); |
Manu_L | 0:773e2a2be16f | 149 | |
Manu_L | 0:773e2a2be16f | 150 | /* Set PWM Frequency of bridge A inputs to 10000 Hz */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 151 | motor->set_bridge_input_pwm_freq(0,10000); |
Manu_L | 0:773e2a2be16f | 152 | |
Manu_L | 0:773e2a2be16f | 153 | /* Set PWM Frequency of bridge B inputs to 10000 Hz */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 154 | motor->set_bridge_input_pwm_freq(1,10000); |
Manu_L | 0:773e2a2be16f | 155 | |
Manu_L | 0:773e2a2be16f | 156 | /* Infinite Loop. */ |
Manu_L | 0:773e2a2be16f | 157 | printf("--> Infinite Loop...\r\n"); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 158 | while (true) { |
davide.aliprandi@st.com | 5:7517162fb2b9 | 159 | switch (demoStep) { |
davide.aliprandi@st.com | 5:7517162fb2b9 | 160 | case 0: { |
Manu_L | 0:773e2a2be16f | 161 | printf("STEP 0: Motor(0) FWD Speed=100%% - Motor(1) Inactive\r\n"); |
Manu_L | 0:773e2a2be16f | 162 | /* Set speed of motor 0 to 100 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 163 | motor->set_speed(0,100); |
Manu_L | 0:773e2a2be16f | 164 | /* start motor 0 to run forward*/ |
Manu_L | 0:773e2a2be16f | 165 | /* if chip is in standby mode */ |
Manu_L | 0:773e2a2be16f | 166 | /* it is automatically awakened */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 167 | motor->run(0, BDCMotor::FWD); |
Manu_L | 0:773e2a2be16f | 168 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 169 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 170 | case 1: { |
Manu_L | 0:773e2a2be16f | 171 | printf("STEP 1: Motor(0) FWD Speed=75%% - Motor(1) BWD Speed=100%%\r\n"); |
Manu_L | 0:773e2a2be16f | 172 | /* Set speed of motor 0 to 75 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 173 | motor->set_speed(0,75); |
Manu_L | 0:773e2a2be16f | 174 | /* Set speed of motor 1 to 100 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 175 | motor->set_speed(1,100); |
Manu_L | 0:773e2a2be16f | 176 | /* start motor 1 to run backward */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 177 | motor->run(1, BDCMotor::BWD); |
Manu_L | 0:773e2a2be16f | 178 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 179 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 180 | case 2: { |
Manu_L | 0:773e2a2be16f | 181 | printf("STEP 2: Motor(0) FWD Speed=50%% - Motor(1) BWD Speed=75%%\r\n"); |
Manu_L | 0:773e2a2be16f | 182 | /* Set speed of motor 0 to 50 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 183 | motor->set_speed(0,50); |
Manu_L | 0:773e2a2be16f | 184 | /* Set speed of motor 1 to 75% */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 185 | motor->set_speed(1,75); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 186 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 187 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 188 | case 3: { |
Manu_L | 0:773e2a2be16f | 189 | printf("STEP 3: Motor(0) FWD Speed=25%% - Motor(1) BWD Speed=50%%\r\n"); |
Manu_L | 0:773e2a2be16f | 190 | /* Set speed of motor 0 to 25 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 191 | motor->set_speed(0,25); |
Manu_L | 0:773e2a2be16f | 192 | /* Set speed of motor 1 to 50% */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 193 | motor->set_speed(1,50); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 194 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 195 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 196 | case 4: { |
Manu_L | 0:773e2a2be16f | 197 | printf("STEP 4: Motor(0) Stopped - Motor(1) BWD Speed=25%%\r\n"); |
Manu_L | 0:773e2a2be16f | 198 | /* Stop Motor 0 */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 199 | motor->hard_stop(0); |
Manu_L | 0:773e2a2be16f | 200 | /* Set speed of motor 1 to 25% */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 201 | motor->set_speed(1,25); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 202 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 203 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 204 | case 5: { |
Manu_L | 0:773e2a2be16f | 205 | printf("STEP 5: Motor(0) BWD Speed=25%% - Motor(1) Stopped\r\n"); |
Manu_L | 0:773e2a2be16f | 206 | /* Set speed of motor 0 to 25 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 207 | motor->set_speed(0,25); |
Manu_L | 0:773e2a2be16f | 208 | /* start motor 0 to run backward */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 209 | motor->run(0, BDCMotor::BWD); |
Manu_L | 0:773e2a2be16f | 210 | /* Stop Motor 1 */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 211 | motor->hard_stop(1); |
Manu_L | 0:773e2a2be16f | 212 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 213 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 214 | case 6: { |
Manu_L | 0:773e2a2be16f | 215 | printf("STEP 6: Motor(0) BWD Speed=50%% - Motor(1) FWD Speed=25%%\r\n"); |
Manu_L | 0:773e2a2be16f | 216 | /* Set speed of motor 0 to 50 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 217 | motor->set_speed(0,50); |
Manu_L | 0:773e2a2be16f | 218 | /* Set speed of motor 1 to 25 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 219 | motor->set_speed(1,25); |
Manu_L | 0:773e2a2be16f | 220 | /* start motor 1 to run backward */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 221 | motor->run(1, BDCMotor::FWD); |
Manu_L | 0:773e2a2be16f | 222 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 223 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 224 | case 7: { |
Manu_L | 0:773e2a2be16f | 225 | printf("STEP 7: Motor(0) BWD Speed=75%% - Motor(1) FWD Speed=50%%\r\n"); |
Manu_L | 0:773e2a2be16f | 226 | /* Set speed of motor 0 to 75 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 227 | motor->set_speed(0,75); |
Manu_L | 0:773e2a2be16f | 228 | /* Set speed of motor 1 to 50 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 229 | motor->set_speed(1,50); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 230 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 231 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 232 | case 8: { |
Manu_L | 0:773e2a2be16f | 233 | printf("STEP 8: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=75%%\r\n"); |
Manu_L | 0:773e2a2be16f | 234 | /* Set speed of motor 0 to 100 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 235 | motor->set_speed(0,100); |
Manu_L | 0:773e2a2be16f | 236 | /* Set speed of motor 1 to 75 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 237 | motor->set_speed(1,75); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 238 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 239 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 240 | case 9: { |
Manu_L | 0:773e2a2be16f | 241 | printf("STEP 9: Motor(0) BWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n"); |
Manu_L | 0:773e2a2be16f | 242 | /* Set speed of motor 1 to 100 % */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 243 | motor->set_speed(1,100); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 244 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 245 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 246 | case 10: { |
Manu_L | 0:773e2a2be16f | 247 | printf("STEP 10\r\n: Stop both motors and disable bridges\r\n"); |
Manu_L | 0:773e2a2be16f | 248 | /* Stop both motors and disable bridge */ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 249 | motor->hard_hiz(0); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 250 | motor->hard_hiz(1); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 251 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 252 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 253 | case 11: { |
Manu_L | 0:773e2a2be16f | 254 | printf("STEP 11: Motor(0) FWD Speed=100%% - Motor(1) FWD Speed=100%%\r\n"); |
Manu_L | 0:773e2a2be16f | 255 | /* Start both motors to go forward*/ |
davide.aliprandi@st.com | 5:7517162fb2b9 | 256 | motor->run(0,BDCMotor::FWD); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 257 | motor->run(1,BDCMotor::FWD); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 258 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 259 | } |
Manu_L | 0:773e2a2be16f | 260 | case 12: |
davide.aliprandi@st.com | 5:7517162fb2b9 | 261 | default: { |
Manu_L | 0:773e2a2be16f | 262 | printf("STEP 12: Stop both motors and enter standby mode\r\n"); |
Manu_L | 0:773e2a2be16f | 263 | /* Stop both motors and put chip in standby mode */ |
Davidroid | 6:bd2fa888c101 | 264 | motor->reset(); |
davide.aliprandi@st.com | 5:7517162fb2b9 | 265 | break; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 266 | } |
Manu_L | 0:773e2a2be16f | 267 | } |
Manu_L | 0:773e2a2be16f | 268 | |
Manu_L | 0:773e2a2be16f | 269 | /* Wait for 5 seconds */ |
Manu_L | 0:773e2a2be16f | 270 | wait_ms(5000); |
Manu_L | 0:773e2a2be16f | 271 | |
Manu_L | 0:773e2a2be16f | 272 | /* Increment demostep*/ |
Manu_L | 0:773e2a2be16f | 273 | demoStep++; |
davide.aliprandi@st.com | 5:7517162fb2b9 | 274 | if (demoStep > 12) { |
Manu_L | 0:773e2a2be16f | 275 | demoStep = 0; |
Manu_L | 0:773e2a2be16f | 276 | } |
Manu_L | 0:773e2a2be16f | 277 | } |
Manu_L | 0:773e2a2be16f | 278 | } |
davide.aliprandi@st.com | 5:7517162fb2b9 | 279 | |
Manu_L | 0:773e2a2be16f | 280 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |