Library used to control ST Nucleo Evaluation board IHM04A1, based on L6206 motor control driver.

Dependencies:   ST_INTERFACES

Dependents:   HelloWorld_IHM04A1 RoboCane_Motore arm_dcmotor_can arm_linear_can_2 ... more

Fork of X_NUCLEO_IHM04A1 by ST Expansion SW Team

Motor Control Library

Library to handle the X-NUCLEO-IHM04A1 Motor Control Expansion Board based on the L6206 component.

It allows a complete management of the L6206 by providing a complete APIs.

The key features of the library are :

  • Configuration of the L6206 (bridges inputs and enabling signals, bridges paralleling)
  • FLAG interrupts handling (overcurrent and thermal alarms reporting)
  • Handling of up to two bidirectional Brush DC motors or up to 4 unidirectional Brush DC motors depending of the bridges paralleling configuration
  • Nucleo and expansion board configuration (GPIOs, PWMs, IRQs…)

To use the L6206 driver library, the user first has to call its initialization method which:

  • Setups the required GPIOs to handle the bridges enable pins, the FLAG interrupt which reports overcurrent detection or thermal protection.
  • Loads the driver parameters with initial values configured by the user or with their predefined values from “l6206_target_config.h”, in order to program the PWMs frequency of the bridges inputs, the bridges paralleling configuration, the number and the type (bidirectional or unidirectional) of brush DC motors.

Once the initialization is done, the user can modify the driver parameters by calling specific functions to change the bridges paralleling configuration, types and numbers of motors or the PWMs frequency.

The user can also write callback functions and attach them to:

  • The flag interrupt handler depending on the actions he wants to perform when an overcurrent or a thermal alarm is reported.
  • The Error handler which is called by the library when it reports an error.

Then, the user can drive the different brush DC motors by requesting to run in a specified direction and by changing the maximal speed. When a motor is requested to run, the corresponding bridge is automatically enabled.

A motion command can be stopped at any moment:

  • Either by a hard stop which immediately stops the motor.
  • Or by a hardHiz command which immediately stops the motor and disables the bridge which is used by the motor.

The library also provides functions to disable or enable the bridges independently from the run or stop commands.

Arduino Connector Compatibility Warning

Using the X-NUCLEO-IHM04A1 expansion board with the NUCLEO-F429ZI requires adopting the following patch:

  • to connect with a wire the PB_4 Nucleo pin to the IN1A expansion board pin;
  • to connect with a wire the PC_7 Nucleo pin to the IN2A expansion board pin;
  • to connect with a wire the PA_15 Nucleo pin to the IN1B expansion board pin;
  • to connect with a wire the PB_3 Nucleo pin to the IN2B expansion board pin.


Board configuration for HelloWorld_IHM04A1 example

/media/uploads/brdirais/drive4brushdcmotor_ihm04a1.png

Committer:
brdirais
Date:
Tue May 17 09:45:13 2016 +0000
Revision:
1:2597a6165252
Parent:
0:2cb6ce8e07bd
Child:
4:24158c44f02e
- Add of Doxygen comments to all functions where missing.; - Suppression of non-used library X-NUCLEO-COMMON; - Update of MBed SDK; - Update of comments in source code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brdirais 0:2cb6ce8e07bd 1 /**
brdirais 0:2cb6ce8e07bd 2 ******************************************************************************
brdirais 0:2cb6ce8e07bd 3 * @file l6206.h
brdirais 0:2cb6ce8e07bd 4 * @author IPC Rennes
brdirais 0:2cb6ce8e07bd 5 * @version V1.2.0
brdirais 0:2cb6ce8e07bd 6 * @date March 30, 2016
brdirais 0:2cb6ce8e07bd 7 * @brief Header for L6206 driver (dual full bridge driver)
brdirais 0:2cb6ce8e07bd 8 * @note (C) COPYRIGHT 2015 STMicroelectronics
brdirais 0:2cb6ce8e07bd 9 ******************************************************************************
brdirais 0:2cb6ce8e07bd 10 * @attention
brdirais 0:2cb6ce8e07bd 11 *
brdirais 1:2597a6165252 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
brdirais 0:2cb6ce8e07bd 13 *
brdirais 0:2cb6ce8e07bd 14 * Redistribution and use in source and binary forms, with or without modification,
brdirais 0:2cb6ce8e07bd 15 * are permitted provided that the following conditions are met:
brdirais 0:2cb6ce8e07bd 16 * 1. Redistributions of source code must retain the above copyright notice,
brdirais 0:2cb6ce8e07bd 17 * this list of conditions and the following disclaimer.
brdirais 0:2cb6ce8e07bd 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
brdirais 0:2cb6ce8e07bd 19 * this list of conditions and the following disclaimer in the documentation
brdirais 0:2cb6ce8e07bd 20 * and/or other materials provided with the distribution.
brdirais 0:2cb6ce8e07bd 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
brdirais 0:2cb6ce8e07bd 22 * may be used to endorse or promote products derived from this software
brdirais 0:2cb6ce8e07bd 23 * without specific prior written permission.
brdirais 0:2cb6ce8e07bd 24 *
brdirais 0:2cb6ce8e07bd 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
brdirais 0:2cb6ce8e07bd 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
brdirais 0:2cb6ce8e07bd 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
brdirais 0:2cb6ce8e07bd 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
brdirais 0:2cb6ce8e07bd 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
brdirais 0:2cb6ce8e07bd 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
brdirais 0:2cb6ce8e07bd 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
brdirais 0:2cb6ce8e07bd 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
brdirais 0:2cb6ce8e07bd 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
brdirais 0:2cb6ce8e07bd 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
brdirais 0:2cb6ce8e07bd 35 *
brdirais 0:2cb6ce8e07bd 36 ******************************************************************************
brdirais 0:2cb6ce8e07bd 37 */
brdirais 0:2cb6ce8e07bd 38
brdirais 0:2cb6ce8e07bd 39 /* Define to prevent recursive inclusion -------------------------------------*/
brdirais 0:2cb6ce8e07bd 40 #ifndef __L6206_H
brdirais 0:2cb6ce8e07bd 41 #define __L6206_H
brdirais 0:2cb6ce8e07bd 42
brdirais 0:2cb6ce8e07bd 43 #ifdef __cplusplus
brdirais 0:2cb6ce8e07bd 44 extern "C" {
brdirais 0:2cb6ce8e07bd 45 #endif
brdirais 0:2cb6ce8e07bd 46
brdirais 0:2cb6ce8e07bd 47 /* Includes ------------------------------------------------------------------*/
brdirais 0:2cb6ce8e07bd 48 #include "l6206_target_config.h"
brdirais 0:2cb6ce8e07bd 49 #include "../Common/motor.h"
brdirais 0:2cb6ce8e07bd 50
brdirais 0:2cb6ce8e07bd 51 /** @addtogroup BSP
brdirais 0:2cb6ce8e07bd 52 * @{
brdirais 0:2cb6ce8e07bd 53 */
brdirais 1:2597a6165252 54
brdirais 1:2597a6165252 55 /** @addtogroup Components
brdirais 1:2597a6165252 56 * @{
brdirais 1:2597a6165252 57 */
brdirais 0:2cb6ce8e07bd 58
brdirais 0:2cb6ce8e07bd 59 /** @addtogroup L6206
brdirais 0:2cb6ce8e07bd 60 * @{
brdirais 0:2cb6ce8e07bd 61 */
brdirais 0:2cb6ce8e07bd 62
brdirais 0:2cb6ce8e07bd 63 /* Exported Constants --------------------------------------------------------*/
brdirais 0:2cb6ce8e07bd 64
brdirais 1:2597a6165252 65 /** @defgroup L6206_Exported_Defines L6206 Exported Defines
brdirais 0:2cb6ce8e07bd 66 * @{
brdirais 0:2cb6ce8e07bd 67 */
brdirais 0:2cb6ce8e07bd 68
brdirais 0:2cb6ce8e07bd 69 /// Current FW version
brdirais 0:2cb6ce8e07bd 70 #define L6206_FW_VERSION (0)
brdirais 0:2cb6ce8e07bd 71 ///Max number of Brush DC motors
brdirais 0:2cb6ce8e07bd 72 #define L6206_NB_MAX_MOTORS (4)
brdirais 0:2cb6ce8e07bd 73 ///Max number of Bridges
brdirais 0:2cb6ce8e07bd 74 #define L6206_NB_MAX_BRIDGES (2)
brdirais 0:2cb6ce8e07bd 75 ///Max number of input of Bridges
brdirais 0:2cb6ce8e07bd 76 #define L6206_NB_MAX_BRIDGE_INPUT (2 * L6206_NB_MAX_BRIDGES)
brdirais 0:2cb6ce8e07bd 77 /// MCU wait time in ms after power bridges are enabled
brdirais 0:2cb6ce8e07bd 78 #define BSP_MOTOR_CONTROL_BOARD_BRIDGE_TURN_ON_DELAY (20)
brdirais 0:2cb6ce8e07bd 79
brdirais 0:2cb6ce8e07bd 80 /**
brdirais 0:2cb6ce8e07bd 81 * @}
brdirais 0:2cb6ce8e07bd 82 */
brdirais 0:2cb6ce8e07bd 83
brdirais 0:2cb6ce8e07bd 84
brdirais 0:2cb6ce8e07bd 85 /* Exported Types -------------------------------------------------------*/
brdirais 0:2cb6ce8e07bd 86
brdirais 0:2cb6ce8e07bd 87 /** @defgroup L6206_Exported_Types L6206 Exported Types
brdirais 0:2cb6ce8e07bd 88 * @{
brdirais 0:2cb6ce8e07bd 89 */
brdirais 0:2cb6ce8e07bd 90
brdirais 0:2cb6ce8e07bd 91
brdirais 0:2cb6ce8e07bd 92
brdirais 0:2cb6ce8e07bd 93
brdirais 0:2cb6ce8e07bd 94 /** @defgroup Initialization_Structure Initialization Structure
brdirais 0:2cb6ce8e07bd 95 * @{
brdirais 0:2cb6ce8e07bd 96 */
brdirais 0:2cb6ce8e07bd 97
brdirais 0:2cb6ce8e07bd 98 typedef struct
brdirais 0:2cb6ce8e07bd 99 {
brdirais 0:2cb6ce8e07bd 100 /// Bridge configuration structure.
brdirais 0:2cb6ce8e07bd 101 dualFullBridgeConfig_t config;
brdirais 0:2cb6ce8e07bd 102
brdirais 0:2cb6ce8e07bd 103 /// PWM frequency
brdirais 0:2cb6ce8e07bd 104 uint32_t pwmFreq[L6206_NB_MAX_BRIDGE_INPUT];
brdirais 0:2cb6ce8e07bd 105
brdirais 0:2cb6ce8e07bd 106 /// Motor speed
brdirais 0:2cb6ce8e07bd 107 uint16_t speed[L6206_NB_MAX_MOTORS];
brdirais 0:2cb6ce8e07bd 108
brdirais 0:2cb6ce8e07bd 109 /// Motor direction
brdirais 0:2cb6ce8e07bd 110 motorDir_t direction[L6206_NB_MAX_MOTORS];
brdirais 0:2cb6ce8e07bd 111
brdirais 0:2cb6ce8e07bd 112 /// Current motor state
brdirais 0:2cb6ce8e07bd 113 motorState_t motionState[L6206_NB_MAX_MOTORS];
brdirais 0:2cb6ce8e07bd 114
brdirais 0:2cb6ce8e07bd 115 /// Bridge enabled (true) or not (false)
brdirais 0:2cb6ce8e07bd 116 bool bridgeEnabled[L6206_NB_MAX_BRIDGES];
brdirais 0:2cb6ce8e07bd 117 } deviceParams_t;
brdirais 0:2cb6ce8e07bd 118
brdirais 0:2cb6ce8e07bd 119
brdirais 0:2cb6ce8e07bd 120
brdirais 0:2cb6ce8e07bd 121
brdirais 0:2cb6ce8e07bd 122 typedef deviceParams_t L6206_Init_t;
brdirais 0:2cb6ce8e07bd 123
brdirais 0:2cb6ce8e07bd 124
brdirais 0:2cb6ce8e07bd 125
brdirais 0:2cb6ce8e07bd 126 /**
brdirais 0:2cb6ce8e07bd 127 * @}
brdirais 0:2cb6ce8e07bd 128 */
brdirais 0:2cb6ce8e07bd 129
brdirais 0:2cb6ce8e07bd 130
brdirais 0:2cb6ce8e07bd 131 /** @defgroup Data_Structure Data Structure
brdirais 0:2cb6ce8e07bd 132 * @{
brdirais 0:2cb6ce8e07bd 133 */
brdirais 0:2cb6ce8e07bd 134
brdirais 0:2cb6ce8e07bd 135 /* ACTION --------------------------------------------------------------------*
brdirais 0:2cb6ce8e07bd 136 * Declare here the structure of component's data, if any, one variable per *
brdirais 0:2cb6ce8e07bd 137 * line without initialization. *
brdirais 0:2cb6ce8e07bd 138 * *
brdirais 0:2cb6ce8e07bd 139 * Example: *
brdirais 0:2cb6ce8e07bd 140 * typedef struct *
brdirais 0:2cb6ce8e07bd 141 * { *
brdirais 0:2cb6ce8e07bd 142 * int T0_out; *
brdirais 0:2cb6ce8e07bd 143 * int T1_out; *
brdirais 0:2cb6ce8e07bd 144 * float T0_degC; *
brdirais 0:2cb6ce8e07bd 145 * float T1_degC; *
brdirais 0:2cb6ce8e07bd 146 * } COMPONENT_Data_t; *
brdirais 0:2cb6ce8e07bd 147 *----------------------------------------------------------------------------*/
brdirais 0:2cb6ce8e07bd 148 typedef struct
brdirais 0:2cb6ce8e07bd 149 {
brdirais 0:2cb6ce8e07bd 150 /// Function pointer to flag interrupt call back
brdirais 0:2cb6ce8e07bd 151 void (*flagInterruptCallback)(void);
brdirais 0:2cb6ce8e07bd 152
brdirais 0:2cb6ce8e07bd 153 /// Function pointer to error handler call back
brdirais 0:2cb6ce8e07bd 154 void (*errorHandlerCallback)(uint16_t error);
brdirais 0:2cb6ce8e07bd 155
brdirais 0:2cb6ce8e07bd 156 /// number of L6206 devices
brdirais 0:2cb6ce8e07bd 157 uint8_t numberOfDevices;
brdirais 0:2cb6ce8e07bd 158
brdirais 0:2cb6ce8e07bd 159 /// L6206 driver instance
brdirais 0:2cb6ce8e07bd 160 uint8_t deviceInstance;
brdirais 0:2cb6ce8e07bd 161
brdirais 0:2cb6ce8e07bd 162 /// L6206 Device Paramaters structure
brdirais 0:2cb6ce8e07bd 163 deviceParams_t devicePrm;
brdirais 0:2cb6ce8e07bd 164 } L6206_Data_t;
brdirais 0:2cb6ce8e07bd 165
brdirais 0:2cb6ce8e07bd 166 /**
brdirais 0:2cb6ce8e07bd 167 * @}
brdirais 0:2cb6ce8e07bd 168 */
brdirais 0:2cb6ce8e07bd 169
brdirais 0:2cb6ce8e07bd 170
brdirais 0:2cb6ce8e07bd 171
brdirais 0:2cb6ce8e07bd 172 /**
brdirais 0:2cb6ce8e07bd 173 * @}
brdirais 0:2cb6ce8e07bd 174 */
brdirais 0:2cb6ce8e07bd 175
brdirais 0:2cb6ce8e07bd 176 /* Exported functions --------------------------------------------------------*/
brdirais 0:2cb6ce8e07bd 177
brdirais 0:2cb6ce8e07bd 178
brdirais 0:2cb6ce8e07bd 179 /** @defgroup MotorControl_Board_Linked_Functions MotorControl Board Linked Functions
brdirais 0:2cb6ce8e07bd 180 * @{
brdirais 0:2cb6ce8e07bd 181 */
brdirais 0:2cb6ce8e07bd 182 ///Delay of the requested number of milliseconds
brdirais 0:2cb6ce8e07bd 183 extern void L6206_Board_Delay(void *handle, uint32_t delay);
brdirais 0:2cb6ce8e07bd 184 ///Disable the specified bridge
brdirais 0:2cb6ce8e07bd 185 extern void L6206_Board_DisableBridge(void *handle, uint8_t bridgeId);
brdirais 0:2cb6ce8e07bd 186 ///Enable the specified bridge
brdirais 0:2cb6ce8e07bd 187 extern void L6206_Board_EnableBridge(void *handle, uint8_t bridgeId, uint8_t addDelay);
brdirais 0:2cb6ce8e07bd 188 //Get the status of the flag and enable Pin
brdirais 0:2cb6ce8e07bd 189 extern uint32_t L6206_Board_GetFlagPinState(void *handle, uint8_t bridgeId);
brdirais 0:2cb6ce8e07bd 190 ///Initialise GPIOs used for L6206s
brdirais 0:2cb6ce8e07bd 191 extern void L6206_Board_GpioInit(void *handle);
brdirais 0:2cb6ce8e07bd 192 ///Set Briges Inputs PWM frequency and start it
brdirais 0:2cb6ce8e07bd 193 extern void L6206_Board_PwmSetFreq(void *handle, uint8_t bridgeInput, uint32_t newFreq, uint8_t duty);
brdirais 0:2cb6ce8e07bd 194 ///Deinitialise the PWM of the specified bridge input
brdirais 0:2cb6ce8e07bd 195 extern void L6206_Board_PwmDeInit(void *handle, uint8_t bridgeInput);
brdirais 0:2cb6ce8e07bd 196 ///Init the PWM of the specified bridge input
brdirais 0:2cb6ce8e07bd 197 extern void L6206_Board_PwmInit(void *handle, uint8_t bridgeInput);
brdirais 0:2cb6ce8e07bd 198 ///Stop the PWM of the specified bridge input
brdirais 0:2cb6ce8e07bd 199 extern void L6206_Board_PwmStop(void *handle, uint8_t bridgeInput);
brdirais 1:2597a6165252 200 /**
brdirais 1:2597a6165252 201 * @}
brdirais 1:2597a6165252 202 */
brdirais 0:2cb6ce8e07bd 203
brdirais 0:2cb6ce8e07bd 204
brdirais 0:2cb6ce8e07bd 205
brdirais 0:2cb6ce8e07bd 206 /**
brdirais 0:2cb6ce8e07bd 207 * @}
brdirais 0:2cb6ce8e07bd 208 */
brdirais 0:2cb6ce8e07bd 209
brdirais 0:2cb6ce8e07bd 210
brdirais 0:2cb6ce8e07bd 211 /**
brdirais 0:2cb6ce8e07bd 212 * @}
brdirais 0:2cb6ce8e07bd 213 */
brdirais 0:2cb6ce8e07bd 214
brdirais 0:2cb6ce8e07bd 215 /**
brdirais 0:2cb6ce8e07bd 216 * @}
brdirais 0:2cb6ce8e07bd 217 */
brdirais 0:2cb6ce8e07bd 218
brdirais 0:2cb6ce8e07bd 219 #ifdef __cplusplus
brdirais 0:2cb6ce8e07bd 220 }
brdirais 0:2cb6ce8e07bd 221 #endif
brdirais 0:2cb6ce8e07bd 222
brdirais 0:2cb6ce8e07bd 223 #endif /* #ifndef __L6206_H */
brdirais 0:2cb6ce8e07bd 224
brdirais 0:2cb6ce8e07bd 225
brdirais 0:2cb6ce8e07bd 226 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
brdirais 0:2cb6ce8e07bd 227
brdirais 0:2cb6ce8e07bd 228