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.
Fork of X_NUCLEO_IHM02A1 by
l6470.h
00001 /** 00002 ****************************************************************************** 00003 * @file L6470.h 00004 * @date 01/10/2014 12:00:00 00005 * @brief This file contains definitions, exported variables and function 00006 * prototypes related to the L6470. 00007 ****************************************************************************** 00008 * 00009 * COPYRIGHT(c) 2014 STMicroelectronics 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 1. Redistributions of source code must retain the above copyright notice, 00014 * this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright notice, 00016 * this list of conditions and the following disclaimer in the documentation 00017 * and/or other materials provided with the distribution. 00018 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00019 * may be used to endorse or promote products derived from this software 00020 * without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00023 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00024 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00025 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00026 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00027 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00028 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00029 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00030 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00031 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 * 00033 ****************************************************************************** 00034 */ 00035 00036 00037 /* Define to prevent recursive inclusion -------------------------------------*/ 00038 00039 #ifndef __L6470_H 00040 #define __L6470_H 00041 00042 #ifdef __cplusplus 00043 extern "C" { 00044 #endif 00045 00046 00047 /* Includes ------------------------------------------------------------------*/ 00048 00049 #include "../Common/microstepping_motor.h" 00050 00051 00052 /* Definitions ---------------------------------------------------------------*/ 00053 00054 /** @addtogroup BSP 00055 * @{ 00056 */ 00057 00058 /** @addtogroup Components 00059 * @{ 00060 */ 00061 00062 /** @addtogroup L6470 00063 * @{ 00064 */ 00065 00066 /** @defgroup L6470_Exported_Defines L6470_Exported_Defines 00067 * @{ 00068 */ 00069 00070 /** 00071 * @defgroup L6470_Exported_Constants 00072 * @brief L6470 Exported Constants. 00073 * @{ 00074 */ 00075 00076 /** 00077 * @defgroup L6470_Register_Max_Values 00078 * @brief Maximum values for L6470 registers. 00079 * @{ 00080 */ 00081 00082 #define L6470_MAX_POSITION (0x1FFFFF) //!< Max position 00083 #define L6470_MIN_POSITION (-(0x200000)) //!< Min position 00084 #define L6470_POSITION_RANGE ((uint32_t)(L6470_MAX_POSITION - L6470_MIN_POSITION)) //!< Position range 00085 #define L6470_MAX_SPEED (0xFFFFF) //!< max value of SPEED 00086 #define L6470_MAX_ACC (0xFFF) //!< max value of ACC 00087 #define L6470_MAX_DEC (0xFFF) //!< max value of DEC 00088 #define L6470_MAX_MAX_SPEED (0x3FF) //!< max value of MAX_SPEED 00089 #define L6470_MAX_MIN_SPEED (0xFFF) //!< max value of MIN_SPEED 00090 #define L6470_MAX_FS_SPD (0x3FF) //!< max value of FS_SPD 00091 #define L6470_MAX_INT_SPEED (0x3FFF) //!< max value of INT_SPEED 00092 #define L6470_MAX_ST_SLP (0xFF) //!< max value of ST_SLP 00093 #define L6470_MAX_FN_SLP_ACC (0xFF) //!< max value of FN_SLP_ACC 00094 #define L6470_MAX_FN_SLP_DEC (0xFF) //!< max value of FN_SLP_DEC 00095 #define L6470_MAX_OCD_TH (0xF) //!< max value of OCD_TH 00096 #define L6470_MAX_STALL_TH (0x7F) //!< max value of STALL_TH 00097 00098 /** 00099 * @} 00100 */ /* End of L6470_Register_Max_Values */ 00101 00102 #define L6470REGIDSIZE 25 //!< Max number of identifiers of L6470 Registers 00103 #define L6470APPCMDIDSIZE 19 //!< Max number of identifiers of L6470 Application Commands 00104 #define L6470DIRIDSIZE 2 //!< Max number of identifiers of L6470 directions 00105 #define L6470ACTIDSIZE 2 //!< Max number of identifiers of actions to perform about ABS_POS register 00106 #define L6470MAXSPICMDBYTESIZE 4 //!< Max number of byte to send via SPI to perform an application command 00107 #define L6470DAISYCHAINSIZE 2 //!< Max number of identifiers of L6470 in daisy chain configuration 00108 00109 #define L6470_MAX_SPEED_VALUE ((float)15610) //!< max value for the speed in step/s 00110 #define L6470_MAX_ACC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2 00111 #define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2 00112 #define L6470_MAX_DEC_VALUE ((float)59590) //!< max value for the acceleration in step/s^2 00113 00114 #define OCD_TH_STEP ((float)375) //!< Minimum step for OCD_TH register in mAmpere 00115 #define STALL_TH_STEP ((float)31.25) //!< Minimum step for STALL_TH register in mAmpere 00116 00117 #define L6470_ACC_CONV ((float)0.068719) //!< Conversion factor for acceleration value from step/s^2 to the right value 00118 #define L6470_DEC_CONV ((float)0.068719) //!< Conversion factor for deceleration value from step/s^2 to the right value 00119 #define L6470_MAXSPEED_CONV ((float)0.065536) //!< Conversion factor for max speed value from step/s to the right value 00120 #define L6470_MINSPEED_CONV ((float)4.194304) //!< Conversion factor for min speed value from step/s to the right value 00121 #define L6470_SPEED_CONV ((float)67.108864) //!< Conversion factor for speed value from step/s to the right value 00122 00123 00124 /* Types ---------------------------------------------------------------------*/ 00125 00126 /** 00127 * @addtogroup BSP 00128 * @{ 00129 */ 00130 00131 /** 00132 * @addtogroup Components 00133 * @{ 00134 */ 00135 00136 /** 00137 * @defgroup L6470 00138 * @brief Tools to manage the L6470 Stepper Motor Driver. 00139 * @{ 00140 */ 00141 00142 /** 00143 * @defgroup L6470_Exported_Types 00144 * @brief L6470 Exported Types. 00145 * @{ 00146 */ 00147 00148 /** 00149 * @brief The structure to store some features of the L6470 Registers. 00150 */ 00151 typedef struct { 00152 uint8_t Address; //!< Register Address 00153 uint8_t Name[12]; //!< Register Name 00154 uint8_t LengthBit; //!< Register Length in bits 00155 uint8_t LengthByte; //!< Register Length in bytes 00156 uint32_t ResetValue; //!< Register Reset Value 00157 } sL6470_Register_t; 00158 00159 /** 00160 * @brief The structure to store some features of the L6470 Application Commands. 00161 */ 00162 typedef struct { 00163 uint8_t Mnemonic[12]; //!< AppCmd Mnemonic 00164 uint8_t BinaryCode; //!< AppCmd Binary Code 00165 uint8_t NrOfParameters; //!< AppCmd number of needed parameters 00166 } sL6470_ApplicationCommand_t; 00167 00168 /** 00169 * @brief The structure to store some features about the L6470 Motor Direction. 00170 */ 00171 typedef struct { 00172 uint8_t Mnemonic[8]; //!< L6470 Direction Mnemonic 00173 uint8_t BinaryCode; //!< L6470 Direction Binary Code 00174 } sL6470_Direction_t; 00175 00176 /** 00177 * @brief The structure to store some features about the action taken with the L6470 ABS_POS register. 00178 */ 00179 typedef struct { 00180 uint8_t Mnemonic[4]; //!< ACT Mnemonic 00181 uint8_t BinaryCode; //!< ACT Binary Code 00182 } sL6470_ACT_t; 00183 00184 /** 00185 * @brief The structure used to store the identifier of the L6470 application 00186 * command and its the needed parameters. 00187 * @note The data stored into this structure will be used to fill the matrix 00188 * used by SPI to send the command to the L6470. 00189 */ 00190 typedef struct { 00191 eL6470_AppCmdId_t L6470_AppCmdId; //!< The identifier of the actual L6470 Application Command 00192 uint32_t p1; //!< The 1st parameter if needed 00193 uint32_t p2; //!< The 2nd parameter if needed 00194 uint32_t p3; //!< The 3rd parameter if needed 00195 } sL6470_AppCmdPkg_t; 00196 00197 /** 00198 * @} 00199 */ /* End of L6470_Exported_Types */ 00200 00201 /** 00202 * @brief L6470 driver initialization structure definition. 00203 */ 00204 /* ACTION --------------------------------------------------------------------* 00205 * Declare here the component's initialization structure, if any, one * 00206 * variable per line without initialization. * 00207 * * 00208 * Example: * 00209 * typedef struct * 00210 * { * 00211 * int frequency; * 00212 * int update_mode; * 00213 * } COMPONENT_Init_t; * 00214 *----------------------------------------------------------------------------*/ 00215 typedef struct 00216 { 00217 float motorvoltage; //!< motor supply voltage in V 00218 float fullstepsperrevolution; //!< min number of steps per revolution for the motor 00219 float phasecurrent; //!< max motor phase voltage in A 00220 float phasevoltage; //!< max motor phase voltage in V 00221 float speed; //!< motor initial speed [step/s] 00222 float acc; //!< motor acceleration [step/s^2] (comment for infinite acceleration mode) 00223 float dec; //!< motor deceleration [step/s^2] (comment for infinite deceleration mode) 00224 float maxspeed; //!< motor maximum speed [step/s] 00225 float minspeed; //!< motor minimum speed [step/s] 00226 float fsspd; //!< motor full-step speed threshold [step/s] 00227 float kvalhold; //!< holding kval [V] 00228 float kvalrun; //!< constant speed kval [V] 00229 float kvalacc; //!< acceleration starting kval [V] 00230 float kvaldec; //!< deceleration starting kval [V] 00231 float intspeed; //!< intersect speed for bemf compensation curve slope changing [step/s] 00232 float stslp; //!< start slope [s/step] 00233 float fnslpacc; //!< acceleration final slope [s/step] 00234 float fnslpdec; //!< deceleration final slope [s/step] 00235 uint8_t kterm; //!< thermal compensation factor (range [0, 15]) 00236 float ocdth; //!< ocd threshold [ma] (range [375 ma, 6000 ma]) 00237 float stallth; //!< stall threshold [ma] (range [31.25 ma, 4000 ma]) 00238 uint8_t step_sel; //!< step mode selection 00239 uint8_t alarmen; //!< alarm conditions enable 00240 uint16_t config; //!< ic configuration 00241 } L6470_Init_t; 00242 00243 /** 00244 * @brief L6470 driver data structure definition. 00245 */ 00246 /* ACTION --------------------------------------------------------------------* 00247 * Declare here the structure of component's data, if any, one variable per * 00248 * line without initialization. * 00249 * * 00250 * Example: * 00251 * typedef struct * 00252 * { * 00253 * int T0_out; * 00254 * int T1_out; * 00255 * float T0_degC; * 00256 * float T1_degC; * 00257 * } COMPONENT_Data_t; * 00258 *----------------------------------------------------------------------------*/ 00259 typedef struct 00260 { 00261 uint8_t L6470_Id; //!< The L6470 identifier inside the daisy chain 00262 sL6470_Register_t *L6470_Register; //[L6470REGIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Registers (the address, the names, the length in bits, the reset value) 00263 sL6470_ApplicationCommand_t *L6470_ApplicationCommand; //[L6470APPCMDIDSIZE]; //!< Array whose elements are a structure in which store information about the L6470 Application Commands (the mnemonic name, the number of needed parameters, the related funtion to call) 00264 sL6470_Direction_t *L6470_Direction; //[L6470DIRIDSIZE]; //!< The mnemonic names for the L6470 direction 00265 sL6470_ACT_t *L6470_ACT; //[L6470ACTIDSIZE]; //!< Action taken about ABS_POS register 00266 sL6470_AppCmdPkg_t L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; //!< To store the identifier of the actual L6470 application command and its the needed parameters 00267 uint8_t L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the command data that are going to be sent by SPI to the L6470 daisy chain 00268 uint8_t L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; //!< To store the matrix that contains the received data by SPI from the L6470 daisy chain 00269 eFlagStatus_t L6470_DaisyChain_HalfPrepared; /* = ZERO_F; */ //!< Boolean variable used when more than one L6470 into the daisy chain is going to be addressed for commanding 00270 sL6470_StatusRegister_t L6470_StatusRegister; //!< To store the received L6470_StatusRegister 00271 sL6470_StatusRegister_t *pL6470_StatusRegister; /* = &L6470_StatusRegister; */ //!< Pointer to the L6470_StatusRegister variable 00272 } L6470_Data_t; 00273 00274 00275 /* Functions -----------------------------------------------------------------*/ 00276 00277 /** @addtogroup BSP 00278 * @{ 00279 */ 00280 00281 /** @addtogroup Components 00282 * @{ 00283 */ 00284 00285 /** @addtogroup L6470 00286 * @{ 00287 */ 00288 00289 /** @defgroup L6470_Imported_Functions L6470_Imported_Functions 00290 * @{ 00291 */ 00292 00293 /* ACTION --------------------------------------------------------------------* 00294 * Declare here extern platform-dependent APIs you might need (e.g.: I/O and * 00295 * interrupt related functions), and implement them in a glue-logic file on * 00296 * the target environment, for example within the "x_nucleo_board.c" file. * 00297 * E.g.: * 00298 * extern Status_t COMPONENT_IO_Init (void *handle); * 00299 * extern Status_t COMPONENT_IO_Read (handle, buf, regadd, bytes); * 00300 * extern Status_t COMPONENT_IO_Write(handle, buf, regadd, bytes); * 00301 * extern void COMPONENT_IO_ITConfig(void); * 00302 *----------------------------------------------------------------------------*/ 00303 extern void L6470_DISABLE(void); 00304 extern void L6470_ENABLE(void); 00305 extern void L6470_nCS_LOW(void); 00306 extern void L6470_nCS_HIGH(void); 00307 extern void L6470_SPI_Communication(uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout); 00308 00309 #ifdef __cplusplus 00310 } 00311 #endif 00312 00313 #endif /* __L6470_H */ 00314 00315 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Jul 14 2022 03:27:23 by
1.7.2
