Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the L6474 component.

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

Dependents:   Stepper_Matlab_Control SunTracker_BLE Stepper_Matlab_Control MemsMotorControl ... more

Fork of X_NUCLEO_IHM01A1 by ST Expansion SW Team

Motor Control Library

Introduction

Library to handle the X-NUCLEO-IHM01A1 Motor Control Expansion Board based on the the L6474 component.

Daisy-Chain Configuration

This board can be stacked up to three times so that the L6474 components will be connected in daisy-chain configuration. For this purpose, some resistors must be correctly connected on the boards as depicted here below:

/media/uploads/Davidroid/daisychaintable.png

Platform compatibility

  • NUCLEO boards have been tested with the default configuration provided by the HelloWorld_IHM01A1 example.
  • LPCXpresso11U68 board has been tested with the following patch:
    • to connect with a wire from the LPCX’s D4 pin to the IHM01A1’s D9 pin;
    • to initialize the pwm PinName variable with D4 rather than D9.
  • FRDM-K64F board has been tested with the following patch:
    • to connect with a wire from the FRDM’s D4 pin to the IHM01A1’s D8 pin;
    • to initialize the standby_reset PinName variable with D4 rather than D8.

Example Applications

Committer:
Davidroid
Date:
Mon Nov 23 11:10:54 2015 +0000
Revision:
8:42e0b00b1e4d
Parent:
5:d3c78f12a78d
Child:
18:2d6ab2b93685
+ Doxygen documentation completed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:2887415a46cd 1 /**
Davidroid 0:2887415a46cd 2 ******************************************************************************
Davidroid 0:2887415a46cd 3 * @file l6474.h
Davidroid 0:2887415a46cd 4 * @author IPC Rennes
Davidroid 0:2887415a46cd 5 * @version V1.5.0
Davidroid 0:2887415a46cd 6 * @date November 12, 2014
Davidroid 0:2887415a46cd 7 * @brief Header for L6474 driver (fully integrated microstepping motor driver)
Davidroid 0:2887415a46cd 8 * @note (C) COPYRIGHT 2014 STMicroelectronics
Davidroid 0:2887415a46cd 9 ******************************************************************************
Davidroid 0:2887415a46cd 10 * @attention
Davidroid 0:2887415a46cd 11 *
Davidroid 0:2887415a46cd 12 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
Davidroid 0:2887415a46cd 13 *
Davidroid 0:2887415a46cd 14 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:2887415a46cd 15 * are permitted provided that the following conditions are met:
Davidroid 0:2887415a46cd 16 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:2887415a46cd 17 * this list of conditions and the following disclaimer.
Davidroid 0:2887415a46cd 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:2887415a46cd 19 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:2887415a46cd 20 * and/or other materials provided with the distribution.
Davidroid 0:2887415a46cd 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:2887415a46cd 22 * may be used to endorse or promote products derived from this software
Davidroid 0:2887415a46cd 23 * without specific prior written permission.
Davidroid 0:2887415a46cd 24 *
Davidroid 0:2887415a46cd 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:2887415a46cd 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:2887415a46cd 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:2887415a46cd 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:2887415a46cd 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:2887415a46cd 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:2887415a46cd 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:2887415a46cd 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:2887415a46cd 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:2887415a46cd 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:2887415a46cd 35 *
Davidroid 0:2887415a46cd 36 ******************************************************************************
Davidroid 0:2887415a46cd 37 */
Davidroid 0:2887415a46cd 38
Davidroid 0:2887415a46cd 39 /* Define to prevent recursive inclusion -------------------------------------*/
Davidroid 0:2887415a46cd 40 #ifndef __L6474_H
Davidroid 0:2887415a46cd 41 #define __L6474_H
Davidroid 0:2887415a46cd 42
Davidroid 0:2887415a46cd 43 #ifdef __cplusplus
Davidroid 0:2887415a46cd 44 extern "C" {
Davidroid 0:2887415a46cd 45 #endif
Davidroid 0:2887415a46cd 46
Davidroid 0:2887415a46cd 47 /* Includes ------------------------------------------------------------------*/
Davidroid 0:2887415a46cd 48 #include "l6474_target_config.h"
Davidroid 0:2887415a46cd 49 #include "../Common/motor.h"
Davidroid 0:2887415a46cd 50
Davidroid 0:2887415a46cd 51 /** @addtogroup BSP
Davidroid 0:2887415a46cd 52 * @{
Davidroid 0:2887415a46cd 53 */
Davidroid 0:2887415a46cd 54
Davidroid 0:2887415a46cd 55 /** @addtogroup L6474
Davidroid 0:2887415a46cd 56 * @{
Davidroid 0:2887415a46cd 57 */
Davidroid 0:2887415a46cd 58
Davidroid 0:2887415a46cd 59 /* Exported Constants --------------------------------------------------------*/
Davidroid 0:2887415a46cd 60
Davidroid 0:2887415a46cd 61 /** @defgroup L6474_Exported_Constants
Davidroid 0:2887415a46cd 62 * @{
Davidroid 0:2887415a46cd 63 */
Davidroid 0:2887415a46cd 64
Davidroid 0:2887415a46cd 65 /// Current FW version
Davidroid 8:42e0b00b1e4d 66 #define L6474_FW_VERSION (5)
Davidroid 0:2887415a46cd 67
Davidroid 0:2887415a46cd 68 /// L6474 max number of bytes of command & arguments to set a parameter
Davidroid 0:2887415a46cd 69 #define L6474_CMD_ARG_MAX_NB_BYTES (4)
Davidroid 0:2887415a46cd 70
Davidroid 0:2887415a46cd 71 /// L6474 command + argument bytes number for GET_STATUS command
Davidroid 0:2887415a46cd 72 #define L6474_CMD_ARG_NB_BYTES_GET_STATUS (1)
Davidroid 0:2887415a46cd 73
Davidroid 0:2887415a46cd 74 /// L6474 response bytes number
Davidroid 0:2887415a46cd 75 #define L6474_RSP_NB_BYTES_GET_STATUS (2)
Davidroid 0:2887415a46cd 76
Davidroid 0:2887415a46cd 77 /// L6474 value mask for ABS_POS register
Davidroid 0:2887415a46cd 78 #define L6474_ABS_POS_VALUE_MASK ((uint32_t) 0x003FFFFF)
Davidroid 0:2887415a46cd 79
Davidroid 0:2887415a46cd 80 /// L6474 sign bit mask for ABS_POS register
Davidroid 0:2887415a46cd 81 #define L6474_ABS_POS_SIGN_BIT_MASK ((uint32_t) 0x00200000)
Davidroid 0:2887415a46cd 82
Davidroid 0:2887415a46cd 83 /**
Davidroid 0:2887415a46cd 84 * @}
Davidroid 0:2887415a46cd 85 */
Davidroid 0:2887415a46cd 86
Davidroid 0:2887415a46cd 87 /**
Davidroid 0:2887415a46cd 88 * @}
Davidroid 0:2887415a46cd 89 */
Davidroid 0:2887415a46cd 90
Davidroid 0:2887415a46cd 91 /* Exported Types -------------------------------------------------------*/
Davidroid 0:2887415a46cd 92
Davidroid 0:2887415a46cd 93 /** @defgroup L6474_Exported_Types
Davidroid 0:2887415a46cd 94 * @{
Davidroid 0:2887415a46cd 95 */
Davidroid 0:2887415a46cd 96
Davidroid 0:2887415a46cd 97 /** @defgroup L6474_Fast_Decay_Time_Options
Davidroid 0:2887415a46cd 98 * @{
Davidroid 0:2887415a46cd 99 */
Davidroid 0:2887415a46cd 100 ///TOFF_FAST values for T_FAST register
Davidroid 0:2887415a46cd 101 typedef enum {
Davidroid 0:2887415a46cd 102 L6474_TOFF_FAST_2us = ((uint8_t) 0x00 << 4),
Davidroid 0:2887415a46cd 103 L6474_TOFF_FAST_4us = ((uint8_t) 0x01 << 4),
Davidroid 0:2887415a46cd 104 L6474_TOFF_FAST_6us = ((uint8_t) 0x02 << 4),
Davidroid 0:2887415a46cd 105 L6474_TOFF_FAST_8us = ((uint8_t) 0x03 << 4),
Davidroid 0:2887415a46cd 106 L6474_TOFF_FAST_10us = ((uint8_t) 0x04 << 4),
Davidroid 0:2887415a46cd 107 L6474_TOFF_FAST_12us = ((uint8_t) 0x05 << 4),
Davidroid 0:2887415a46cd 108 L6474_TOFF_FAST_14us = ((uint8_t) 0x06 << 4),
Davidroid 0:2887415a46cd 109 L6474_TOFF_FAST_16us = ((uint8_t) 0x07 << 4),
Davidroid 0:2887415a46cd 110 L6474_TOFF_FAST_18us = ((uint8_t) 0x08 << 4),
Davidroid 0:2887415a46cd 111 L6474_TOFF_FAST_20us = ((uint8_t) 0x09 << 4),
Davidroid 0:2887415a46cd 112 L6474_TOFF_FAST_22us = ((uint8_t) 0x0A << 4),
Davidroid 0:2887415a46cd 113 L6474_TOFF_FAST_24us = ((uint8_t) 0x0B << 4),
Davidroid 0:2887415a46cd 114 L6474_TOFF_FAST_26us = ((uint8_t) 0x0C << 4),
Davidroid 0:2887415a46cd 115 L6474_TOFF_FAST_28us = ((uint8_t) 0x0D << 4),
Davidroid 0:2887415a46cd 116 L6474_TOFF_FAST_30us = ((uint8_t) 0x0E << 4),
Davidroid 0:2887415a46cd 117 L6474_TOFF_FAST_32us = ((uint8_t) 0x0F << 4)
Davidroid 0:2887415a46cd 118 } L6474_TOFF_FAST_t;
Davidroid 0:2887415a46cd 119 /**
Davidroid 0:2887415a46cd 120 * @}
Davidroid 0:2887415a46cd 121 */
Davidroid 0:2887415a46cd 122
Davidroid 0:2887415a46cd 123 /** @defgroup L6474_Fall_Step_Time_Options
Davidroid 0:2887415a46cd 124 * @{
Davidroid 0:2887415a46cd 125 */
Davidroid 0:2887415a46cd 126 ///FAST_STEP values for T_FAST register
Davidroid 0:2887415a46cd 127 typedef enum {
Davidroid 0:2887415a46cd 128 L6474_FAST_STEP_2us = ((uint8_t) 0x00),
Davidroid 0:2887415a46cd 129 L6474_FAST_STEP_4us = ((uint8_t) 0x01),
Davidroid 0:2887415a46cd 130 L6474_FAST_STEP_6us = ((uint8_t) 0x02),
Davidroid 0:2887415a46cd 131 L6474_FAST_STEP_8us = ((uint8_t) 0x03),
Davidroid 0:2887415a46cd 132 L6474_FAST_STEP_10us = ((uint8_t) 0x04),
Davidroid 0:2887415a46cd 133 L6474_FAST_STEP_12us = ((uint8_t) 0x05),
Davidroid 0:2887415a46cd 134 L6474_FAST_STEP_14us = ((uint8_t) 0x06),
Davidroid 0:2887415a46cd 135 L6474_FAST_STEP_16us = ((uint8_t) 0x07),
Davidroid 0:2887415a46cd 136 L6474_FAST_STEP_18us = ((uint8_t) 0x08),
Davidroid 0:2887415a46cd 137 L6474_FAST_STEP_20us = ((uint8_t) 0x09),
Davidroid 0:2887415a46cd 138 L6474_FAST_STEP_22us = ((uint8_t) 0x0A),
Davidroid 0:2887415a46cd 139 L6474_FAST_STEP_24us = ((uint8_t) 0x0B),
Davidroid 0:2887415a46cd 140 L6474_FAST_STEP_26us = ((uint8_t) 0x0C),
Davidroid 0:2887415a46cd 141 L6474_FAST_STEP_28us = ((uint8_t) 0x0D),
Davidroid 0:2887415a46cd 142 L6474_FAST_STEP_30us = ((uint8_t) 0x0E),
Davidroid 0:2887415a46cd 143 L6474_FAST_STEP_32us = ((uint8_t) 0x0F)
Davidroid 0:2887415a46cd 144 } L6474_FAST_STEP_t;
Davidroid 0:2887415a46cd 145 /**
Davidroid 0:2887415a46cd 146 * @}
Davidroid 0:2887415a46cd 147 */
Davidroid 0:2887415a46cd 148
Davidroid 0:2887415a46cd 149 /** @defgroup L6474_Overcurrent_Threshold_options
Davidroid 0:2887415a46cd 150 * @{
Davidroid 0:2887415a46cd 151 */
Davidroid 0:2887415a46cd 152 ///OCD_TH register
Davidroid 0:2887415a46cd 153 typedef enum {
Davidroid 0:2887415a46cd 154 L6474_OCD_TH_375mA = ((uint8_t) 0x00),
Davidroid 0:2887415a46cd 155 L6474_OCD_TH_750mA = ((uint8_t) 0x01),
Davidroid 0:2887415a46cd 156 L6474_OCD_TH_1125mA = ((uint8_t) 0x02),
Davidroid 0:2887415a46cd 157 L6474_OCD_TH_1500mA = ((uint8_t) 0x03),
Davidroid 0:2887415a46cd 158 L6474_OCD_TH_1875mA = ((uint8_t) 0x04),
Davidroid 0:2887415a46cd 159 L6474_OCD_TH_2250mA = ((uint8_t) 0x05),
Davidroid 0:2887415a46cd 160 L6474_OCD_TH_2625mA = ((uint8_t) 0x06),
Davidroid 0:2887415a46cd 161 L6474_OCD_TH_3000mA = ((uint8_t) 0x07),
Davidroid 0:2887415a46cd 162 L6474_OCD_TH_3375mA = ((uint8_t) 0x08),
Davidroid 0:2887415a46cd 163 L6474_OCD_TH_3750mA = ((uint8_t) 0x09),
Davidroid 0:2887415a46cd 164 L6474_OCD_TH_4125mA = ((uint8_t) 0x0A),
Davidroid 0:2887415a46cd 165 L6474_OCD_TH_4500mA = ((uint8_t) 0x0B),
Davidroid 0:2887415a46cd 166 L6474_OCD_TH_4875mA = ((uint8_t) 0x0C),
Davidroid 0:2887415a46cd 167 L6474_OCD_TH_5250mA = ((uint8_t) 0x0D),
Davidroid 0:2887415a46cd 168 L6474_OCD_TH_5625mA = ((uint8_t) 0x0E),
Davidroid 0:2887415a46cd 169 L6474_OCD_TH_6000mA = ((uint8_t) 0x0F)
Davidroid 0:2887415a46cd 170 } L6474_OCD_TH_t;
Davidroid 0:2887415a46cd 171 /**
Davidroid 0:2887415a46cd 172 * @}
Davidroid 0:2887415a46cd 173 */
Davidroid 0:2887415a46cd 174
Davidroid 0:2887415a46cd 175 /** @defgroup L6474_STEP_MODE_Register_Masks
Davidroid 0:2887415a46cd 176 * @{
Davidroid 0:2887415a46cd 177 */
Davidroid 0:2887415a46cd 178 ///STEP_MODE register
Davidroid 0:2887415a46cd 179 typedef enum {
Davidroid 0:2887415a46cd 180 L6474_STEP_MODE_STEP_SEL = ((uint8_t) 0x07),
Davidroid 0:2887415a46cd 181 L6474_STEP_MODE_SYNC_SEL = ((uint8_t) 0x70)
Davidroid 0:2887415a46cd 182 } L6474_STEP_MODE_Masks_t;
Davidroid 0:2887415a46cd 183 /**
Davidroid 0:2887415a46cd 184 * @}
Davidroid 0:2887415a46cd 185 */
Davidroid 0:2887415a46cd 186
Davidroid 0:2887415a46cd 187 /** @defgroup L6474_STEP_SEL_Options_For_STEP_MODE_Register
Davidroid 0:2887415a46cd 188 * @{
Davidroid 0:2887415a46cd 189 */
Davidroid 0:2887415a46cd 190 ///STEP_SEL field of STEP_MODE register
Davidroid 0:2887415a46cd 191 typedef enum {
Davidroid 0:2887415a46cd 192 L6474_STEP_SEL_1 = ((uint8_t) 0x08), //full step
Davidroid 0:2887415a46cd 193 L6474_STEP_SEL_1_2 = ((uint8_t) 0x09), //half step
Davidroid 0:2887415a46cd 194 L6474_STEP_SEL_1_4 = ((uint8_t) 0x0A), //1/4 microstep
Davidroid 0:2887415a46cd 195 L6474_STEP_SEL_1_8 = ((uint8_t) 0x0B), //1/8 microstep
Davidroid 0:2887415a46cd 196 L6474_STEP_SEL_1_16 = ((uint8_t) 0x0C) //1/16 microstep
Davidroid 0:2887415a46cd 197 } L6474_STEP_SEL_t;
Davidroid 0:2887415a46cd 198 /**
Davidroid 0:2887415a46cd 199 * @}
Davidroid 0:2887415a46cd 200 */
Davidroid 0:2887415a46cd 201
Davidroid 0:2887415a46cd 202 /** @defgroup L6474_SYNC_SEL_Options_For_STEP_MODE_Register
Davidroid 0:2887415a46cd 203 * @{
Davidroid 0:2887415a46cd 204 */
Davidroid 0:2887415a46cd 205 ///SYNC_SEL field of STEP_MODE register
Davidroid 0:2887415a46cd 206 typedef enum {
Davidroid 0:2887415a46cd 207 L6474_SYNC_SEL_1_2 = ((uint8_t) 0x80),
Davidroid 0:2887415a46cd 208 L6474_SYNC_SEL_1 = ((uint8_t) 0x90),
Davidroid 0:2887415a46cd 209 L6474_SYNC_SEL_2 = ((uint8_t) 0xA0),
Davidroid 0:2887415a46cd 210 L6474_SYNC_SEL_4 = ((uint8_t) 0xB0),
Davidroid 0:2887415a46cd 211 L6474_SYNC_SEL_8 = ((uint8_t) 0xC0),
Davidroid 0:2887415a46cd 212 L6474_SYNC_SEL_UNUSED = ((uint8_t) 0xD0)
Davidroid 0:2887415a46cd 213 } L6474_SYNC_SEL_t;
Davidroid 0:2887415a46cd 214 /**
Davidroid 0:2887415a46cd 215 * @}
Davidroid 0:2887415a46cd 216 */
Davidroid 0:2887415a46cd 217
Davidroid 0:2887415a46cd 218 /** @defgroup L6474_ALARM_EN_Register_Options
Davidroid 0:2887415a46cd 219 * @{
Davidroid 0:2887415a46cd 220 */
Davidroid 0:2887415a46cd 221 ///ALARM_EN register
Davidroid 0:2887415a46cd 222 typedef enum {
Davidroid 0:2887415a46cd 223 L6474_ALARM_EN_OVERCURRENT = ((uint8_t) 0x01),
Davidroid 0:2887415a46cd 224 L6474_ALARM_EN_THERMAL_SHUTDOWN = ((uint8_t) 0x02),
Davidroid 0:2887415a46cd 225 L6474_ALARM_EN_THERMAL_WARNING = ((uint8_t) 0x04),
Davidroid 0:2887415a46cd 226 L6474_ALARM_EN_UNDERVOLTAGE = ((uint8_t) 0x08),
Davidroid 0:2887415a46cd 227 L6474_ALARM_EN_SW_TURN_ON = ((uint8_t) 0x40),
Davidroid 0:2887415a46cd 228 L6474_ALARM_EN_WRONG_NPERF_CMD = ((uint8_t) 0x80)
Davidroid 0:2887415a46cd 229 } L6474_ALARM_EN_t;
Davidroid 0:2887415a46cd 230 /**
Davidroid 0:2887415a46cd 231 * @}
Davidroid 0:2887415a46cd 232 */
Davidroid 0:2887415a46cd 233
Davidroid 0:2887415a46cd 234 /** @defgroup L6474_CONFIG_Register_Masks
Davidroid 0:2887415a46cd 235 * @{
Davidroid 0:2887415a46cd 236 */
Davidroid 0:2887415a46cd 237 ///CONFIG register
Davidroid 0:2887415a46cd 238 typedef enum {
Davidroid 0:2887415a46cd 239 L6474_CONFIG_OSC_SEL = ((uint16_t) 0x0007),
Davidroid 0:2887415a46cd 240 L6474_CONFIG_EXT_CLK = ((uint16_t) 0x0008),
Davidroid 0:2887415a46cd 241 L6474_CONFIG_EN_TQREG = ((uint16_t) 0x0020),
Davidroid 0:2887415a46cd 242 L6474_CONFIG_OC_SD = ((uint16_t) 0x0080),
Davidroid 0:2887415a46cd 243 L6474_CONFIG_POW_SR = ((uint16_t) 0x0300),
Davidroid 0:2887415a46cd 244 L6474_CONFIG_TOFF = ((uint16_t) 0x7C00)
Davidroid 0:2887415a46cd 245 } L6474_CONFIG_Masks_t;
Davidroid 0:2887415a46cd 246 /**
Davidroid 0:2887415a46cd 247 * @}
Davidroid 0:2887415a46cd 248 */
Davidroid 0:2887415a46cd 249
Davidroid 0:2887415a46cd 250 /** @defgroup L6474_Clock_Source_Options_For_CONFIG_Register
Davidroid 0:2887415a46cd 251 * @{
Davidroid 0:2887415a46cd 252 */
Davidroid 0:2887415a46cd 253 ///Clock source option for CONFIG register
Davidroid 0:2887415a46cd 254 typedef enum {
Davidroid 0:2887415a46cd 255 L6474_CONFIG_INT_16MHZ = ((uint16_t) 0x0000),
Davidroid 0:2887415a46cd 256 L6474_CONFIG_INT_16MHZ_OSCOUT_2MHZ = ((uint16_t) 0x0008),
Davidroid 0:2887415a46cd 257 L6474_CONFIG_INT_16MHZ_OSCOUT_4MHZ = ((uint16_t) 0x0009),
Davidroid 0:2887415a46cd 258 L6474_CONFIG_INT_16MHZ_OSCOUT_8MHZ = ((uint16_t) 0x000A),
Davidroid 0:2887415a46cd 259 L6474_CONFIG_INT_16MHZ_OSCOUT_16MHZ = ((uint16_t) 0x000B),
Davidroid 0:2887415a46cd 260 L6474_CONFIG_EXT_8MHZ_XTAL_DRIVE = ((uint16_t) 0x0004),
Davidroid 0:2887415a46cd 261 L6474_CONFIG_EXT_16MHZ_XTAL_DRIVE = ((uint16_t) 0x0005),
Davidroid 0:2887415a46cd 262 L6474_CONFIG_EXT_24MHZ_XTAL_DRIVE = ((uint16_t) 0x0006),
Davidroid 0:2887415a46cd 263 L6474_CONFIG_EXT_32MHZ_XTAL_DRIVE = ((uint16_t) 0x0007),
Davidroid 0:2887415a46cd 264 L6474_CONFIG_EXT_8MHZ_OSCOUT_INVERT = ((uint16_t) 0x000C),
Davidroid 0:2887415a46cd 265 L6474_CONFIG_EXT_16MHZ_OSCOUT_INVERT = ((uint16_t) 0x000D),
Davidroid 0:2887415a46cd 266 L6474_CONFIG_EXT_24MHZ_OSCOUT_INVERT = ((uint16_t) 0x000E),
Davidroid 0:2887415a46cd 267 L6474_CONFIG_EXT_32MHZ_OSCOUT_INVERT = ((uint16_t) 0x000F)
Davidroid 0:2887415a46cd 268 } L6474_CONFIG_OSC_MGMT_t;
Davidroid 0:2887415a46cd 269 /**
Davidroid 0:2887415a46cd 270 * @}
Davidroid 0:2887415a46cd 271 */
Davidroid 0:2887415a46cd 272
Davidroid 0:2887415a46cd 273 /** @defgroup L6474_External_Torque_Regulation_Options_For_CONFIG_Register
Davidroid 0:2887415a46cd 274 * @{
Davidroid 0:2887415a46cd 275 */
Davidroid 0:2887415a46cd 276 ///External Torque regulation options for CONFIG register
Davidroid 0:2887415a46cd 277 typedef enum {
Davidroid 0:2887415a46cd 278 L6474_CONFIG_EN_TQREG_TVAL_USED = ((uint16_t) 0x0000),
Davidroid 0:2887415a46cd 279 L6474_CONFIG_EN_TQREG_ADC_OUT = ((uint16_t) 0x0020)
Davidroid 0:2887415a46cd 280 } L6474_CONFIG_EN_TQREG_t;
Davidroid 0:2887415a46cd 281 /**
Davidroid 0:2887415a46cd 282 * @}
Davidroid 0:2887415a46cd 283 */
Davidroid 0:2887415a46cd 284
Davidroid 0:2887415a46cd 285 /** @defgroup L6474_Over_Current_Shutdown_Options_For_CONFIG_Register
Davidroid 0:2887415a46cd 286 * @{
Davidroid 0:2887415a46cd 287 */
Davidroid 0:2887415a46cd 288 ///Over Current Shutdown options for CONFIG register
Davidroid 0:2887415a46cd 289 typedef enum {
Davidroid 0:2887415a46cd 290 L6474_CONFIG_OC_SD_DISABLE = ((uint16_t) 0x0000),
Davidroid 0:2887415a46cd 291 L6474_CONFIG_OC_SD_ENABLE = ((uint16_t) 0x0080)
Davidroid 0:2887415a46cd 292 } L6474_CONFIG_OC_SD_t;
Davidroid 0:2887415a46cd 293 /**
Davidroid 0:2887415a46cd 294 * @}
Davidroid 0:2887415a46cd 295 */
Davidroid 0:2887415a46cd 296
Davidroid 0:2887415a46cd 297 /** @defgroup L6474_Power_Bridge_Output_Slew_Rate_Options
Davidroid 0:2887415a46cd 298 * @{
Davidroid 0:2887415a46cd 299 */
Davidroid 0:2887415a46cd 300 /// POW_SR values for CONFIG register
Davidroid 0:2887415a46cd 301 typedef enum {
Davidroid 0:2887415a46cd 302 L6474_CONFIG_SR_320V_us =((uint16_t)0x0000),
Davidroid 0:2887415a46cd 303 L6474_CONFIG_SR_075V_us =((uint16_t)0x0100),
Davidroid 0:2887415a46cd 304 L6474_CONFIG_SR_110V_us =((uint16_t)0x0200),
Davidroid 0:2887415a46cd 305 L6474_CONFIG_SR_260V_us =((uint16_t)0x0300)
Davidroid 0:2887415a46cd 306 } L6474_CONFIG_POW_SR_t;
Davidroid 0:2887415a46cd 307 /**
Davidroid 0:2887415a46cd 308 * @}
Davidroid 0:2887415a46cd 309 */
Davidroid 0:2887415a46cd 310
Davidroid 0:2887415a46cd 311 /** @defgroup L6474_Off_Time_Options
Davidroid 0:2887415a46cd 312 * @{
Davidroid 0:2887415a46cd 313 */
Davidroid 0:2887415a46cd 314 /// TOFF values for CONFIG register
Davidroid 0:2887415a46cd 315 typedef enum {
Davidroid 0:2887415a46cd 316 L6474_CONFIG_TOFF_004us = (((uint16_t) 0x01) << 10),
Davidroid 0:2887415a46cd 317 L6474_CONFIG_TOFF_008us = (((uint16_t) 0x02) << 10),
Davidroid 0:2887415a46cd 318 L6474_CONFIG_TOFF_012us = (((uint16_t) 0x03) << 10),
Davidroid 0:2887415a46cd 319 L6474_CONFIG_TOFF_016us = (((uint16_t) 0x04) << 10),
Davidroid 0:2887415a46cd 320 L6474_CONFIG_TOFF_020us = (((uint16_t) 0x05) << 10),
Davidroid 0:2887415a46cd 321 L6474_CONFIG_TOFF_024us = (((uint16_t) 0x06) << 10),
Davidroid 0:2887415a46cd 322 L6474_CONFIG_TOFF_028us = (((uint16_t) 0x07) << 10),
Davidroid 0:2887415a46cd 323 L6474_CONFIG_TOFF_032us = (((uint16_t) 0x08) << 10),
Davidroid 0:2887415a46cd 324 L6474_CONFIG_TOFF_036us = (((uint16_t) 0x09) << 10),
Davidroid 0:2887415a46cd 325 L6474_CONFIG_TOFF_040us = (((uint16_t) 0x0A) << 10),
Davidroid 0:2887415a46cd 326 L6474_CONFIG_TOFF_044us = (((uint16_t) 0x0B) << 10),
Davidroid 0:2887415a46cd 327 L6474_CONFIG_TOFF_048us = (((uint16_t) 0x0C) << 10),
Davidroid 0:2887415a46cd 328 L6474_CONFIG_TOFF_052us = (((uint16_t) 0x0D) << 10),
Davidroid 0:2887415a46cd 329 L6474_CONFIG_TOFF_056us = (((uint16_t) 0x0E) << 10),
Davidroid 0:2887415a46cd 330 L6474_CONFIG_TOFF_060us = (((uint16_t) 0x0F) << 10),
Davidroid 0:2887415a46cd 331 L6474_CONFIG_TOFF_064us = (((uint16_t) 0x10) << 10),
Davidroid 0:2887415a46cd 332 L6474_CONFIG_TOFF_068us = (((uint16_t) 0x11) << 10),
Davidroid 0:2887415a46cd 333 L6474_CONFIG_TOFF_072us = (((uint16_t) 0x12) << 10),
Davidroid 0:2887415a46cd 334 L6474_CONFIG_TOFF_076us = (((uint16_t) 0x13) << 10),
Davidroid 0:2887415a46cd 335 L6474_CONFIG_TOFF_080us = (((uint16_t) 0x14) << 10),
Davidroid 0:2887415a46cd 336 L6474_CONFIG_TOFF_084us = (((uint16_t) 0x15) << 10),
Davidroid 0:2887415a46cd 337 L6474_CONFIG_TOFF_088us = (((uint16_t) 0x16) << 10),
Davidroid 0:2887415a46cd 338 L6474_CONFIG_TOFF_092us = (((uint16_t) 0x17) << 10),
Davidroid 0:2887415a46cd 339 L6474_CONFIG_TOFF_096us = (((uint16_t) 0x18) << 10),
Davidroid 0:2887415a46cd 340 L6474_CONFIG_TOFF_100us = (((uint16_t) 0x19) << 10),
Davidroid 0:2887415a46cd 341 L6474_CONFIG_TOFF_104us = (((uint16_t) 0x1A) << 10),
Davidroid 0:2887415a46cd 342 L6474_CONFIG_TOFF_108us = (((uint16_t) 0x1B) << 10),
Davidroid 0:2887415a46cd 343 L6474_CONFIG_TOFF_112us = (((uint16_t) 0x1C) << 10),
Davidroid 0:2887415a46cd 344 L6474_CONFIG_TOFF_116us = (((uint16_t) 0x1D) << 10),
Davidroid 0:2887415a46cd 345 L6474_CONFIG_TOFF_120us = (((uint16_t) 0x1E) << 10),
Davidroid 0:2887415a46cd 346 L6474_CONFIG_TOFF_124us = (((uint16_t) 0x1F) << 10)
Davidroid 0:2887415a46cd 347 } L6474_CONFIG_TOFF_t;
Davidroid 0:2887415a46cd 348 /**
Davidroid 0:2887415a46cd 349 * @}
Davidroid 0:2887415a46cd 350 */
Davidroid 0:2887415a46cd 351
Davidroid 0:2887415a46cd 352 /** @defgroup L6474_STATUS_Register_Bit_Masks
Davidroid 0:2887415a46cd 353 * @{
Davidroid 0:2887415a46cd 354 */
Davidroid 0:2887415a46cd 355 ///STATUS Register Bit Masks
Davidroid 0:2887415a46cd 356 typedef enum {
Davidroid 0:2887415a46cd 357 L6474_STATUS_HIZ = (((uint16_t) 0x0001)),
Davidroid 0:2887415a46cd 358 L6474_STATUS_DIR = (((uint16_t) 0x0010)),
Davidroid 0:2887415a46cd 359 L6474_STATUS_NOTPERF_CMD = (((uint16_t) 0x0080)),
Davidroid 0:2887415a46cd 360 L6474_STATUS_WRONG_CMD = (((uint16_t) 0x0100)),
Davidroid 0:2887415a46cd 361 L6474_STATUS_UVLO = (((uint16_t) 0x0200)),
Davidroid 0:2887415a46cd 362 L6474_STATUS_TH_WRN = (((uint16_t) 0x0400)),
Davidroid 0:2887415a46cd 363 L6474_STATUS_TH_SD = (((uint16_t) 0x0800)),
Davidroid 0:2887415a46cd 364 L6474_STATUS_OCD = (((uint16_t) 0x1000))
Davidroid 0:2887415a46cd 365 } L6474_STATUS_Masks_t;
Davidroid 0:2887415a46cd 366 /**
Davidroid 0:2887415a46cd 367 * @}
Davidroid 0:2887415a46cd 368 */
Davidroid 0:2887415a46cd 369
Davidroid 0:2887415a46cd 370 /** @defgroup L6474_Direction_Field_Of_STATUS_Register
Davidroid 0:2887415a46cd 371 * @{
Davidroid 0:2887415a46cd 372 */
Davidroid 0:2887415a46cd 373 ///Diretion field of STATUS register
Davidroid 0:2887415a46cd 374 typedef enum {
Davidroid 0:2887415a46cd 375 L6474_STATUS_DIR_FORWARD = (((uint16_t) 0x0001) << 4),
Davidroid 0:2887415a46cd 376 L6474_STATUS_DIR_REVERSE = (((uint16_t) 0x0000) << 4)
Davidroid 0:2887415a46cd 377 } L6474_STATUS_DIR_t;
Davidroid 0:2887415a46cd 378 /**
Davidroid 0:2887415a46cd 379 * @}
Davidroid 0:2887415a46cd 380 */
Davidroid 0:2887415a46cd 381
Davidroid 0:2887415a46cd 382 /** @defgroup L6474_Internal_Register_Addresses
Davidroid 0:2887415a46cd 383 * @{
Davidroid 0:2887415a46cd 384 */
Davidroid 0:2887415a46cd 385 /// Internal L6474 register addresses
Davidroid 0:2887415a46cd 386 typedef enum {
Davidroid 0:2887415a46cd 387 L6474_ABS_POS = ((uint8_t) 0x01),
Davidroid 0:2887415a46cd 388 L6474_EL_POS = ((uint8_t) 0x02),
Davidroid 0:2887415a46cd 389 L6474_MARK = ((uint8_t) 0x03),
Davidroid 0:2887415a46cd 390 L6474_RESERVED_REG01 = ((uint8_t) 0x04),
Davidroid 0:2887415a46cd 391 L6474_RESERVED_REG02 = ((uint8_t) 0x05),
Davidroid 0:2887415a46cd 392 L6474_RESERVED_REG03 = ((uint8_t) 0x06),
Davidroid 0:2887415a46cd 393 L6474_RESERVED_REG04 = ((uint8_t) 0x07),
Davidroid 0:2887415a46cd 394 L6474_RESERVED_REG05 = ((uint8_t) 0x08),
Davidroid 0:2887415a46cd 395 L6474_RESERVED_REG06 = ((uint8_t) 0x15),
Davidroid 0:2887415a46cd 396 L6474_TVAL = ((uint8_t) 0x09),
Davidroid 0:2887415a46cd 397 L6474_RESERVED_REG07 = ((uint8_t) 0x0A),
Davidroid 0:2887415a46cd 398 L6474_RESERVED_REG08 = ((uint8_t) 0x0B),
Davidroid 0:2887415a46cd 399 L6474_RESERVED_REG09 = ((uint8_t) 0x0C),
Davidroid 0:2887415a46cd 400 L6474_RESERVED_REG10 = ((uint8_t) 0x0D),
Davidroid 0:2887415a46cd 401 L6474_T_FAST = ((uint8_t) 0x0E),
Davidroid 0:2887415a46cd 402 L6474_TON_MIN = ((uint8_t) 0x0F),
Davidroid 0:2887415a46cd 403 L6474_TOFF_MIN = ((uint8_t) 0x10),
Davidroid 0:2887415a46cd 404 L6474_RESERVED_REG11 = ((uint8_t) 0x11),
Davidroid 0:2887415a46cd 405 L6474_ADC_OUT = ((uint8_t) 0x12),
Davidroid 0:2887415a46cd 406 L6474_OCD_TH = ((uint8_t) 0x13),
Davidroid 0:2887415a46cd 407 L6474_RESERVED_REG12 = ((uint8_t) 0x14),
Davidroid 0:2887415a46cd 408 L6474_STEP_MODE = ((uint8_t) 0x16),
Davidroid 0:2887415a46cd 409 L6474_ALARM_EN = ((uint8_t) 0x17),
Davidroid 0:2887415a46cd 410 L6474_CONFIG = ((uint8_t) 0x18),
Davidroid 0:2887415a46cd 411 L6474_STATUS = ((uint8_t) 0x19),
Davidroid 0:2887415a46cd 412 L6474_RESERVED_REG13 = ((uint8_t) 0x1A),
Davidroid 0:2887415a46cd 413 L6474_RESERVED_REG14 = ((uint8_t) 0x1B),
Davidroid 0:2887415a46cd 414 L6474_INEXISTENT_REG = ((uint8_t) 0x1F)
Davidroid 0:2887415a46cd 415 } L6474_Registers_t;
Davidroid 0:2887415a46cd 416 /**
Davidroid 0:2887415a46cd 417 * @}
Davidroid 0:2887415a46cd 418 */
Davidroid 0:2887415a46cd 419
Davidroid 0:2887415a46cd 420 /** @defgroup L6474_Command_Set
Davidroid 0:2887415a46cd 421 * @{
Davidroid 0:2887415a46cd 422 */
Davidroid 0:2887415a46cd 423 /// L6474 command set
Davidroid 0:2887415a46cd 424 typedef enum {
Davidroid 0:2887415a46cd 425 L6474_NOP = ((uint8_t) 0x00),
Davidroid 0:2887415a46cd 426 L6474_SET_PARAM = ((uint8_t) 0x00),
Davidroid 0:2887415a46cd 427 L6474_GET_PARAM = ((uint8_t) 0x20),
Davidroid 0:2887415a46cd 428 L6474_ENABLE = ((uint8_t) 0xB8),
Davidroid 0:2887415a46cd 429 L6474_DISABLE = ((uint8_t) 0xA8),
Davidroid 0:2887415a46cd 430 L6474_GET_STATUS = ((uint8_t) 0xD0),
Davidroid 0:2887415a46cd 431 L6474_RESERVED_CMD1 = ((uint8_t) 0xEB),
Davidroid 0:2887415a46cd 432 L6474_RESERVED_CMD2 = ((uint8_t) 0xF8)
Davidroid 0:2887415a46cd 433 } L6474_Commands_t;
Davidroid 0:2887415a46cd 434 /**
Davidroid 0:2887415a46cd 435 * @}
Davidroid 0:2887415a46cd 436 */
Davidroid 0:2887415a46cd 437
Davidroid 0:2887415a46cd 438 /**
Davidroid 0:2887415a46cd 439 * @brief L6474 driver data structure definition
Davidroid 0:2887415a46cd 440 */
Davidroid 0:2887415a46cd 441 typedef struct
Davidroid 0:2887415a46cd 442 {
Davidroid 0:2887415a46cd 443 /// Function pointer to flag interrupt call back
Davidroid 0:2887415a46cd 444 void (*flagInterruptCallback)(void);
Davidroid 0:2887415a46cd 445 /// Function pointer to error handler call back
Davidroid 0:2887415a46cd 446 void (*errorHandlerCallback)(uint16_t error);
Davidroid 0:2887415a46cd 447 bool spiPreemtionByIsr; // = FALSE;
Davidroid 0:2887415a46cd 448 bool isrFlag; // = FALSE;
Davidroid 0:2887415a46cd 449 /// L6474 Device Paramaters structure
Davidroid 0:2887415a46cd 450 deviceParams_t devicePrm; //[MAX_NUMBER_OF_DEVICES];
Davidroid 0:2887415a46cd 451 uint8_t numberOfDevices;
Davidroid 0:2887415a46cd 452 uint8_t deviceInstance;
Davidroid 5:d3c78f12a78d 453 uint8_t spiTxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
Davidroid 5:d3c78f12a78d 454 uint8_t spiRxBursts[L6474_CMD_ARG_MAX_NB_BYTES][MAX_NUMBER_OF_DEVICES];
Davidroid 0:2887415a46cd 455 } L6474_DrvDataTypeDef;
Davidroid 0:2887415a46cd 456
Davidroid 0:2887415a46cd 457
Davidroid 1:b38ebb8ea286 458 /* Exported functions --------------------------------------------------------*/
Davidroid 0:2887415a46cd 459
Davidroid 1:b38ebb8ea286 460 /** @defgroup L6474_Exported_Functions
Davidroid 1:b38ebb8ea286 461 * @{
Davidroid 1:b38ebb8ea286 462 */
Davidroid 0:2887415a46cd 463
Davidroid 0:2887415a46cd 464 /* ACTION --------------------------------------------------------------------*
Davidroid 1:b38ebb8ea286 465 * Declare here extern I/O and interrupt related functions you might need, *
Davidroid 1:b38ebb8ea286 466 * and implemented then in a glue logic file on the target environment, for *
Davidroid 1:b38ebb8ea286 467 * example within the "x_nucleo_<board>.c" file., e.g.: *
Davidroid 1:b38ebb8ea286 468 * extern DrvStatusTypeDef COMPONENT_IO_Init (void *handle); *
Davidroid 0:2887415a46cd 469 * extern DrvStatusTypeDef COMPONENT_IO_Read (handle, buf, regadd, bytes); *
Davidroid 0:2887415a46cd 470 * extern DrvStatusTypeDef COMPONENT_IO_Write(handle, buf, regadd, bytes); *
Davidroid 1:b38ebb8ea286 471 * extern void COMPONENT_IO_ITConfig(void); *
Davidroid 0:2887415a46cd 472 *----------------------------------------------------------------------------*/
Davidroid 1:b38ebb8ea286 473 /** @defgroup MotorControl_Board_Linked_Functions
Davidroid 1:b38ebb8ea286 474 * @{
Davidroid 1:b38ebb8ea286 475 */
Davidroid 0:2887415a46cd 476 ///Delay of the requested number of milliseconds
Davidroid 0:2887415a46cd 477 extern void L6474_Delay(void *handle, uint32_t delay);
Davidroid 0:2887415a46cd 478 ///Enable Irq
Davidroid 0:2887415a46cd 479 extern void L6474_EnableIrq(void *handle);
Davidroid 0:2887415a46cd 480 ///Disable Irq
Davidroid 0:2887415a46cd 481 extern void L6474_DisableIrq(void *handle);
Davidroid 0:2887415a46cd 482 ///Set PWM1 frequency and start it
Davidroid 0:2887415a46cd 483 extern void L6474_Pwm1SetFreq(void *handle, uint16_t newFreq);
Davidroid 0:2887415a46cd 484 ///Set PWM2 frequency and start it
Davidroid 0:2887415a46cd 485 extern void L6474_Pwm2SetFreq(void *handle, uint16_t newFreq);
Davidroid 0:2887415a46cd 486 ///Set PWM3 frequency and start it
Davidroid 0:2887415a46cd 487 extern void L6474_Pwm3SetFreq(void *handle, uint16_t newFreq);
Davidroid 0:2887415a46cd 488 ///Init the PWM
Davidroid 0:2887415a46cd 489 extern void L6474_PwmInit(void *handle);
Davidroid 0:2887415a46cd 490 ///Stop the PWM
Davidroid 0:2887415a46cd 491 extern void L6474_PwmStop(void *handle);
Davidroid 0:2887415a46cd 492 ///Reset the L6474 reset pin
Davidroid 0:2887415a46cd 493 extern void L6474_ReleaseReset(void *handle);
Davidroid 0:2887415a46cd 494 ///Set the L6474 reset pin
Davidroid 0:2887415a46cd 495 extern void L6474_Reset(void *handle);
Davidroid 0:2887415a46cd 496 ///Set direction GPIO
Davidroid 0:2887415a46cd 497 extern void L6474_SetDirectionGpio(void *handle, uint8_t gpioState);
Davidroid 0:2887415a46cd 498 ///Write bytes to the L6474s via SPI
Davidroid 0:2887415a46cd 499 extern uint8_t L6474_SpiWriteBytes(void *handle, uint8_t *pByteToTransmit, uint8_t *pReceivedByte);
Davidroid 0:2887415a46cd 500
Davidroid 0:2887415a46cd 501 /**
Davidroid 0:2887415a46cd 502 * @}
Davidroid 0:2887415a46cd 503 */
Davidroid 0:2887415a46cd 504
Davidroid 0:2887415a46cd 505 /**
Davidroid 0:2887415a46cd 506 * @}
Davidroid 0:2887415a46cd 507 */
Davidroid 0:2887415a46cd 508
Davidroid 0:2887415a46cd 509 /**
Davidroid 0:2887415a46cd 510 * @}
Davidroid 0:2887415a46cd 511 */
Davidroid 0:2887415a46cd 512
Davidroid 0:2887415a46cd 513 /**
Davidroid 0:2887415a46cd 514 * @}
Davidroid 0:2887415a46cd 515 */
Davidroid 0:2887415a46cd 516
Davidroid 0:2887415a46cd 517 #ifdef __cplusplus
Davidroid 0:2887415a46cd 518 }
Davidroid 0:2887415a46cd 519 #endif
Davidroid 0:2887415a46cd 520
Davidroid 0:2887415a46cd 521 #endif /* #ifndef __L6474_H */
Davidroid 0:2887415a46cd 522
Davidroid 0:2887415a46cd 523
Davidroid 0:2887415a46cd 524 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/