Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ST_INTERFACES
Dependents: HelloWorld_IHM14A1
Fork of X_NUCLEO_IHM14A1 by
Components/STSPIN820/STSPIN820_def.h@2:4fd08b67958c, 2018-09-27 (annotated)
- Committer:
- Davidroid
- Date:
- Thu Sep 27 14:05:44 2018 +0000
- Revision:
- 2:4fd08b67958c
- Parent:
- 1:bc265521eb00
Library to handle the X-NUCLEO-IHM14A1 Motor Control Expansion Board based on the STSPIN820 component.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Davidroid | 2:4fd08b67958c | 1 | /** |
Davidroid | 2:4fd08b67958c | 2 | ******************************************************************************* |
Davidroid | 2:4fd08b67958c | 3 | * @file STSPIN820_def.h |
Davidroid | 2:4fd08b67958c | 4 | * @author STM |
Davidroid | 2:4fd08b67958c | 5 | * @version V1.0.0 |
Davidroid | 2:4fd08b67958c | 6 | * @date August 7th, 2017 |
Davidroid | 2:4fd08b67958c | 7 | * @brief Header for STSPIN820 driver (fully integrated microstepping motor |
Davidroid | 2:4fd08b67958c | 8 | * driver). |
Davidroid | 2:4fd08b67958c | 9 | * @note (C) COPYRIGHT 2017 STMicroelectronics |
Davidroid | 2:4fd08b67958c | 10 | ******************************************************************************* |
Davidroid | 2:4fd08b67958c | 11 | * @attention |
Davidroid | 2:4fd08b67958c | 12 | * |
Davidroid | 2:4fd08b67958c | 13 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
Davidroid | 2:4fd08b67958c | 14 | * |
Davidroid | 2:4fd08b67958c | 15 | * Redistribution and use in source and binary forms, with or without modification, |
Davidroid | 2:4fd08b67958c | 16 | * are permitted provided that the following conditions are met: |
Davidroid | 2:4fd08b67958c | 17 | * 1. Redistributions of source code must retain the above copyright notice, |
Davidroid | 2:4fd08b67958c | 18 | * this list of conditions and the following disclaimer. |
Davidroid | 2:4fd08b67958c | 19 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
Davidroid | 2:4fd08b67958c | 20 | * this list of conditions and the following disclaimer in the documentation |
Davidroid | 2:4fd08b67958c | 21 | * and/or other materials provided with the distribution. |
Davidroid | 2:4fd08b67958c | 22 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
Davidroid | 2:4fd08b67958c | 23 | * may be used to endorse or promote products derived from this software |
Davidroid | 2:4fd08b67958c | 24 | * without specific prior written permission. |
Davidroid | 2:4fd08b67958c | 25 | * |
Davidroid | 2:4fd08b67958c | 26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
Davidroid | 2:4fd08b67958c | 27 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
Davidroid | 2:4fd08b67958c | 28 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
Davidroid | 2:4fd08b67958c | 29 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
Davidroid | 2:4fd08b67958c | 30 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
Davidroid | 2:4fd08b67958c | 31 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
Davidroid | 2:4fd08b67958c | 32 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
Davidroid | 2:4fd08b67958c | 33 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
Davidroid | 2:4fd08b67958c | 34 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
Davidroid | 2:4fd08b67958c | 35 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Davidroid | 2:4fd08b67958c | 36 | * |
Davidroid | 2:4fd08b67958c | 37 | ******************************************************************************* |
Davidroid | 2:4fd08b67958c | 38 | */ |
Davidroid | 1:bc265521eb00 | 39 | |
Davidroid | 1:bc265521eb00 | 40 | |
Davidroid | 1:bc265521eb00 | 41 | /* Define to prevent recursive inclusion -------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 42 | |
Davidroid | 1:bc265521eb00 | 43 | #ifndef __STSPIN820_H |
Davidroid | 1:bc265521eb00 | 44 | #define __STSPIN820_H |
Davidroid | 1:bc265521eb00 | 45 | |
Davidroid | 1:bc265521eb00 | 46 | #ifdef __cplusplus |
Davidroid | 1:bc265521eb00 | 47 | extern "C" { |
Davidroid | 1:bc265521eb00 | 48 | #endif |
Davidroid | 1:bc265521eb00 | 49 | |
Davidroid | 1:bc265521eb00 | 50 | |
Davidroid | 1:bc265521eb00 | 51 | /* Includes ------------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 52 | |
Davidroid | 1:bc265521eb00 | 53 | #include "STSPIN820_config.h" |
Davidroid | 1:bc265521eb00 | 54 | #include "motor_def.h" |
Davidroid | 1:bc265521eb00 | 55 | |
Davidroid | 1:bc265521eb00 | 56 | /** @addtogroup BSP |
Davidroid | 1:bc265521eb00 | 57 | * @{ |
Davidroid | 1:bc265521eb00 | 58 | */ |
Davidroid | 1:bc265521eb00 | 59 | |
Davidroid | 1:bc265521eb00 | 60 | /** @addtogroup STSPIN820 |
Davidroid | 1:bc265521eb00 | 61 | * @{ |
Davidroid | 1:bc265521eb00 | 62 | */ |
Davidroid | 1:bc265521eb00 | 63 | |
Davidroid | 1:bc265521eb00 | 64 | |
Davidroid | 1:bc265521eb00 | 65 | /* Definitions ---------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 66 | |
Davidroid | 1:bc265521eb00 | 67 | /** @defgroup STSPIN820_Exported_Constants STSPIN820 Exported Constants |
Davidroid | 1:bc265521eb00 | 68 | * @{ |
Davidroid | 1:bc265521eb00 | 69 | */ |
Davidroid | 1:bc265521eb00 | 70 | /// Current FW major version |
Davidroid | 1:bc265521eb00 | 71 | #define STSPIN820_FW_MAJOR_VERSION (uint8_t)(1) |
Davidroid | 1:bc265521eb00 | 72 | /// Current FW minor version |
Davidroid | 1:bc265521eb00 | 73 | #define STSPIN820_FW_MINOR_VERSION (uint8_t)(0) |
Davidroid | 1:bc265521eb00 | 74 | /// Current FW patch version |
Davidroid | 1:bc265521eb00 | 75 | #define STSPIN820_FW_PATCH_VERSION (uint8_t)(0) |
Davidroid | 1:bc265521eb00 | 76 | /// Current FW version |
Davidroid | 1:bc265521eb00 | 77 | #define STSPIN820_FW_VERSION (uint32_t)((STSPIN820_FW_MAJOR_VERSION<<16)|\ |
Davidroid | 1:bc265521eb00 | 78 | (STSPIN820_FW_MINOR_VERSION<<8)|\ |
Davidroid | 1:bc265521eb00 | 79 | (STSPIN820_FW_PATCH_VERSION)) |
Davidroid | 1:bc265521eb00 | 80 | |
Davidroid | 1:bc265521eb00 | 81 | /// Max position |
Davidroid | 1:bc265521eb00 | 82 | #define STSPIN820_MAX_POSITION (0x7FFFFFFF) |
Davidroid | 1:bc265521eb00 | 83 | |
Davidroid | 1:bc265521eb00 | 84 | /// Min position |
Davidroid | 1:bc265521eb00 | 85 | #define STSPIN820_MIN_POSITION (0x80000000) |
Davidroid | 1:bc265521eb00 | 86 | |
Davidroid | 1:bc265521eb00 | 87 | /// Position range |
Davidroid | 1:bc265521eb00 | 88 | #define STSPIN820_POSITION_RANGE ((uint32_t)(STSPIN820_MAX_POSITION -\ |
Davidroid | 1:bc265521eb00 | 89 | STSPIN820_MIN_POSITION)) |
Davidroid | 1:bc265521eb00 | 90 | /// STSPIN820 error base number |
Davidroid | 1:bc265521eb00 | 91 | #define STSPIN820_ERROR_BASE (0xA000) |
Davidroid | 1:bc265521eb00 | 92 | |
Davidroid | 1:bc265521eb00 | 93 | /// run bit mask |
Davidroid | 1:bc265521eb00 | 94 | #define STSPIN820_RUN_BIT_MASK (0x01) |
Davidroid | 1:bc265521eb00 | 95 | |
Davidroid | 1:bc265521eb00 | 96 | /// move bit mask |
Davidroid | 1:bc265521eb00 | 97 | #define STSPIN820_MOVE_BIT_MASK (0x02) |
Davidroid | 1:bc265521eb00 | 98 | |
Davidroid | 1:bc265521eb00 | 99 | /// soft stop bit mask |
Davidroid | 1:bc265521eb00 | 100 | #define STSPIN820_SOFT_STOP_BIT_MASK (0x04) |
Davidroid | 1:bc265521eb00 | 101 | |
Davidroid | 1:bc265521eb00 | 102 | /// direction change bit mask |
Davidroid | 1:bc265521eb00 | 103 | #define STSPIN820_DIR_CHANGE_BIT_MASK (0x08) |
Davidroid | 1:bc265521eb00 | 104 | |
Davidroid | 1:bc265521eb00 | 105 | /// Maximum frequency of the step clock frequency in Hz |
Davidroid | 1:bc265521eb00 | 106 | #define STSPIN820_MAX_STCK_FREQ (10000) |
Davidroid | 1:bc265521eb00 | 107 | |
Davidroid | 1:bc265521eb00 | 108 | /// Minimum frequency of the step clock frequency in Hz |
Davidroid | 1:bc265521eb00 | 109 | #define STSPIN820_MIN_STCK_FREQ (8) |
Davidroid | 1:bc265521eb00 | 110 | |
Davidroid | 1:bc265521eb00 | 111 | /// Minimum duration of standby |
Davidroid | 1:bc265521eb00 | 112 | #define STANDBY_MIN_DURATION (1) |
Davidroid | 1:bc265521eb00 | 113 | |
Davidroid | 1:bc265521eb00 | 114 | /// Dead time after standby exit |
Davidroid | 1:bc265521eb00 | 115 | #define AFTER_STANDBY_EXIT_DEAD_TIME (1) |
Davidroid | 1:bc265521eb00 | 116 | |
Davidroid | 1:bc265521eb00 | 117 | /// Reset delay to select step mode |
Davidroid | 1:bc265521eb00 | 118 | #define SELECT_STEP_MODE_DELAY (1) |
Davidroid | 1:bc265521eb00 | 119 | |
Davidroid | 1:bc265521eb00 | 120 | /// PWM REF and bridges disable delay |
Davidroid | 1:bc265521eb00 | 121 | #define DISABLE_DELAY (1) |
Davidroid | 1:bc265521eb00 | 122 | |
Davidroid | 1:bc265521eb00 | 123 | /// Microstepping sequencer maximum value |
Davidroid | 1:bc265521eb00 | 124 | #define SEQUENCER_MAX_VALUE (uint16_t)(0x3FF) |
Davidroid | 1:bc265521eb00 | 125 | |
Davidroid | 1:bc265521eb00 | 126 | |
Davidroid | 1:bc265521eb00 | 127 | /* Types ---------------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 128 | |
Davidroid | 1:bc265521eb00 | 129 | /** @defgroup STSPIN820_Exported_Types STSPIN820 Exported Types |
Davidroid | 1:bc265521eb00 | 130 | * @{ |
Davidroid | 1:bc265521eb00 | 131 | */ |
Davidroid | 1:bc265521eb00 | 132 | |
Davidroid | 1:bc265521eb00 | 133 | /** @defgroup Error_Types Error Types |
Davidroid | 1:bc265521eb00 | 134 | * @{ |
Davidroid | 1:bc265521eb00 | 135 | */ |
Davidroid | 1:bc265521eb00 | 136 | /// Errors |
Davidroid | 1:bc265521eb00 | 137 | typedef enum |
Davidroid | 1:bc265521eb00 | 138 | { |
Davidroid | 1:bc265521eb00 | 139 | STSPIN820_ERROR_SET_HOME = STSPIN820_ERROR_BASE, /// Error while setting home position |
Davidroid | 1:bc265521eb00 | 140 | STSPIN820_ERROR_SET_MAX_SPEED = STSPIN820_ERROR_BASE + 1, /// Error while setting max speed |
Davidroid | 1:bc265521eb00 | 141 | STSPIN820_ERROR_SET_MIN_SPEED = STSPIN820_ERROR_BASE + 2, /// Error while setting min speed |
Davidroid | 1:bc265521eb00 | 142 | STSPIN820_ERROR_SET_ACCELERATION = STSPIN820_ERROR_BASE + 3, /// Error while setting acceleration |
Davidroid | 1:bc265521eb00 | 143 | STSPIN820_ERROR_SET_DECELERATION = STSPIN820_ERROR_BASE + 4, /// Error while setting decelaration |
Davidroid | 1:bc265521eb00 | 144 | STSPIN820_ERROR_MCU_OSC_CONFIG = STSPIN820_ERROR_BASE + 5, /// Error while configuring mcu oscillator |
Davidroid | 1:bc265521eb00 | 145 | STSPIN820_ERROR_MCU_CLOCK_CONFIG = STSPIN820_ERROR_BASE + 6, /// Error while configuring mcu clock |
Davidroid | 1:bc265521eb00 | 146 | STSPIN820_ERROR_POSITION = STSPIN820_ERROR_BASE + 7, /// Unexpected current position (wrong number of steps) |
Davidroid | 1:bc265521eb00 | 147 | STSPIN820_ERROR_SPEED = STSPIN820_ERROR_BASE + 8, /// Unexpected current speed |
Davidroid | 1:bc265521eb00 | 148 | STSPIN820_ERROR_INIT = STSPIN820_ERROR_BASE + 9, /// Unexpected number of devices or unexpected value for predefined parameter |
Davidroid | 1:bc265521eb00 | 149 | STSPIN820_ERROR_SET_DIRECTION = STSPIN820_ERROR_BASE + 10, /// Error while setting direction |
Davidroid | 1:bc265521eb00 | 150 | STSPIN820_ERROR_SET_STEP_MODE = STSPIN820_ERROR_BASE + 11, /// Attempt to set an unsupported step mode |
Davidroid | 1:bc265521eb00 | 151 | STSPIN820_ERROR_APPLY_SPEED = STSPIN820_ERROR_BASE + 12, /// Error while applying speed |
Davidroid | 1:bc265521eb00 | 152 | STSPIN820_ERROR_SET_TORQUE = STSPIN820_ERROR_BASE + 13, /// Error while setting torque |
Davidroid | 1:bc265521eb00 | 153 | STSPIN820_ERROR_STEP_CLOCK = STSPIN820_ERROR_BASE + 14 /// Error related to step clock |
Davidroid | 1:bc265521eb00 | 154 | } error_types_t; |
Davidroid | 1:bc265521eb00 | 155 | /** |
Davidroid | 1:bc265521eb00 | 156 | * @} |
Davidroid | 1:bc265521eb00 | 157 | */ |
Davidroid | 1:bc265521eb00 | 158 | |
Davidroid | 1:bc265521eb00 | 159 | /** @defgroup Device_Commands Device Commands |
Davidroid | 1:bc265521eb00 | 160 | * @{ |
Davidroid | 1:bc265521eb00 | 161 | */ |
Davidroid | 1:bc265521eb00 | 162 | /// Device commands |
Davidroid | 1:bc265521eb00 | 163 | typedef enum |
Davidroid | 1:bc265521eb00 | 164 | { |
Davidroid | 1:bc265521eb00 | 165 | NO_CMD = 0x00, |
Davidroid | 1:bc265521eb00 | 166 | RUN_CMD = (STSPIN820_RUN_BIT_MASK), |
Davidroid | 1:bc265521eb00 | 167 | MOVE_CMD = (STSPIN820_MOVE_BIT_MASK), |
Davidroid | 1:bc265521eb00 | 168 | } device_command_t; |
Davidroid | 1:bc265521eb00 | 169 | /** |
Davidroid | 1:bc265521eb00 | 170 | * @} |
Davidroid | 1:bc265521eb00 | 171 | */ |
Davidroid | 1:bc265521eb00 | 172 | |
Davidroid | 1:bc265521eb00 | 173 | |
Davidroid | 1:bc265521eb00 | 174 | /** @defgroup Device_Parameters Device Parameters |
Davidroid | 1:bc265521eb00 | 175 | * @{ |
Davidroid | 1:bc265521eb00 | 176 | */ |
Davidroid | 1:bc265521eb00 | 177 | |
Davidroid | 1:bc265521eb00 | 178 | /// Device Parameters Structure Type |
Davidroid | 1:bc265521eb00 | 179 | typedef struct |
Davidroid | 1:bc265521eb00 | 180 | { |
Davidroid | 1:bc265521eb00 | 181 | /// accumulator used to store speed increase smaller than 1 pps |
Davidroid | 1:bc265521eb00 | 182 | volatile uint32_t accu; |
Davidroid | 1:bc265521eb00 | 183 | /// Position in microstep according to current step mode |
Davidroid | 1:bc265521eb00 | 184 | volatile int32_t currentPosition; |
Davidroid | 1:bc265521eb00 | 185 | /// Position of sequencer |
Davidroid | 1:bc265521eb00 | 186 | volatile int16_t sequencerPosition; |
Davidroid | 1:bc265521eb00 | 187 | /// mark position in microstep (motor position control mode) |
Davidroid | 1:bc265521eb00 | 188 | volatile int32_t markPosition; |
Davidroid | 1:bc265521eb00 | 189 | /// position in microstep at the end of the accelerating phase |
Davidroid | 1:bc265521eb00 | 190 | volatile uint32_t endAccPos; |
Davidroid | 1:bc265521eb00 | 191 | /// nb of in microstep performed from the beggining of the goto or the move command |
Davidroid | 1:bc265521eb00 | 192 | volatile uint32_t relativePos; |
Davidroid | 1:bc265521eb00 | 193 | /// position in microstep step at the start of the decelerating phase |
Davidroid | 1:bc265521eb00 | 194 | volatile uint32_t startDecPos; |
Davidroid | 1:bc265521eb00 | 195 | /// nb of microstep steps to perform for the goto or move commands |
Davidroid | 1:bc265521eb00 | 196 | uint32_t stepsToTake; |
Davidroid | 1:bc265521eb00 | 197 | |
Davidroid | 1:bc265521eb00 | 198 | /// constant speed phase torque value (%) |
Davidroid | 1:bc265521eb00 | 199 | volatile uint8_t runTorque; |
Davidroid | 1:bc265521eb00 | 200 | /// acceleration phase torque value (%) |
Davidroid | 1:bc265521eb00 | 201 | volatile uint8_t accelTorque; |
Davidroid | 1:bc265521eb00 | 202 | /// deceleration phase torque value (%) |
Davidroid | 1:bc265521eb00 | 203 | volatile uint8_t decelTorque; |
Davidroid | 1:bc265521eb00 | 204 | /// holding phase torque value (%) |
Davidroid | 1:bc265521eb00 | 205 | volatile uint8_t holdTorque; |
Davidroid | 1:bc265521eb00 | 206 | /// current selected torque value |
Davidroid | 1:bc265521eb00 | 207 | volatile uint8_t currentTorque; |
Davidroid | 1:bc265521eb00 | 208 | /// torque update |
Davidroid | 1:bc265521eb00 | 209 | volatile bool updateTorque; |
Davidroid | 1:bc265521eb00 | 210 | /// PWM frequency used to generate REF voltage |
Davidroid | 1:bc265521eb00 | 211 | volatile uint32_t refPwmFreq; |
Davidroid | 1:bc265521eb00 | 212 | /// torque boost enable |
Davidroid | 1:bc265521eb00 | 213 | volatile bool torqueBoostEnable; |
Davidroid | 1:bc265521eb00 | 214 | /// torque boost speed threshold |
Davidroid | 1:bc265521eb00 | 215 | volatile uint16_t torqueBoostSpeedThreshold; |
Davidroid | 1:bc265521eb00 | 216 | |
Davidroid | 1:bc265521eb00 | 217 | /// acceleration in pps^2 |
Davidroid | 1:bc265521eb00 | 218 | volatile uint16_t acceleration; |
Davidroid | 1:bc265521eb00 | 219 | /// deceleration in pps^2 |
Davidroid | 1:bc265521eb00 | 220 | volatile uint16_t deceleration; |
Davidroid | 1:bc265521eb00 | 221 | /// max speed in pps (speed use for goto or move command) |
Davidroid | 1:bc265521eb00 | 222 | volatile uint16_t maxSpeed; |
Davidroid | 1:bc265521eb00 | 223 | /// min speed in pps |
Davidroid | 1:bc265521eb00 | 224 | volatile uint16_t minSpeed; |
Davidroid | 1:bc265521eb00 | 225 | /// current speed in pps |
Davidroid | 1:bc265521eb00 | 226 | volatile uint16_t speed; |
Davidroid | 1:bc265521eb00 | 227 | |
Davidroid | 1:bc265521eb00 | 228 | /// command under execution |
Davidroid | 1:bc265521eb00 | 229 | volatile device_command_t commandExecuted; |
Davidroid | 1:bc265521eb00 | 230 | /// FORWARD or BACKWARD direction |
Davidroid | 1:bc265521eb00 | 231 | volatile motor_direction_t direction; |
Davidroid | 1:bc265521eb00 | 232 | /// current state of the device |
Davidroid | 1:bc265521eb00 | 233 | volatile motor_state_t motionState; |
Davidroid | 1:bc265521eb00 | 234 | /// current step mode |
Davidroid | 1:bc265521eb00 | 235 | volatile motor_step_mode_t stepMode; |
Davidroid | 1:bc265521eb00 | 236 | /// latched step mode |
Davidroid | 1:bc265521eb00 | 237 | motor_step_mode_t stepModeLatched; |
Davidroid | 1:bc265521eb00 | 238 | /// current stop mode |
Davidroid | 1:bc265521eb00 | 239 | motor_stop_mode_t stopMode; |
Davidroid | 1:bc265521eb00 | 240 | } device_params_t; |
Davidroid | 1:bc265521eb00 | 241 | |
Davidroid | 1:bc265521eb00 | 242 | /* ACTION --------------------------------------------------------------------* |
Davidroid | 1:bc265521eb00 | 243 | * Declare here the component's initialization structure, if any, one * |
Davidroid | 1:bc265521eb00 | 244 | * variable per line without initialization. * |
Davidroid | 1:bc265521eb00 | 245 | * * |
Davidroid | 1:bc265521eb00 | 246 | * Example: * |
Davidroid | 1:bc265521eb00 | 247 | * typedef struct * |
Davidroid | 1:bc265521eb00 | 248 | * { * |
Davidroid | 1:bc265521eb00 | 249 | * int frequency; * |
Davidroid | 1:bc265521eb00 | 250 | * int update_mode; * |
Davidroid | 1:bc265521eb00 | 251 | * } COMPONENT_init_t; * |
Davidroid | 1:bc265521eb00 | 252 | *----------------------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 253 | /// Motor driver initialization structure definition |
Davidroid | 1:bc265521eb00 | 254 | typedef struct |
Davidroid | 1:bc265521eb00 | 255 | { |
Davidroid | 1:bc265521eb00 | 256 | /// acceleration in pps^2 |
Davidroid | 1:bc265521eb00 | 257 | uint16_t acceleration; |
Davidroid | 1:bc265521eb00 | 258 | /// deceleration in pps^2 |
Davidroid | 1:bc265521eb00 | 259 | uint16_t deceleration; |
Davidroid | 1:bc265521eb00 | 260 | /// max speed in pps (speed use for goto or move command) |
Davidroid | 1:bc265521eb00 | 261 | uint16_t maxSpeed; |
Davidroid | 1:bc265521eb00 | 262 | /// min speed in pps |
Davidroid | 1:bc265521eb00 | 263 | uint16_t minSpeed; |
Davidroid | 1:bc265521eb00 | 264 | /// acceleration phase torque value (%) |
Davidroid | 1:bc265521eb00 | 265 | uint8_t accelTorque; |
Davidroid | 1:bc265521eb00 | 266 | /// deceleration phase torque value (%) |
Davidroid | 1:bc265521eb00 | 267 | uint8_t decelTorque; |
Davidroid | 1:bc265521eb00 | 268 | /// constant speed phase torque value (%) |
Davidroid | 1:bc265521eb00 | 269 | uint8_t runTorque; |
Davidroid | 1:bc265521eb00 | 270 | /// holding phase torque value (%) |
Davidroid | 1:bc265521eb00 | 271 | uint8_t holdTorque; |
Davidroid | 1:bc265521eb00 | 272 | /// torque boost enable |
Davidroid | 1:bc265521eb00 | 273 | bool torqueBoostEnable; |
Davidroid | 1:bc265521eb00 | 274 | /// torque boost speed threshold |
Davidroid | 1:bc265521eb00 | 275 | uint16_t torqueBoostSpeedThreshold; |
Davidroid | 1:bc265521eb00 | 276 | /// step mode |
Davidroid | 1:bc265521eb00 | 277 | motor_step_mode_t stepMode; |
Davidroid | 1:bc265521eb00 | 278 | /// stop mode |
Davidroid | 1:bc265521eb00 | 279 | motor_stop_mode_t stopMode; |
Davidroid | 1:bc265521eb00 | 280 | /// PWM frequency used to generate REF voltage |
Davidroid | 1:bc265521eb00 | 281 | uint32_t vrefPwmFreq; |
Davidroid | 1:bc265521eb00 | 282 | } STSPIN820_init_t; |
Davidroid | 1:bc265521eb00 | 283 | |
Davidroid | 1:bc265521eb00 | 284 | /** |
Davidroid | 1:bc265521eb00 | 285 | * @brief STSPIN820 driver data structure definition. |
Davidroid | 1:bc265521eb00 | 286 | */ |
Davidroid | 1:bc265521eb00 | 287 | /* ACTION --------------------------------------------------------------------* |
Davidroid | 1:bc265521eb00 | 288 | * Declare here the structure of component's data, if any, one variable per * |
Davidroid | 1:bc265521eb00 | 289 | * line without initialization. * |
Davidroid | 1:bc265521eb00 | 290 | * * |
Davidroid | 1:bc265521eb00 | 291 | * Example: * |
Davidroid | 1:bc265521eb00 | 292 | * typedef struct * |
Davidroid | 1:bc265521eb00 | 293 | * { * |
Davidroid | 1:bc265521eb00 | 294 | * int T0_out; * |
Davidroid | 1:bc265521eb00 | 295 | * int T1_out; * |
Davidroid | 1:bc265521eb00 | 296 | * float T0_degC; * |
Davidroid | 1:bc265521eb00 | 297 | * float T1_degC; * |
Davidroid | 1:bc265521eb00 | 298 | * } COMPONENT_data_t; * |
Davidroid | 1:bc265521eb00 | 299 | *----------------------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 300 | typedef struct |
Davidroid | 1:bc265521eb00 | 301 | { |
Davidroid | 1:bc265521eb00 | 302 | /// Function pointer to flag interrupt call back |
Davidroid | 1:bc265521eb00 | 303 | void (*flag_interrupt_callback)(void); |
Davidroid | 1:bc265521eb00 | 304 | /// Function pointer to error handler call back |
Davidroid | 1:bc265521eb00 | 305 | void (*error_handler_callback)(uint16_t error); |
Davidroid | 1:bc265521eb00 | 306 | uint8_t toggle_odd; |
Davidroid | 1:bc265521eb00 | 307 | |
Davidroid | 1:bc265521eb00 | 308 | /// STSPIN820 Device Paramaters structure |
Davidroid | 1:bc265521eb00 | 309 | device_params_t device_prm; |
Davidroid | 1:bc265521eb00 | 310 | uint8_t number_of_devices; |
Davidroid | 1:bc265521eb00 | 311 | uint8_t device_instance; |
Davidroid | 1:bc265521eb00 | 312 | } STSPIN820_data_t; |
Davidroid | 1:bc265521eb00 | 313 | |
Davidroid | 1:bc265521eb00 | 314 | /** |
Davidroid | 1:bc265521eb00 | 315 | * @} |
Davidroid | 1:bc265521eb00 | 316 | */ |
Davidroid | 1:bc265521eb00 | 317 | |
Davidroid | 1:bc265521eb00 | 318 | /** |
Davidroid | 1:bc265521eb00 | 319 | * @} |
Davidroid | 1:bc265521eb00 | 320 | */ |
Davidroid | 1:bc265521eb00 | 321 | |
Davidroid | 1:bc265521eb00 | 322 | |
Davidroid | 1:bc265521eb00 | 323 | /** @defgroup MotorControl_Board_Linked_Functions MotorControl Board Linked Functions |
Davidroid | 1:bc265521eb00 | 324 | * @{ |
Davidroid | 1:bc265521eb00 | 325 | */ |
Davidroid | 1:bc265521eb00 | 326 | /* ACTION --------------------------------------------------------------------* |
Davidroid | 1:bc265521eb00 | 327 | * Declare here extern I/O and interrupt related functions you might need, * |
Davidroid | 1:bc265521eb00 | 328 | * and implemented then in a glue logic file on the target environment, for * |
Davidroid | 1:bc265521eb00 | 329 | * example within the "x_nucleo_board.c" file., e.g.: * |
Davidroid | 1:bc265521eb00 | 330 | * extern status_t COMPONENT_IO_Init (void *handle); * |
Davidroid | 1:bc265521eb00 | 331 | * extern status_t COMPONENT_IO_Read (handle, buf, regadd, bytes); * |
Davidroid | 1:bc265521eb00 | 332 | * extern status_t COMPONENT_IO_Write(handle, buf, regadd, bytes); * |
Davidroid | 1:bc265521eb00 | 333 | * extern void COMPONENT_IO_ITConfig(void); * |
Davidroid | 1:bc265521eb00 | 334 | *----------------------------------------------------------------------------*/ |
Davidroid | 1:bc265521eb00 | 335 | ///Delay of the requested number of milliseconds |
Davidroid | 1:bc265521eb00 | 336 | extern void STSPIN820_Board_Delay(void *handle, uint32_t delay); |
Davidroid | 1:bc265521eb00 | 337 | ///Disable the power bridges (leave the output bridges HiZ) |
Davidroid | 1:bc265521eb00 | 338 | extern void STSPIN820_Board_Disable(void *handle); |
Davidroid | 1:bc265521eb00 | 339 | ///Disable Irq |
Davidroid | 1:bc265521eb00 | 340 | extern void STSPIN820_Board_DisableIrq(void *handle); |
Davidroid | 1:bc265521eb00 | 341 | //Get the EN FAULT pin state |
Davidroid | 1:bc265521eb00 | 342 | extern uint32_t STSPIN820_Board_EN_AND_FAULT_PIN_GetState(void *handle); |
Davidroid | 1:bc265521eb00 | 343 | ///Enable the power bridges (leave the output bridges HiZ) |
Davidroid | 1:bc265521eb00 | 344 | extern void STSPIN820_Board_Enable(void *handle); |
Davidroid | 1:bc265521eb00 | 345 | ///Enable Irq |
Davidroid | 1:bc265521eb00 | 346 | extern void STSPIN820_Board_EnableIrq(void *handle); |
Davidroid | 1:bc265521eb00 | 347 | ///Initialise GPIOs used for STSPIN820 |
Davidroid | 1:bc265521eb00 | 348 | extern void STSPIN820_Board_GpioInit(void *handle); |
Davidroid | 1:bc265521eb00 | 349 | ///Init the reference voltage pwm |
Davidroid | 1:bc265521eb00 | 350 | extern void STSPIN820_Board_PwmRefInit(void *handle); |
Davidroid | 1:bc265521eb00 | 351 | ///Set the frequency and duty cycle of PWM used for the reference voltage generation |
Davidroid | 1:bc265521eb00 | 352 | extern void STSPIN820_Board_PwmRefSetFreqAndDutyCycle(void *handle, uint32_t newFreq, uint8_t dutyCycle); |
Davidroid | 1:bc265521eb00 | 353 | ///Start the reference voltage pwm |
Davidroid | 1:bc265521eb00 | 354 | extern void STSPIN820_Board_PwmRefStart(void *handle); |
Davidroid | 1:bc265521eb00 | 355 | ///Stop the reference voltage pwm |
Davidroid | 1:bc265521eb00 | 356 | extern void STSPIN820_Board_PwmRefStop(void *handle); |
Davidroid | 1:bc265521eb00 | 357 | ///Reset the STSPIN820 reset pin |
Davidroid | 1:bc265521eb00 | 358 | extern void STSPIN820_Board_ReleaseReset(void *handle); |
Davidroid | 1:bc265521eb00 | 359 | ///Set the STSPIN820 reset pin |
Davidroid | 1:bc265521eb00 | 360 | extern void STSPIN820_Board_Reset(void *handle); |
Davidroid | 1:bc265521eb00 | 361 | ///Set decay GPIO |
Davidroid | 1:bc265521eb00 | 362 | extern void STSPIN820_Board_SetDecayGpio(void *handle, uint8_t gpioState); |
Davidroid | 1:bc265521eb00 | 363 | ///Get decay GPIO |
Davidroid | 1:bc265521eb00 | 364 | extern uint8_t STSPIN820_Board_GetDecayGpio(void *handle); |
Davidroid | 1:bc265521eb00 | 365 | ///Set direction GPIO |
Davidroid | 1:bc265521eb00 | 366 | extern void STSPIN820_Board_SetDirectionGpio(void *handle, uint8_t gpioState); |
Davidroid | 1:bc265521eb00 | 367 | ///Select Full Step mode |
Davidroid | 1:bc265521eb00 | 368 | extern void STSPIN820_Board_SetFullStep(void *handle); |
Davidroid | 1:bc265521eb00 | 369 | ///Select the STSPIN820 mode1, mode2, and mode3 pins levels |
Davidroid | 1:bc265521eb00 | 370 | extern bool STSPIN820_Board_SetModePins(void *handle, uint8_t modePin1Level, uint8_t modePin2Level, uint8_t modePin3Level); |
Davidroid | 1:bc265521eb00 | 371 | ///Step clock compare value initialization |
Davidroid | 1:bc265521eb00 | 372 | extern void STSPIN820_Board_TimStckCompareInit(void *handle); |
Davidroid | 1:bc265521eb00 | 373 | ///DeInit the timer |
Davidroid | 1:bc265521eb00 | 374 | extern void STSPIN820_Board_TimStckDeInit(void *handle); |
Davidroid | 1:bc265521eb00 | 375 | ///Init the timer |
Davidroid | 1:bc265521eb00 | 376 | extern void STSPIN820_Board_TimStckInit(void *handle); |
Davidroid | 1:bc265521eb00 | 377 | ///Set step clock frequency |
Davidroid | 1:bc265521eb00 | 378 | extern void STSPIN820_Board_TimStckSetFreq(void *handle, uint16_t newFreq); |
Davidroid | 1:bc265521eb00 | 379 | ///Start step clock |
Davidroid | 1:bc265521eb00 | 380 | extern void STSPIN820_Board_TimStckStart(void *handle); |
Davidroid | 1:bc265521eb00 | 381 | ///Stop the timer |
Davidroid | 1:bc265521eb00 | 382 | extern uint8_t STSPIN820_Board_TimStckStop(void *handle, uint8_t *pToggleOdd); |
Davidroid | 1:bc265521eb00 | 383 | ///Unselect Full Step mode |
Davidroid | 1:bc265521eb00 | 384 | extern void STSPIN820_Board_UnsetFullStep(void *handle); |
Davidroid | 1:bc265521eb00 | 385 | /** |
Davidroid | 1:bc265521eb00 | 386 | * @} |
Davidroid | 1:bc265521eb00 | 387 | */ |
Davidroid | 1:bc265521eb00 | 388 | |
Davidroid | 1:bc265521eb00 | 389 | /** |
Davidroid | 1:bc265521eb00 | 390 | * @} |
Davidroid | 1:bc265521eb00 | 391 | */ |
Davidroid | 1:bc265521eb00 | 392 | |
Davidroid | 1:bc265521eb00 | 393 | /** |
Davidroid | 1:bc265521eb00 | 394 | * @} |
Davidroid | 1:bc265521eb00 | 395 | */ |
Davidroid | 1:bc265521eb00 | 396 | |
Davidroid | 1:bc265521eb00 | 397 | #ifdef __cplusplus |
Davidroid | 1:bc265521eb00 | 398 | } |
Davidroid | 1:bc265521eb00 | 399 | #endif |
Davidroid | 1:bc265521eb00 | 400 | |
Davidroid | 1:bc265521eb00 | 401 | #endif /* #ifndef __STSPIN820_H */ |
Davidroid | 1:bc265521eb00 | 402 | |
Davidroid | 1:bc265521eb00 | 403 | /******************* (C) COPYRIGHT 2017 STMicroelectronics *****END OF FILE****/ |