Library to handle the X_NUCLEO_IHM02A1 Motor Control Expansion Board based on the L6470 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   HelloWorld_IHM02A1 ConcorsoFinal HelloWorld_IHM02A1_mbedOS HelloWorld_IHM02A1-Serialinterpreter ... more

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM02A1 Motor Control Expansion Board based on the the L6470 component.

Daisy-Chain Configuration

The two L6470 components mounted on this board are connected in daisy-chain configuration. This board can be stacked up to four times so that the eight L6470 components will be connected two-by-two in daisy-chain configuration.

Concerning the SSEL pin of the SPI communication, each expansion board must be in one of the following configuration:

  • SB_23 resistor connected only: SSEL on pin A2;
  • SB_7 resistor connected only: SSEL on pin D2;
  • SB_8 resistor connected only: SSEL on pin D10;
  • SB_9 resistor connected only: SSEL on pin D5.

Arduino Connector Compatibility Warning

X-NUCLEO-IHM02A1 is Arduino compatible with one exception: instead of using D13 pin to drive the SPI clock, it uses D3 pin, hence the default configuration for this library is with the SPI clock on D3 pin.

To be fully Arduino compatible the following patch is required:

  • to remove the SB34 resistor;
  • to solder the SB12 resistor.

Alternatively, you can route the Nucleo board’s D13 pin directly to the expansion board’s D3 pin with a wire. In case you patch your expansion board or route the pin, the SPI clock will be driven on D13 pin rather than on D3 pin, and you have also to initialize the sclk PinName variable with D13 rather than D3. This patch is known to be required, for example, on the following boards: NUCLEO-F103RB, NUCLEO-F302RB, NUCLEO-F411RE, and NUCLEO-F429ZI.

If you use D13 pin for the SPI clock, please be aware that on STM32 Nucleo boards you may not drive the LED, otherwise you will get a conflict: the LED on STM32 Nucleo boards is connected to the D13 pin.

Example Applications

Committer:
Davidroid
Date:
Tue Feb 09 16:01:30 2016 +0000
Revision:
14:e614697ebf34
Parent:
11:1aca63b2f034
+ Updated with the new template's syntax.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:92706998571a 1 /**
Davidroid 14:e614697ebf34 2 ******************************************************************************
Davidroid 14:e614697ebf34 3 * @file microstepping_motor.h
Davidroid 14:e614697ebf34 4 * @author IPD SYSTEM LAB & TECH MKTG
Davidroid 14:e614697ebf34 5 * @version V0.0.1
Davidroid 14:e614697ebf34 6 * @date 04-June-2015
Davidroid 14:e614697ebf34 7 * @brief This file contains all the functions prototypes for the microstepping
Davidroid 14:e614697ebf34 8 * motor driver with motion engine.
Davidroid 14:e614697ebf34 9 ******************************************************************************
Davidroid 14:e614697ebf34 10 * @attention
Davidroid 14:e614697ebf34 11 *
Davidroid 14:e614697ebf34 12 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Davidroid 14:e614697ebf34 13 *
Davidroid 14:e614697ebf34 14 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 14:e614697ebf34 15 * are permitted provided that the following conditions are met:
Davidroid 14:e614697ebf34 16 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 14:e614697ebf34 17 * this list of conditions and the following disclaimer.
Davidroid 14:e614697ebf34 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 14:e614697ebf34 19 * this list of conditions and the following disclaimer in the documentation
Davidroid 14:e614697ebf34 20 * and/or other materials provided with the distribution.
Davidroid 14:e614697ebf34 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 14:e614697ebf34 22 * may be used to endorse or promote products derived from this software
Davidroid 14:e614697ebf34 23 * without specific prior written permission.
Davidroid 14:e614697ebf34 24 *
Davidroid 14:e614697ebf34 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 14:e614697ebf34 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 14:e614697ebf34 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 14:e614697ebf34 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 14:e614697ebf34 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 14:e614697ebf34 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 14:e614697ebf34 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 14:e614697ebf34 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 14:e614697ebf34 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 14:e614697ebf34 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 14:e614697ebf34 35 *
Davidroid 14:e614697ebf34 36 ******************************************************************************
Davidroid 14:e614697ebf34 37 */
Davidroid 14:e614697ebf34 38
Davidroid 0:92706998571a 39
Davidroid 0:92706998571a 40 /* Define to prevent recursive inclusion -------------------------------------*/
Davidroid 14:e614697ebf34 41
Davidroid 0:92706998571a 42 #ifndef __MICROSTEPPINGMOTOR_H
Davidroid 0:92706998571a 43 #define __MICROSTEPPINGMOTOR_H
Davidroid 0:92706998571a 44
Davidroid 0:92706998571a 45 #ifdef __cplusplus
Davidroid 0:92706998571a 46 extern "C" {
Davidroid 0:92706998571a 47 #endif
Davidroid 0:92706998571a 48
Davidroid 14:e614697ebf34 49
Davidroid 0:92706998571a 50 /* Includes ------------------------------------------------------------------*/
Davidroid 14:e614697ebf34 51
Davidroid 0:92706998571a 52 #include <stdint.h>
Davidroid 0:92706998571a 53 #include "component.h"
Davidroid 0:92706998571a 54
Davidroid 14:e614697ebf34 55
Davidroid 14:e614697ebf34 56 /* Types ---------------------------------------------------------------------*/
Davidroid 14:e614697ebf34 57
Davidroid 0:92706998571a 58 /** @addtogroup BSP
Davidroid 0:92706998571a 59 * @{
Davidroid 0:92706998571a 60 */
Davidroid 0:92706998571a 61
Davidroid 0:92706998571a 62 /** @addtogroup Components
Davidroid 0:92706998571a 63 * @{
Davidroid 0:92706998571a 64 */
Davidroid 0:92706998571a 65
Davidroid 0:92706998571a 66 /** @defgroup MicrosteppingMotorDriver
Davidroid 0:92706998571a 67 * @{
Davidroid 0:92706998571a 68 */
Davidroid 0:92706998571a 69
Davidroid 0:92706998571a 70 /** @defgroup StepperMotorExportedTypes
Davidroid 0:92706998571a 71 * @{
Davidroid 0:92706998571a 72 */
Davidroid 0:92706998571a 73
Davidroid 0:92706998571a 74 /**
Davidroid 0:92706998571a 75 * @brief The L6470 Registers Identifiers.
Davidroid 0:92706998571a 76 */
Davidroid 0:92706998571a 77 typedef enum {
Davidroid 0:92706998571a 78 L6470_ABS_POS_ID = 0, //!< Current position
Davidroid 0:92706998571a 79 L6470_EL_POS_ID, //!< Electrical position
Davidroid 0:92706998571a 80 L6470_MARK_ID, //!< Mark position
Davidroid 0:92706998571a 81 L6470_SPEED_ID, //!< Current speed
Davidroid 0:92706998571a 82 L6470_ACC_ID, //!< Acceleration
Davidroid 0:92706998571a 83 L6470_DEC_ID, //!< Deceleration
Davidroid 0:92706998571a 84 L6470_MAX_SPEED_ID, //!< Maximum speed
Davidroid 0:92706998571a 85 L6470_MIN_SPEED_ID, //!< Minimum speed
Davidroid 0:92706998571a 86 L6470_FS_SPD_ID, //!< Full-step speed
Davidroid 0:92706998571a 87 L6470_KVAL_HOLD_ID, //!< Holding KVAL
Davidroid 0:92706998571a 88 L6470_KVAL_RUN_ID, //!< Constant speed KVAL
Davidroid 0:92706998571a 89 L6470_KVAL_ACC_ID, //!< Acceleration starting KVAL
Davidroid 0:92706998571a 90 L6470_KVAL_DEC_ID, //!< Deceleration starting KVAL
Davidroid 0:92706998571a 91 L6470_INT_SPEED_ID, //!< Intersect speed
Davidroid 0:92706998571a 92 L6470_ST_SLP_ID, //!< Start slope
Davidroid 0:92706998571a 93 L6470_FN_SLP_ACC_ID, //!< Acceleration final slope
Davidroid 0:92706998571a 94 L6470_FN_SLP_DEC_ID, //!< Deceleration final slope
Davidroid 0:92706998571a 95 L6470_K_THERM_ID, //!< Thermal compensation factor
Davidroid 0:92706998571a 96 L6470_ADC_OUT_ID, //!< ADC output, (the reset value is according to startup conditions)
Davidroid 0:92706998571a 97 L6470_OCD_TH_ID, //!< OCD threshold
Davidroid 0:92706998571a 98 L6470_STALL_TH_ID, //!< STALL threshold
Davidroid 0:92706998571a 99 L6470_STEP_MODE_ID, //!< Step mode
Davidroid 0:92706998571a 100 L6470_ALARM_EN_ID, //!< Alarm enable
Davidroid 0:92706998571a 101 L6470_CONFIG_ID, //!< IC configuration
Davidroid 14:e614697ebf34 102 L6470_STATUS_ID //!< Status, (the reset value is according to startup conditions)
Davidroid 0:92706998571a 103 } eL6470_RegId_t;
Davidroid 0:92706998571a 104
Davidroid 0:92706998571a 105 /**
Davidroid 0:92706998571a 106 * @brief The L6470 Application Commands Identifiers.
Davidroid 0:92706998571a 107 */
Davidroid 0:92706998571a 108 typedef enum {
Davidroid 0:92706998571a 109 L6470_NOP_ID = 0, //!< Nothing
Davidroid 0:92706998571a 110 L6470_SETPARAM_ID, //!< Writes VALUE in PARAM register
Davidroid 0:92706998571a 111 L6470_GETPARAM_ID, //!< Returns the stored value in PARAM register
Davidroid 0:92706998571a 112 L6470_RUN_ID, //!< Sets the target speed and the motor direction
Davidroid 0:92706998571a 113 L6470_STEPCLOCK_ID, //!< Puts the device into Step-clock mode and imposes DIR direction
Davidroid 0:92706998571a 114 L6470_MOVE_ID, //!< Makes N_STEP (micro)steps in DIR direction (Not performable when motor is running)
Davidroid 0:92706998571a 115 L6470_GOTO_ID, //!< Brings motor into ABS_POS position (minimum path)
Davidroid 0:92706998571a 116 L6470_GOTODIR_ID, //!< Brings motor into ABS_POS position forcing DIR direction
Davidroid 0:92706998571a 117 L6470_GOUNTIL_ID, //!< Performs a motion in DIR direction with speed SPD until SW is closed, the ACT action is executed then a SoftStop takes place
Davidroid 0:92706998571a 118 L6470_RELEASESW_ID, //!< Performs a motion in DIR direction at minimum speed until the SW is released (open), the ACT action is executed then a HardStop takes place
Davidroid 0:92706998571a 119 L6470_GOHOME_ID, //!< Brings the motor into HOME position
Davidroid 0:92706998571a 120 L6470_GOMARK_ID, //!< Brings the motor into MARK position
Davidroid 0:92706998571a 121 L6470_RESETPOS_ID, //!< Resets the ABS_POS register (set HOME position)
Davidroid 0:92706998571a 122 L6470_RESETDEVICE_ID, //!< Device is reset to power-up conditions
Davidroid 0:92706998571a 123 L6470_SOFTSTOP_ID, //!< Stops motor with a deceleration phase
Davidroid 0:92706998571a 124 L6470_HARDSTOP_ID, //!< Stops motor immediately
Davidroid 0:92706998571a 125 L6470_SOFTHIZ_ID, //!< Puts the bridges into high impedance status after a deceleration phase
Davidroid 0:92706998571a 126 L6470_HARDHIZ_ID, //!< Puts the bridges into high impedance status immediately
Davidroid 0:92706998571a 127 L6470_GETSTATUS_ID //!< Returns the STATUS register value
Davidroid 0:92706998571a 128 } eL6470_AppCmdId_t;
Davidroid 0:92706998571a 129
Davidroid 0:92706998571a 130 /**
Davidroid 0:92706998571a 131 * @brief The L6470 Status Register Flag identifiers.
Davidroid 0:92706998571a 132 */
Davidroid 0:92706998571a 133 typedef enum {
Davidroid 0:92706998571a 134 HiZ_ID = 0, //!< HiZ flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 135 BUSY_ID, //!< BUSY flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 136 SW_F_ID, //!< SW_F flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 137 SW_EVN_ID, //!< SW_EVN flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 138 DIR_ID, //!< DIR flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 139 MOT_STATUS_ID, //!< MOT_STATUS flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 140 NOTPERF_CMD_ID, //!< NOTPERF_CMD flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 141 WRONG_CMD_ID, //!< WRONG_CMD flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 142 UVLO_ID, //!< UVLO flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 143 TH_WRN_ID, //!< TH_WRN flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 144 TH_SD_ID, //!< TH_SD flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 145 OCD_ID, //!< OCD flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 146 STEP_LOSS_A_ID, //!< STEP_LOSS_A flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 147 STEP_LOSS_B_ID, //!< STEP_LOSS_B flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 148 SCK_MOD_ID //!< SCK_MOD flag identifier inside the L6470 Status Register
Davidroid 0:92706998571a 149 } eL6470_StatusRegisterFlagId_t;
Davidroid 0:92706998571a 150
Davidroid 0:92706998571a 151 /**
Davidroid 0:92706998571a 152 * @brief The L6470 Direction identifiers.
Davidroid 0:92706998571a 153 */
Davidroid 0:92706998571a 154 typedef enum {
Davidroid 0:92706998571a 155 L6470_DIR_REV_ID = 0, //!< Reverse direction
Davidroid 0:92706998571a 156 L6470_DIR_FWD_ID //!< Forward direction
Davidroid 0:92706998571a 157 } eL6470_DirId_t;
Davidroid 0:92706998571a 158
Davidroid 0:92706998571a 159 /**
Davidroid 0:92706998571a 160 * @brief The L6470 Action identifiers about ABS_POS register.
Davidroid 0:92706998571a 161 */
Davidroid 0:92706998571a 162 typedef enum {
Davidroid 0:92706998571a 163 L6470_ACT_RST_ID = 0, //!< ABS_POS register is reset
Davidroid 0:92706998571a 164 L6470_ACT_CPY_ID //!< ABS_POS register value is copied into the MARK register
Davidroid 0:92706998571a 165 } eL6470_ActId_t;
Davidroid 0:92706998571a 166
Davidroid 0:92706998571a 167 /**
Davidroid 0:92706998571a 168 * @brief The L6470 Status Register Flag states.
Davidroid 0:92706998571a 169 */
Davidroid 0:92706998571a 170 typedef enum {
Davidroid 0:92706998571a 171 ZERO_F = 0, //!< The flag is '0'
Davidroid 0:92706998571a 172 ONE_F = !ZERO_F //!< The flag is '1'
Davidroid 0:92706998571a 173 } eFlagStatus_t;
Davidroid 0:92706998571a 174
Davidroid 0:92706998571a 175 /**
Davidroid 0:92706998571a 176 * @brief The L6470 Motor Directions.
Davidroid 0:92706998571a 177 */
Davidroid 0:92706998571a 178 typedef enum {
Davidroid 0:92706998571a 179 REVERSE_F = 0, //!< Reverse motor direction
Davidroid 0:92706998571a 180 FORWARD_F = !REVERSE_F //!< Forward motor direction
Davidroid 0:92706998571a 181 } eMotorDirection_t;
Davidroid 0:92706998571a 182
Davidroid 0:92706998571a 183 /**
Davidroid 0:92706998571a 184 * @brief The L6470 Motor Status.
Davidroid 0:92706998571a 185 */
Davidroid 0:92706998571a 186 typedef enum {
Davidroid 0:92706998571a 187 STOPPED_F = 0, //!< Stopped
Davidroid 0:92706998571a 188 ACCELERATION_F = 1, //!< Acceleration
Davidroid 0:92706998571a 189 DECELERATION_F = 2, //!< Deceleration
Davidroid 0:92706998571a 190 CONSTANTSPEED_F = 3 //!< Constant speed
Davidroid 0:92706998571a 191 } eMotorStatus_t;
Davidroid 0:92706998571a 192
Davidroid 0:92706998571a 193 /**
Davidroid 0:92706998571a 194 * @brief The possible stepping modes for L6470.
Davidroid 0:92706998571a 195 */
Davidroid 0:92706998571a 196 typedef enum
Davidroid 0:92706998571a 197 {
Davidroid 0:92706998571a 198 FULL_STEP = 0x00, //!< Full-step
Davidroid 0:92706998571a 199 HALF_STEP = 0x01, //!< Half-step
Davidroid 0:92706998571a 200 MICROSTEP_1_4 = 0x02, //!< 1/4 microstep
Davidroid 0:92706998571a 201 MICROSTEP_1_8 = 0x03, //!< 1/8 microstep
Davidroid 0:92706998571a 202 MICROSTEP_1_16 = 0x04, //!< 1/16 microstep
Davidroid 0:92706998571a 203 MICROSTEP_1_32 = 0x05, //!< 1/32 microstep
Davidroid 0:92706998571a 204 MICROSTEP_1_64 = 0x06, //!< 1/64 microstep
Davidroid 0:92706998571a 205 MICROSTEP_1_128 = 0x07 //!< 1/128 microstep
Davidroid 0:92706998571a 206 } eMotorStepMode_t;
Davidroid 0:92706998571a 207
Davidroid 0:92706998571a 208 /**
Davidroid 0:92706998571a 209 * @brief The identifiers for the possible L6470 alarm conditions.
Davidroid 0:92706998571a 210 */
Davidroid 0:92706998571a 211 typedef enum
Davidroid 0:92706998571a 212 {
Davidroid 0:92706998571a 213 L6470_OVERCURRENT = 0x01, //!< Overcurrent
Davidroid 0:92706998571a 214 L6470_THERMAL_SHUTDOWN = 0x02, //!< Thermal shutdown
Davidroid 0:92706998571a 215 L6470_THERMAL_WARNING = 0x04, //!< Thermal warning
Davidroid 0:92706998571a 216 L6470_UNDERVOLTAGE = 0x08, //!< Undervoltage
Davidroid 0:92706998571a 217 L6470_STALL_DETECTION_A = 0x10, //!< Stall detection (Bridge A)
Davidroid 0:92706998571a 218 L6470_STALL_DETECTION_B = 0x20, //!< Stall detection (Bridge B)
Davidroid 0:92706998571a 219 L6470_SWITCH_TURN_ON_EVENT = 0x40, //!< Switch turn-on event
Davidroid 0:92706998571a 220 L6470_WRONG_OR_NON_PERFORMABLE_COMMAND = 0x80 //!< Wrong or non-performable command
Davidroid 0:92706998571a 221 } eL6470_AlarmCondition_t;
Davidroid 0:92706998571a 222
Davidroid 0:92706998571a 223 /**
Davidroid 0:92706998571a 224 * @brief The L6470 STEP_MODE Register (see L6470 DataSheet for more details).
Davidroid 0:92706998571a 225 */
Davidroid 0:92706998571a 226 typedef struct {
Davidroid 0:92706998571a 227 uint8_t STEP_SEL: 3; //!< Step mode
Davidroid 0:92706998571a 228 uint8_t WRT: 1; //!< When the register is written, this bit should be set to 0.
Davidroid 0:92706998571a 229 uint8_t SYNC_SEL: 3; //!< Synchronization selection
Davidroid 0:92706998571a 230 uint8_t SYNC_EN: 1; //!< Synchronization enable
Davidroid 0:92706998571a 231 } sL6470_StepModeRegister_t;
Davidroid 0:92706998571a 232
Davidroid 0:92706998571a 233 /**
Davidroid 0:92706998571a 234 * @brief The L6470 ALARM_EN Register (see L6470 DataSheet for more details).
Davidroid 0:92706998571a 235 */
Davidroid 0:92706998571a 236 typedef struct {
Davidroid 0:92706998571a 237 uint8_t OCD_EN: 1; //!< Overcurrent
Davidroid 0:92706998571a 238 uint8_t TH_SD_EN: 1; //!< Thermal shutdown
Davidroid 0:92706998571a 239 uint8_t TH_WRN_EN: 1; //!< Thermal warning
Davidroid 0:92706998571a 240 uint8_t UVLO_EN: 1; //!< Undervoltage
Davidroid 0:92706998571a 241 uint8_t STEP_LOSS_A_EN: 1; //!< Stall detection (Bridge A)
Davidroid 0:92706998571a 242 uint8_t STEP_LOSS_B_EN: 1; //!< Stall detection (Bridge B)
Davidroid 0:92706998571a 243 uint8_t SW_EVN_EN: 1; //!< Switch turn-on event
Davidroid 0:92706998571a 244 uint8_t WRONG_NOTPERF_CMD_EN: 1; //!< Wrong or non-performable command
Davidroid 0:92706998571a 245 } sL6470_AlarmEnRegister_t;
Davidroid 0:92706998571a 246
Davidroid 0:92706998571a 247 /**
Davidroid 0:92706998571a 248 * @brief The L6470 CONFIG Register (see L6470 DataSheet for more details).
Davidroid 0:92706998571a 249 */
Davidroid 0:92706998571a 250 typedef struct {
Davidroid 0:92706998571a 251 uint8_t OSC_SEL: 3; //!< Oscillator Selection
Davidroid 0:92706998571a 252 uint8_t EXT_CLK: 1; //!< External Clock
Davidroid 0:92706998571a 253 uint8_t SW_MODE: 1; //!< Switch mode
Davidroid 0:92706998571a 254 uint8_t EN_VSCOMP: 1; //!< Motor supply voltage compensation
Davidroid 0:92706998571a 255 uint8_t RESERVED: 1; //!< RESERVED
Davidroid 0:92706998571a 256 uint8_t OC_SD: 1; //!< Overcurrent event
Davidroid 0:92706998571a 257 uint8_t POW_SR: 2; //!< Output slew rate
Davidroid 0:92706998571a 258 uint8_t F_PWM_DEC: 3; //!< Multiplication factor
Davidroid 0:92706998571a 259 uint8_t F_PWM_INT: 3; //!< Integer division factor
Davidroid 0:92706998571a 260 } sL6470_ConfigRegister_t;
Davidroid 0:92706998571a 261
Davidroid 0:92706998571a 262 /**
Davidroid 0:92706998571a 263 * @brief The L6470 STATUS Register (see L6470 DataSheet for more details).
Davidroid 0:92706998571a 264 */
Davidroid 0:92706998571a 265 typedef struct {
Davidroid 0:92706998571a 266 uint8_t HiZ: 1; //!< The bridges are in high impedance state (the flag is active high)
Davidroid 0:92706998571a 267 uint8_t BUSY: 1; //!< BUSY pin status (the flag is active low)
Davidroid 0:92706998571a 268 uint8_t SW_F: 1; //!< SW input status (the flag is low for open and high for closed)
Davidroid 0:92706998571a 269 uint8_t SW_EVN: 1; //!< Switch turn-on event (the flag is active high)
Davidroid 0:92706998571a 270 uint8_t DIR: 1; //!< The current motor direction (1 as forward, 0 as reverse)
Davidroid 0:92706998571a 271 uint8_t MOT_STATUS: 2; //!< The current motor status (0 as stopped, 1 as acceleration, 2 as deceleration, 3 as constant speed)
Davidroid 0:92706998571a 272 uint8_t NOTPERF_CMD: 1; //!< The command received by SPI cannot be performed (the flag is active high)
Davidroid 0:92706998571a 273 uint8_t WRONG_CMD: 1; //!< The command received by SPI does not exist at all (the flag is active high)
Davidroid 0:92706998571a 274 uint8_t UVLO: 1; //!< Undervoltage lockout or reset events (the flag is active low)
Davidroid 0:92706998571a 275 uint8_t TH_WRN: 1; //!< Thermal warning event (the flag is active low)
Davidroid 0:92706998571a 276 uint8_t TH_SD: 1; //!< Thermal shutdown event (the flag is active low)
Davidroid 0:92706998571a 277 uint8_t OCD: 1; //!< Overcurrent detection event (the flag is active low)
Davidroid 0:92706998571a 278 uint8_t STEP_LOSS_A: 1; //!< Stall detection on bridge A (the flag is active low)
Davidroid 0:92706998571a 279 uint8_t STEP_LOSS_B: 1; //!< Stall detection on bridge B (the flag is active low)
Davidroid 0:92706998571a 280 uint8_t SCK_MOD: 1; //!< Step-clock mode (the flag is active high)
Davidroid 0:92706998571a 281 } sL6470_StatusRegister_t;
Davidroid 0:92706998571a 282
Davidroid 0:92706998571a 283 /**
Davidroid 0:92706998571a 284 * @brief Stepper Motor Registers
Davidroid 0:92706998571a 285 */
Davidroid 0:92706998571a 286 typedef struct
Davidroid 0:92706998571a 287 {
Davidroid 0:92706998571a 288 uint32_t ABS_POS; //!< CurrentPosition Register
Davidroid 0:92706998571a 289 uint16_t EL_POS; //!< ElectricalPosition Register
Davidroid 0:92706998571a 290 uint32_t MARK; //!< MarkPosition Register
Davidroid 0:92706998571a 291 uint32_t SPEED; //!< CurrentSpeed Register
Davidroid 0:92706998571a 292 uint16_t ACC; //!< Acceleration Register
Davidroid 0:92706998571a 293 uint16_t DEC; //!< Deceleration Register
Davidroid 0:92706998571a 294 uint16_t MAX_SPEED; //!< MaximumSpeed Register
Davidroid 0:92706998571a 295 uint16_t MIN_SPEED; //!< MinimumSpeed Register
Davidroid 0:92706998571a 296 uint16_t FS_SPD; //!< FullStepSpeed Register
Davidroid 0:92706998571a 297 uint8_t KVAL_HOLD; //!< HoldingKval Register
Davidroid 0:92706998571a 298 uint8_t KVAL_RUN; //!< ConstantSpeedKval Register
Davidroid 0:92706998571a 299 uint8_t KVAL_ACC; //!< AccelerationStartingKval Register
Davidroid 0:92706998571a 300 uint8_t KVAL_DEC; //!< DecelerationStartingKval Register
Davidroid 0:92706998571a 301 uint16_t INT_SPEED; //!< IntersectSpeed Register
Davidroid 0:92706998571a 302 uint8_t ST_SLP; //!< StartSlope Register
Davidroid 0:92706998571a 303 uint8_t FN_SLP_ACC; //!< AccelerationFinalSlope Register
Davidroid 0:92706998571a 304 uint8_t FN_SLP_DEC; //!< DecelerationFinalSlope Register
Davidroid 0:92706998571a 305 uint8_t K_THERM; //!< ThermalCompensationFactor Register
Davidroid 0:92706998571a 306 uint8_t ADC_OUT; //!< AdcOutput Register
Davidroid 0:92706998571a 307 uint8_t OCD_TH; //!< OcdThreshold Register
Davidroid 0:92706998571a 308 uint8_t STALL_TH; //!< StallThreshold Register
Davidroid 0:92706998571a 309 uint8_t STEP_MODE; //!< StepMode Register
Davidroid 0:92706998571a 310 uint8_t ALARM_EN; //!< AlarmEnable Register
Davidroid 0:92706998571a 311 uint16_t CONFIG; //!< Config Register
Davidroid 0:92706998571a 312 uint16_t STATUS; //!< Status Register
Davidroid 0:92706998571a 313 } StepperMotorRegister_t;
Davidroid 0:92706998571a 314
Davidroid 14:e614697ebf34 315 /**
Davidroid 14:e614697ebf34 316 * @brief MICROSTEPPING_MOTOR driver virtual table structure definition.
Davidroid 14:e614697ebf34 317 */
Davidroid 0:92706998571a 318 typedef struct
Davidroid 0:92706998571a 319 {
Davidroid 0:92706998571a 320 /* ACTION ----------------------------------------------------------------*
Davidroid 0:92706998571a 321 * Declare here the component's generic functions. *
Davidroid 0:92706998571a 322 * Tag this group of functions with the " Generic " C-style comment. *
Davidroid 0:92706998571a 323 * A component's interface has to define at least the two generic *
Davidroid 0:92706998571a 324 * functions provided here below within the "Example" section, as the *
Davidroid 0:92706998571a 325 * first and second functions of its Virtual Table. They have to be *
Davidroid 0:92706998571a 326 * specified exactly in the given way. *
Davidroid 0:92706998571a 327 * *
Davidroid 0:92706998571a 328 * Example: *
Davidroid 14:e614697ebf34 329 * Status_t (*Init) (void *handle, void *init); *
Davidroid 14:e614697ebf34 330 * Status_t (*ReadID) (void *handle, uint8_t *id); *
Davidroid 0:92706998571a 331 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 332 /* Generic */
Davidroid 14:e614697ebf34 333 Status_t (*Init)(void *handle, void *init);
Davidroid 14:e614697ebf34 334 Status_t (*ReadID)(void *handle, uint8_t *id);
Davidroid 0:92706998571a 335
Davidroid 0:92706998571a 336 /* ACTION ----------------------------------------------------------------*
Davidroid 0:92706998571a 337 * Declare here the component's specific functions. *
Davidroid 0:92706998571a 338 * Tag this group of functions with the " Specific " C-style comment. *
Davidroid 0:92706998571a 339 * Do not specify any function if not required. *
Davidroid 0:92706998571a 340 * *
Davidroid 0:92706998571a 341 * Example: *
Davidroid 14:e614697ebf34 342 * Status_t (*GetValue) (void *handle, float *f); *
Davidroid 0:92706998571a 343 *------------------------------------------------------------------------*/
Davidroid 0:92706998571a 344 /* Specific */
Davidroid 0:92706998571a 345 void (*SetParam)(void *handle, eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 346 uint32_t (*GetParam)(void *handle, eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 347 void (*Run)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 348 void (*StepClock)(void *handle, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 349 void (*Move)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 350 void (*GoTo)(void *handle, uint32_t AbsPos);
Davidroid 0:92706998571a 351 void (*GoToDir)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 352 void (*GoUntil)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 353 void (*ReleaseSW)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 354 void (*GoHome)(void *handle);
Davidroid 0:92706998571a 355 void (*GoMark)(void *handle);
Davidroid 0:92706998571a 356 void (*ResetPos)(void *handle);
Davidroid 0:92706998571a 357 void (*ResetDevice)(void *handle);
Davidroid 0:92706998571a 358 void (*SoftStop)(void *handle);
Davidroid 0:92706998571a 359 void (*HardStop)(void *handle);
Davidroid 0:92706998571a 360 void (*SoftHiZ)(void *handle);
Davidroid 0:92706998571a 361 void (*HardHiZ)(void *handle);
Davidroid 0:92706998571a 362 uint16_t (*GetStatus)(void *handle);
Davidroid 0:92706998571a 363 void (*PrepareSetParam)(void *handle, eL6470_RegId_t L6470_RegId, uint32_t Value);
Davidroid 0:92706998571a 364 void (*PrepareGetParam)(void *handle, eL6470_RegId_t L6470_RegId);
Davidroid 0:92706998571a 365 void (*PrepareRun)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 366 void (*PrepareStepClock)(void *handle, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 367 void (*PrepareMove)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t N_Step);
Davidroid 0:92706998571a 368 void (*PrepareGoTo)(void *handle, uint32_t AbsPos);
Davidroid 0:92706998571a 369 void (*PrepareGoToDir)(void *handle, eL6470_DirId_t L6470_DirId, uint32_t AbsPos);
Davidroid 0:92706998571a 370 void (*PrepareGoUntil)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed);
Davidroid 0:92706998571a 371 void (*PrepareReleaseSW)(void *handle, eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId);
Davidroid 0:92706998571a 372 void (*PrepareGoHome)(void *handle);
Davidroid 0:92706998571a 373 void (*PrepareGoMark)(void *handle);
Davidroid 0:92706998571a 374 void (*PrepareResetPos)(void *handle);
Davidroid 0:92706998571a 375 void (*PrepareResetDevice)(void *handle);
Davidroid 0:92706998571a 376 void (*PrepareSoftStop)(void *handle);
Davidroid 0:92706998571a 377 void (*PrepareHardStop)(void *handle);
Davidroid 0:92706998571a 378 void (*PrepareSoftHiZ)(void *handle);
Davidroid 0:92706998571a 379 void (*PrepareHardHiZ)(void *handle);
Davidroid 0:92706998571a 380 void (*PrepareGetStatus)(void *handle);
Davidroid 0:92706998571a 381 uint8_t (*CheckStatusRegisterFlag)(void *handle, uint8_t L6470_StatusRegisterFlagId);
Davidroid 0:92706998571a 382 uint8_t* (*PerformPreparedApplicationCommand)(void *handle);
Davidroid 0:92706998571a 383 uint8_t* (*GetRegisterName)(void *handle, uint8_t id);
Davidroid 0:92706998571a 384 int32_t (*AbsPos_2_Position)(void *handle, uint32_t AbsPos);
Davidroid 0:92706998571a 385 uint32_t (*Position_2_AbsPos)(void *handle, int32_t Position);
Davidroid 0:92706998571a 386 float (*Speed_2_Step_s)(void *handle, uint32_t Speed);
Davidroid 0:92706998571a 387 uint32_t (*Step_s_2_Speed)(void *handle, float Step_s);
Davidroid 0:92706998571a 388 float (*Acc_2_Step_s2)(void *handle, uint16_t Acc);
Davidroid 0:92706998571a 389 uint16_t (*Step_s2_2_Acc)(void *handle, float Step_s2);
Davidroid 0:92706998571a 390 float (*Dec_2_Step_s2)(void *handle, uint16_t Dec);
Davidroid 0:92706998571a 391 uint16_t (*Step_s2_2_Dec)(void *handle, float Step_s2);
Davidroid 0:92706998571a 392 float (*MaxSpeed_2_Step_s)(void *handle, uint16_t MaxSpeed);
Davidroid 0:92706998571a 393 uint16_t (*Step_s_2_MaxSpeed)(void *handle, float Step_s);
Davidroid 0:92706998571a 394 float (*MinSpeed_2_Step_s)(void *handle, uint16_t MinSpeed);
Davidroid 0:92706998571a 395 uint16_t (*Step_s_2_MinSpeed)(void *handle, float Step_s);
Davidroid 0:92706998571a 396 float (*FsSpd_2_Step_s)(void *handle, uint16_t FsSpd);
Davidroid 0:92706998571a 397 uint16_t (*Step_s_2_FsSpd)(void *handle, float Step_s);
Davidroid 0:92706998571a 398 float (*IntSpeed_2_Step_s)(void *handle, uint16_t IntSpeed);
Davidroid 0:92706998571a 399 uint16_t (*Step_s_2_IntSpeed)(void *handle, float Step_s);
Davidroid 0:92706998571a 400 float (*StSlp_2_s_Step)(void *handle, uint8_t StSlp);
Davidroid 0:92706998571a 401 uint8_t (*s_Step_2_StSlp)(void *handle, float s_Step);
Davidroid 0:92706998571a 402 float (*FnSlpAcc_2_s_Step)(void *handle, uint8_t FnSlpAcc);
Davidroid 0:92706998571a 403 uint8_t (*s_Step_2_FnSlpAcc)(void *handle, float s_Step);
Davidroid 0:92706998571a 404 float (*FnSlpDec_2_s_Step)(void *handle, uint8_t FnSlpDec);
Davidroid 0:92706998571a 405 uint8_t (*s_Step_2_FnSlpDec)(void *handle, float s_Step);
Davidroid 0:92706998571a 406 float (*OcdTh_2_mA)(void *handle, uint8_t OcdTh);
Davidroid 0:92706998571a 407 uint8_t (*mA_2_OcdTh)(void *handle, float mA);
Davidroid 0:92706998571a 408 float (*StallTh_2_mA)(void *handle, uint8_t StallTh);
Davidroid 0:92706998571a 409 uint8_t (*mA_2_StallTh)(void *handle, float mA);
Davidroid 14:e614697ebf34 410 uint32_t (*ExtractReturnedData)(void *handle, uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte);
Davidroid 14:e614697ebf34 411 } MICROSTEPPING_MOTOR_VTable_t;
Davidroid 0:92706998571a 412
Davidroid 0:92706998571a 413 /**
Davidroid 0:92706998571a 414 * @brief Stepper Motor Board Driver Structure
Davidroid 0:92706998571a 415 */
Davidroid 0:92706998571a 416 typedef struct
Davidroid 0:92706998571a 417 {
Davidroid 0:92706998571a 418 void (*SetParam)(uint8_t, uint8_t, eL6470_RegId_t, uint32_t);
Davidroid 0:92706998571a 419 uint32_t (*GetParam)(uint8_t, uint8_t, eL6470_RegId_t);
Davidroid 0:92706998571a 420 void (*Run)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
Davidroid 0:92706998571a 421 void (*StepClock)(uint8_t, uint8_t, eL6470_DirId_t);
Davidroid 0:92706998571a 422 void (*Move)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
Davidroid 0:92706998571a 423 void (*GoTo)(uint8_t, uint8_t L6470_Id, uint32_t AbsPos);
Davidroid 0:92706998571a 424 void (*GoToDir)(uint8_t, uint8_t, eL6470_DirId_t, uint32_t);
Davidroid 0:92706998571a 425 void (*GoUntil)(uint8_t, uint8_t, eL6470_ActId_t, eL6470_DirId_t, uint32_t);
Davidroid 0:92706998571a 426 void (*ReleaseSW)(uint8_t, uint8_t, eL6470_ActId_t, eL6470_DirId_t);
Davidroid 0:92706998571a 427 void (*GoHome)(uint8_t, uint8_t);
Davidroid 0:92706998571a 428 void (*GoMark)(uint8_t, uint8_t);
Davidroid 0:92706998571a 429 void (*ResetPos)(uint8_t, uint8_t);
Davidroid 0:92706998571a 430 void (*ResetDevice)(uint8_t, uint8_t);
Davidroid 0:92706998571a 431 void (*SoftStop)(uint8_t, uint8_t);
Davidroid 0:92706998571a 432 void (*HardStop)(uint8_t, uint8_t);
Davidroid 0:92706998571a 433 void (*SoftHiZ)(uint8_t, uint8_t);
Davidroid 0:92706998571a 434 void (*HardHiZ)(uint8_t, uint8_t);
Davidroid 0:92706998571a 435 uint16_t (*GetStatus)(uint8_t, uint8_t);
Davidroid 0:92706998571a 436 uint8_t (*CheckStatusRegisterFlag)(uint8_t, uint8_t, uint8_t);
Davidroid 0:92706998571a 437 uint8_t* (*PerformPreparedApplicationCommand)(uint8_t);
Davidroid 14:e614697ebf34 438 } MICROSTEPPING_MOTOR_EB_VTable_t;
Davidroid 0:92706998571a 439
Davidroid 0:92706998571a 440 /**
Davidroid 0:92706998571a 441 * @brief Stepper Motor Handle Structure
Davidroid 0:92706998571a 442 */
Davidroid 0:92706998571a 443 typedef struct __StepperMotorDriver_HandleTypeDef
Davidroid 0:92706998571a 444 {
Davidroid 0:92706998571a 445 uint8_t DaisyChainPosition;
Davidroid 14:e614697ebf34 446 void (*Config)(void*);
Davidroid 14:e614697ebf34 447 MICROSTEPPING_MOTOR_VTable_t *Command;
Davidroid 0:92706998571a 448 } StepperMotorDriverHandle_t;
Davidroid 0:92706998571a 449
Davidroid 0:92706998571a 450 /**
Davidroid 0:92706998571a 451 * @brief Stepper Motor Handle Structure
Davidroid 0:92706998571a 452 */
Davidroid 0:92706998571a 453 typedef struct __StepperMotorBoard_HandleTypeDef
Davidroid 0:92706998571a 454 {
Davidroid 0:92706998571a 455 uint8_t StackedPosition;
Davidroid 14:e614697ebf34 456 void (*Config)(void*);
Davidroid 14:e614697ebf34 457 MICROSTEPPING_MOTOR_EB_VTable_t *Command;
Davidroid 0:92706998571a 458 StepperMotorDriverHandle_t *StepperMotorDriverHandle[2];
Davidroid 0:92706998571a 459 uint8_t (*Select)(uint8_t);
Davidroid 0:92706998571a 460 } StepperMotorBoardHandle_t;
Davidroid 0:92706998571a 461
Davidroid 0:92706998571a 462 /**
Davidroid 0:92706998571a 463 * @}
Davidroid 0:92706998571a 464 */ /* StepperMotorExportedTypes */
Davidroid 0:92706998571a 465
Davidroid 0:92706998571a 466 /**
Davidroid 0:92706998571a 467 * @}
Davidroid 0:92706998571a 468 */ /* MicrosteppingMotorDriver */
Davidroid 0:92706998571a 469
Davidroid 0:92706998571a 470 /**
Davidroid 0:92706998571a 471 * @}
Davidroid 0:92706998571a 472 */ /* Components */
Davidroid 0:92706998571a 473
Davidroid 0:92706998571a 474 /**
Davidroid 0:92706998571a 475 * @}
Davidroid 0:92706998571a 476 */ /* BSP */
Davidroid 0:92706998571a 477
Davidroid 0:92706998571a 478 #ifdef __cplusplus
Davidroid 0:92706998571a 479 }
Davidroid 0:92706998571a 480 #endif
Davidroid 0:92706998571a 481
Davidroid 0:92706998571a 482 #endif /* __MICROSTEPPINGMOTOR_H */
Davidroid 0:92706998571a 483
Davidroid 0:92706998571a 484 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/