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: X_NUCLEO_COMMON ST_INTERFACES
Dependents: SpleisserProgramm SpleisserProgramm_v2 SpleisserProgramm_v5 SpleisserProgramm_V7 ... more
L6470.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file l6470_class.cpp 00004 * @date 01/10/2014 12:00:00 00005 * @brief This file provides set of firmware functions to manage the 00006 * 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 /* Generated with STM32CubeTOO -----------------------------------------------*/ 00038 00039 00040 /* Revision ------------------------------------------------------------------*/ 00041 /* 00042 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev 00043 Branch/Trunk/Tag: trunk 00044 Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.c 00045 Revision: 0 00046 */ 00047 00048 00049 /* Includes ------------------------------------------------------------------*/ 00050 00051 #include "L6470.h" 00052 00053 00054 /* Variables -----------------------------------------------------------------*/ 00055 00056 /* Number of instantiated devices on an expansion board. */ 00057 uint8_t L6470::number_of_devices = 0; 00058 00059 /* SPI Transmission for Daisy-Chain Configuration. */ 00060 eFlagStatus_t L6470::L6470_DaisyChain_HalfPrepared; 00061 sL6470_AppCmdPkg_t L6470::L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; 00062 uint8_t L6470::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 00063 uint8_t L6470::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 00064 00065 /////////////////////////////////////////////////////////////////////////////////////////////////////Fabian 00066 uint8_t L6470B::number_of_devices1 = 0; 00067 eFlagStatus_t L6470B::L6470_DaisyChain_HalfPrepared; 00068 sL6470_AppCmdPkg_t L6470B::L6470_AppCmdPkg[L6470DAISYCHAINSIZE]; 00069 uint8_t L6470B::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 00070 uint8_t L6470B::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE]; 00071 00072 //////////////////////////////////////////////////////////////////////////////////////////////////// 00073 00074 00075 /** 00076 * @brief Array whose elements are a structure in which store information about 00077 * the L6470 Registers (the address, the names, the length in bits, the 00078 * reset value) 00079 */ 00080 const sL6470_Register_t L6470::_L6470_Register[L6470REGIDSIZE] = { 00081 {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position 00082 {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position 00083 {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position 00084 {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed 00085 {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration 00086 {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration 00087 {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed 00088 {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed 00089 {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed 00090 {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL 00091 {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL 00092 {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL 00093 {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL 00094 {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed 00095 {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope 00096 {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope 00097 {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope 00098 {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor 00099 {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions) 00100 {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold 00101 {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold 00102 {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode 00103 {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable 00104 {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration 00105 {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions) 00106 }; 00107 00108 /** 00109 * @brief Array whose elements are a structure in which store information about 00110 * the L6470 Application Commands (the mnemonic name, the number of 00111 * needed parameters, the related funtion to call) 00112 */ 00113 const sL6470_ApplicationCommand_t L6470::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = { 00114 {"NOP", 0x00, 0}, 00115 {"SETPARAM", 0x00, 2}, 00116 {"GETPARAM", 0x20, 1}, 00117 {"RUN", 0x50, 2}, 00118 {"STEPCLOCK", 0x58, 1}, 00119 {"MOVE", 0x40, 2}, 00120 {"GOTO", 0x60, 1}, 00121 {"GOTO_DIR", 0x68, 2}, 00122 {"GOUNTIL", 0x82, 3}, 00123 {"RELEASESW", 0x92, 2}, 00124 {"GOHOME", 0x70, 0}, 00125 {"GOMARK", 0x78, 0}, 00126 {"RESETPOS", 0xD8, 0}, 00127 {"RESETDEVICE", 0xC0, 0}, 00128 {"SOFTSTOP", 0xB0, 0}, 00129 {"HARDSTOP", 0xB8, 0}, 00130 {"SOFTHIZ", 0xA0, 0}, 00131 {"HARDHIZ", 0xA8, 0}, 00132 {"GETSTATUS", 0xD0, 0} 00133 }; 00134 00135 /** 00136 * @brief The mnemonic names for the L6470 direction 00137 */ 00138 const sL6470_Direction_t L6470::_L6470_Direction[L6470DIRIDSIZE] = { 00139 {"REV", 0x00}, //!< Reverse direction 00140 {"FWD", 0x01} //!< Forward direction 00141 }; 00142 00143 /** 00144 * @brief Action taken about ABS_POS register 00145 */ 00146 const sL6470_ACT_t L6470::_L6470_ACT[L6470ACTIDSIZE] = { 00147 {"RST", 0x00}, //!< ABS_POS register is reset 00148 {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register 00149 }; 00150 00151 /* End of L6470_Private_Constants */ 00152 00153 /** 00154 * @defgroup L6470_Private_Variables 00155 * @brief L6470 Private Variables. 00156 * @{ 00157 */ 00158 00159 /* End of L6470_Private_Variables */ 00160 00161 00162 /** 00163 * @addtogroup L6470_Private_Functions 00164 * @{ 00165 */ 00166 00167 00168 /* Methods -------------------------------------------------------------------*/ 00169 00170 /** 00171 * @brief Reset the structure used to store the identifier of the L6470 00172 * application command and its the needed parameters. 00173 * @param pL6470_AppCmdPkg The structure to be reset. 00174 */ 00175 void L6470::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg) 00176 { 00177 uint8_t id; 00178 00179 for(id=0; id<L6470DAISYCHAINSIZE; id++) 00180 { 00181 (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0; 00182 (pL6470_AppCmdPkg+id)->p1=0; 00183 (pL6470_AppCmdPkg+id)->p2=0; 00184 (pL6470_AppCmdPkg+id)->p3=0; 00185 } 00186 } 00187 00188 /** 00189 * @brief Fill the structure used to store the identifier of the L6470 00190 * application command and its the needed parameters. 00191 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 00192 * @param pL6470_AppCmdPkg The structure to be filled. 00193 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. 00194 * @param p1 The 1st parameter (if it is not needed it will be not considered). 00195 * @param p2 The 2nd parameter (if it is not needed it will be not considered). 00196 * @param p3 The 3rd parameter (if it is not needed it will be not considered). 00197 */ 00198 void L6470::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) 00199 { 00200 (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId; 00201 (pL6470_AppCmdPkg+L6470_Id)->p1 = p1; 00202 (pL6470_AppCmdPkg+L6470_Id)->p2 = p2; 00203 (pL6470_AppCmdPkg+L6470_Id)->p3 = p3; 00204 } 00205 00206 /** 00207 * @brief This function will fill the column of the L6470_AppCmdPkg related 00208 * the L6470 to be addressed inside the daisy chain. 00209 * 00210 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 00211 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. 00212 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. 00213 * @param p1 The 1st parameter (if it is not needed it will be not considered). 00214 * @param p2 The 2nd parameter (if it is not needed it will be not considered). 00215 * @param p3 The 3rd parameter (if it is not needed it will be not considered). 00216 */ 00217 void L6470::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) 00218 { 00219 if(!L6470_DaisyChain_HalfPrepared) 00220 { 00221 L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */ 00222 L6470_ResetAppCmdPkg(pL6470_AppCmdPkg); 00223 } 00224 00225 L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3); 00226 } 00227 00228 /** 00229 * @brief This function will translate the data inside the L6470_AppCmdPkg into 00230 * the right data to be sent via SPI to the L6470 daisy chain. 00231 * 00232 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. 00233 * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands. 00234 */ 00235 void L6470::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct) 00236 { 00237 uint8_t PkgId; 00238 uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */ 00239 uint8_t spibyte; 00240 00241 /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */ 00242 uint8_t i = 0; 00243 for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++) 00244 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) 00245 *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00; 00246 00247 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) 00248 { 00249 /* Build the 1st bytes to transmit with the binary code of the command */ 00250 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode); 00251 00252 /* Perform the related L6470_AppCmdId */ 00253 switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId) 00254 { 00255 case L6470_NOP_ID: 00256 break; 00257 case L6470_SETPARAM_ID: 00258 /* Build the 1st bytes to transmit (PARAM) */ 00259 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); 00260 00261 /* The length, in byte, of this register (PARAM) is... */ 00262 PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte; 00263 00264 /* Build the others bytes to transmit (VALUE) */ 00265 for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++) 00266 { 00267 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte))); 00268 } 00269 break; 00270 case L6470_GETPARAM_ID: 00271 /* Build the 1st bytes to transmit (PARAM) */ 00272 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); 00273 break; 00274 case L6470_RUN_ID: 00275 /* Build the 1st bytes to transmit (DIR) */ 00276 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 00277 00278 /* Build the others bytes to transmit (SPD) */ 00279 for (spibyte=1; spibyte<(3+1); spibyte++) 00280 { 00281 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 00282 } 00283 break; 00284 case L6470_STEPCLOCK_ID: 00285 /* Build the 1st bytes to transmit (DIR) */ 00286 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 00287 break; 00288 case L6470_MOVE_ID: 00289 /* Build the 1st bytes to transmit (DIR) */ 00290 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 00291 00292 /* Build the others bytes to transmit (N_STEP) */ 00293 for (spibyte=1; spibyte<(3+1); spibyte++) 00294 { 00295 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 00296 } 00297 break; 00298 case L6470_GOTO_ID: 00299 /* Build the others bytes to transmit (ABS_POS) */ 00300 for (spibyte=1; spibyte<(3+1); spibyte++) 00301 { 00302 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte))); 00303 } 00304 break; 00305 case L6470_GOTODIR_ID: 00306 /* Build the 1st bytes to transmit (DIR) */ 00307 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 00308 00309 /* Build the others bytes to transmit (ABS_POS) */ 00310 for (spibyte=1; spibyte<(3+1); spibyte++) 00311 { 00312 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 00313 } 00314 break; 00315 case L6470_GOUNTIL_ID: 00316 /* Build the 1st bytes to transmit (ACT) */ 00317 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); 00318 /* Build the 1st bytes to transmit (DIR) */ 00319 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); 00320 00321 /* Build the others bytes to transmit (SPD) */ 00322 for (spibyte=1; spibyte<(3+1); spibyte++) 00323 { 00324 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte))); 00325 } 00326 break; 00327 case L6470_RELEASESW_ID: 00328 /* Build the 1st bytes to transmit (ACT) */ 00329 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); 00330 /* Build the 1st bytes to transmit (DIR) */ 00331 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); 00332 break; 00333 case L6470_GOHOME_ID: 00334 break; 00335 case L6470_GOMARK_ID: 00336 break; 00337 case L6470_RESETPOS_ID: 00338 break; 00339 case L6470_RESETDEVICE_ID: 00340 break; 00341 case L6470_SOFTSTOP_ID: 00342 break; 00343 case L6470_HARDSTOP_ID: 00344 break; 00345 case L6470_SOFTHIZ_ID: 00346 break; 00347 case L6470_HARDHIZ_ID: 00348 break; 00349 case L6470_GETSTATUS_ID: 00350 break; 00351 } 00352 } 00353 } 00354 00355 /* End of L6470_Private_Functions */ 00356 00357 /** 00358 * @addtogroup L6470_Exported_Functions 00359 * @{ 00360 */ 00361 00362 /** 00363 * @addtogroup L6470_Conversion_Functions 00364 * @brief The following functions act just on one driver inside the L6470 00365 * daisy chain. The command is immediately sent. 00366 * @{ 00367 */ 00368 00369 /** 00370 * @brief Convert the absolute position as 2's complement format into the signed number. 00371 * 00372 * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. 00373 * @retval Position The position as signed number. 00374 */ 00375 int32_t L6470::L6470_AbsPos_2_Position(uint32_t AbsPos) 00376 { 00377 if (AbsPos > L6470_MAX_POSITION) 00378 return (AbsPos - (L6470_POSITION_RANGE + 1)); 00379 else 00380 return AbsPos; 00381 } 00382 00383 /** 00384 * @brief Convert the position as signed number into absolute position as 2's complement format. 00385 * 00386 * @param Position The position as signed number. 00387 * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. 00388 */ 00389 uint32_t L6470::L6470_Position_2_AbsPos(int32_t Position) 00390 { 00391 if ((Position >= 0) && (Position <= L6470_MAX_POSITION)) 00392 return Position; 00393 else 00394 { 00395 if ((Position >= L6470_MIN_POSITION) && (Position < 0)) 00396 return (Position + (L6470_POSITION_RANGE + 1)); 00397 else 00398 return (L6470_POSITION_RANGE + 1); // OVF 00399 } 00400 } 00401 00402 /** 00403 * @brief Convert the SPEED register value into step/s. 00404 * 00405 * @param Speed The SPEED register value. 00406 * @retval step/s The speed as step/s. 00407 */ 00408 float L6470::L6470_Speed_2_Step_s(uint32_t Speed) 00409 { 00410 return (Speed * ((float)14.9012e-3)); 00411 } 00412 00413 /** 00414 * @brief Convert the speed as step/s into a right value for SPEED register. 00415 * 00416 * @param step/s The speed as step/s. 00417 * @retval Speed The SPEED register value. 00418 */ 00419 uint32_t L6470::L6470_Step_s_2_Speed(float Step_s) 00420 { 00421 if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3))) 00422 return (uint32_t)(Step_s / ((float)14.9012e-3)); 00423 else 00424 return 0; // Warning 00425 } 00426 00427 /** 00428 * @brief Convert the ACC register value into step/(s^2). 00429 * 00430 * @param Acc The ACC register value. 00431 * @retval step/(s^2) The acceleration as step/(s^2). 00432 */ 00433 float L6470::L6470_Acc_2_Step_s2(uint16_t Acc) 00434 { 00435 if (Acc <= L6470_MAX_ACC) 00436 return (Acc * ((float)1.4552e1)); 00437 else 00438 return 0; // Warning 00439 } 00440 00441 /** 00442 * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register. 00443 * 00444 * @param step/(s^2) The acceleration as step/(s^2). 00445 * @retval Acc The ACC register value. 00446 */ 00447 uint16_t L6470::L6470_Step_s2_2_Acc(float Step_s2) 00448 { 00449 if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1))) 00450 return (uint16_t)(Step_s2 / ((float)1.4552e1)); 00451 else 00452 return 0; // Warning 00453 } 00454 00455 /** 00456 * @brief Convert the DEC register value into step/(s^2). 00457 * 00458 * @param Dec The DEC register value. 00459 * @retval step/(s^2) The deceleration as step/(s^2). 00460 */ 00461 float L6470::L6470_Dec_2_Step_s2(uint16_t Dec) 00462 { 00463 if (Dec <= L6470_MAX_DEC) 00464 return (Dec * ((float)1.4552e1)); 00465 else 00466 return 0; // Warning 00467 } 00468 00469 /** 00470 * @brief Convert the deceleration as step/(s^2) into a right value for DEC register. 00471 * 00472 * @param step/(s^2) The deceleration as step/(s^2). 00473 * @retval Dec The DEC register value. 00474 */ 00475 uint16_t L6470::L6470_Step_s2_2_Dec(float Step_s2) 00476 { 00477 if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1))) 00478 return (uint16_t)(Step_s2 / ((float)1.4552e1)); 00479 else 00480 return 0; // Warning 00481 } 00482 00483 /** 00484 * @brief Convert the MAX_SPEED register value into step/s. 00485 * 00486 * @param MaxSpeed The MAX_SPEED register value. 00487 * @retval step/s The max speed as step/s. 00488 */ 00489 float L6470::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed) 00490 { 00491 if (MaxSpeed <= L6470_MAX_MAX_SPEED) 00492 return (MaxSpeed * ((float)15.2588)); 00493 else 00494 return 0; // Warning 00495 } 00496 00497 /** 00498 * @brief Convert the max speed as step/s into a right value for MAX_SPEED register. 00499 * 00500 * @param step/s The max speed as step/s. 00501 * @retval MaxSpeed The MAX_SPEED register value. 00502 */ 00503 uint16_t L6470::L6470_Step_s_2_MaxSpeed(float Step_s) 00504 { 00505 if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588))) 00506 return (uint16_t)(Step_s / ((float)15.2588)); 00507 else 00508 return 0; // Warning 00509 } 00510 00511 /** 00512 * @brief Convert the MIN_SPEED register value into step/s. 00513 * 00514 * @param MinSpeed The MIN_SPEED register value. 00515 * @retval step/s The min speed as step/s. 00516 */ 00517 float L6470::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed) 00518 { 00519 if (MinSpeed <= L6470_MAX_MIN_SPEED) 00520 return (MinSpeed * ((float)238.4186e-3)); 00521 else 00522 return 0; // Warning 00523 } 00524 00525 /** 00526 * @brief Convert the min speed as step/s into a right value for MIN_SPEED register. 00527 * 00528 * @param step/s The min speed as step/s. 00529 * @retval MinSpeed The MIN_SPEED register value. 00530 */ 00531 uint16_t L6470::L6470_Step_s_2_MinSpeed(float Step_s) 00532 { 00533 if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3))) 00534 return (uint16_t)(Step_s / ((float)238.4186e-3)); 00535 else 00536 return 0; // Warning 00537 } 00538 00539 /** 00540 * @brief Convert the FS_SPD register value into step/s. 00541 * 00542 * @param FsSpd The FS_SPD register value. 00543 * @retval step/s The full-step speed as step/s. 00544 */ 00545 float L6470::L6470_FsSpd_2_Step_s(uint16_t FsSpd) 00546 { 00547 if (FsSpd <= L6470_MAX_FS_SPD) 00548 return ((FsSpd+0.5) * ((float)15.25)); 00549 else 00550 return 0; // Warning 00551 } 00552 00553 /** 00554 * @brief Convert the full-step speed as step/s into a right value for FS_SPD register. 00555 * 00556 * @param step/s The full-step speed as step/s. 00557 * @retval FsSpd The FS_SPD register value. 00558 */ 00559 uint16_t L6470::L6470_Step_s_2_FsSpd(float Step_s) 00560 { 00561 if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25))) 00562 return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5); 00563 else 00564 return 0; // Warning 00565 } 00566 00567 /** 00568 * @brief Convert the INT_SPEED register value into step/s. 00569 * 00570 * @param IntSpeed The INT_SPEED register value. 00571 * @retval step/s The intersect speed as step/s. 00572 */ 00573 float L6470::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed) 00574 { 00575 if (IntSpeed <= L6470_MAX_INT_SPEED) 00576 return (IntSpeed * ((float)59.6046e-3)); 00577 else 00578 return 0; // Warning 00579 } 00580 00581 /** 00582 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 00583 * 00584 * @param step/s The full-step speed as step/s. 00585 * @retval FsSpd The FS_SPD register value. 00586 */ 00587 uint16_t L6470::L6470_Step_s_2_IntSpeed(float Step_s) 00588 { 00589 if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3))) 00590 return (uint16_t)(Step_s / ((float)59.6046e-3)); 00591 else 00592 return 0; // Warning 00593 } 00594 00595 /** 00596 * @brief Convert the ST_SLP register value into s/step. 00597 * 00598 * @param StartSlope The ST_SLP register value. 00599 * @retval s/step The start slope as s/step. 00600 */ 00601 float L6470::L6470_StSlp_2_s_Step(uint8_t StSlp) 00602 { 00603 // if (StSlp <= L6470_MAX_ST_SLP) 00604 return (StSlp * ((float)1.5686e-5)); 00605 // else 00606 // return 0; // Warning 00607 } 00608 00609 /** 00610 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 00611 * 00612 * @param step/s The full-step speed as step/s. 00613 * @retval FsSpd The FS_SPD register value. 00614 */ 00615 uint8_t L6470::L6470_s_Step_2_StSlp(float s_Step) 00616 { 00617 if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5))) 00618 return (uint8_t)(s_Step / ((float)1.5686e-5)); 00619 else 00620 return 0; // Warning 00621 } 00622 00623 /** 00624 * @brief Convert the INT_SPEED register value into step/s. 00625 * 00626 * @param IntSpeed The INT_SPEED register value. 00627 * @retval step/s The intersect speed as step/s. 00628 */ 00629 float L6470::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc) 00630 { 00631 // if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC) 00632 return (FnSlpAcc * ((float)1.5686e-5)); 00633 // else 00634 // return 0; // Warning 00635 } 00636 00637 /** 00638 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 00639 * 00640 * @param step/s The full-step speed as step/s. 00641 * @retval FsSpd The FS_SPD register value. 00642 */ 00643 uint8_t L6470::L6470_s_Step_2_FnSlpAcc(float s_Step) 00644 { 00645 if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5))) 00646 return (uint8_t)(s_Step / ((float)1.5686e-5)); 00647 else 00648 return 0; // Warning 00649 } 00650 00651 /** 00652 * @brief Convert the INT_SPEED register value into step/s. 00653 * 00654 * @param IntSpeed The INT_SPEED register value. 00655 * @retval step/s The intersect speed as step/s. 00656 */ 00657 float L6470::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec) 00658 { 00659 // if (FnSlpDec <= L6470_MAX_FN_SLP_DEC) 00660 return (FnSlpDec * ((float)1.5686e-5)); 00661 // else 00662 // return 0; // Warning 00663 } 00664 00665 /** 00666 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 00667 * 00668 * @param step/s The full-step speed as step/s. 00669 * @retval FsSpd The FS_SPD register value. 00670 */ 00671 uint8_t L6470::L6470_s_Step_2_FnSlpDec(float s_Step) 00672 { 00673 if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5))) 00674 return (uint8_t)(s_Step / ((float)1.5686e-5)); 00675 else 00676 return 0; // Warning 00677 } 00678 00679 /** 00680 * @brief Convert the OCD_TH register value into mA. 00681 * 00682 * @param OcdTh The OCD_TH register value. 00683 * @retval mA The overcurrent threshold as mA. 00684 */ 00685 float L6470::L6470_OcdTh_2_mA(uint8_t OcdTh) 00686 { 00687 if (OcdTh <= L6470_MAX_OCD_TH) 00688 return ((OcdTh+1) * ((float)375)); 00689 else 00690 return 0; // Warning 00691 } 00692 00693 /** 00694 * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register. 00695 * 00696 * @param mA The overcurrent threshold as mA. 00697 * @retval OcdTh The OCD_TH register value. 00698 */ 00699 uint8_t L6470::L6470_mA_2_OcdTh(float mA) 00700 { 00701 float result, decimal; 00702 00703 if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375))) 00704 { 00705 result = (mA / ((float)375)); 00706 decimal = result - (uint8_t)result; 00707 00708 if (decimal < (float)0.5) 00709 return ((uint8_t)result - 1); 00710 else 00711 return ((uint8_t)result); 00712 } 00713 else 00714 return 0; // Warning 00715 } 00716 00717 /** 00718 * @brief Convert the STALL_TH register value into mA. 00719 * 00720 * @param StallTh The STALL_TH register value. 00721 * @retval mA The stall detection threshold as mA. 00722 */ 00723 float L6470::L6470_StallTh_2_mA(uint8_t StallTh) 00724 { 00725 if (StallTh <= L6470_MAX_STALL_TH) 00726 return ((StallTh+1) * ((float)31.25)); 00727 else 00728 return 0; // Warning 00729 } 00730 00731 /** 00732 * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register. 00733 * 00734 * @param mA The stall detection threshold as mA. 00735 * @retval StallTh The STALL_TH register value. 00736 */ 00737 uint8_t L6470::L6470_mA_2_StallTh(float mA) 00738 { 00739 float result, decimal; 00740 00741 if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25))) 00742 { 00743 result = (mA / ((float)31.25)); 00744 decimal = result - (uint8_t)result; 00745 00746 if (decimal < (float)0.5) 00747 return ((uint8_t)result - 1); 00748 else 00749 return ((uint8_t)result); 00750 } 00751 else 00752 return 0; // Warning 00753 } 00754 00755 /* End of L6470_Conversion_Functions */ 00756 00757 /** 00758 * @addtogroup L6470_AppCMDs 00759 * @{ 00760 */ 00761 00762 /** 00763 * @brief SetParam command sets the register value equal to a new value. 00764 * 00765 * @param L6470_RegId The identifier of the L6470 register to be addressed. 00766 * @param Value The new value. 00767 */ 00768 void L6470::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) 00769 { 00770 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); 00771 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00772 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00773 } 00774 00775 /** 00776 * @brief GetParam command reads the register value. 00777 * 00778 * @param L6470_RegId The identifier of the L6470 register to be addressed. 00779 * 00780 * @retval ReceivedValue The register value. 00781 */ 00782 uint32_t L6470::L6470_GetParam(eL6470_RegId_t L6470_RegId) 00783 { 00784 uint8_t ValueLengthByte; 00785 uint32_t ReceivedValue; 00786 00787 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); 00788 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00789 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00790 00791 ValueLengthByte = L6470_Register[L6470_RegId].LengthByte; 00792 00793 ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte); 00794 00795 return ReceivedValue; 00796 } 00797 00798 /** 00799 * @brief Run command produces a motion at fixed speed. 00800 * 00801 * @param L6470_DirId The identifier of the L6470 motion direction. 00802 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 00803 */ 00804 void L6470::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed) 00805 { 00806 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); 00807 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00808 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00809 } 00810 00811 /** 00812 * @brief StepClock command switches the device in Step-clock mode. 00813 * 00814 * @param L6470_DirId The identifier of the L6470 motion direction. 00815 */ 00816 void L6470::L6470_StepClock(eL6470_DirId_t L6470_DirId) 00817 { 00818 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); 00819 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00820 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00821 } 00822 00823 /** 00824 * @brief Move command produces a motion of N_STEP microsteps. 00825 * 00826 * @param L6470_DirId The identifier of the L6470 motion direction. 00827 * @param N_Step The number of microsteps. 00828 */ 00829 void L6470::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step) 00830 { 00831 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); 00832 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00833 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00834 } 00835 00836 /** 00837 * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path. 00838 * 00839 * @param AbsPos The target absolute position. 00840 */ 00841 void L6470::L6470_GoTo(uint32_t AbsPos) 00842 { 00843 if (AbsPos <= L6470_POSITION_RANGE) 00844 { 00845 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); 00846 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00847 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00848 } 00849 } 00850 00851 /** 00852 * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction. 00853 * 00854 * @param L6470_DirId The identifier of the L6470 motion direction. 00855 * @param AbsPos The target absolute position. 00856 */ 00857 void L6470::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) 00858 { 00859 if (AbsPos <= L6470_POSITION_RANGE) 00860 { 00861 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); 00862 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00863 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00864 } 00865 } 00866 00867 /** 00868 * @brief GoUntil command produces a motion at fixed speed imposing a direction 00869 * until an external switch turn-on event occurs. 00870 * 00871 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 00872 * @param L6470_DirId The identifier of the L6470 motion direction. 00873 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 00874 */ 00875 void L6470::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) 00876 { 00877 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); 00878 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00879 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00880 } 00881 00882 /** 00883 * @brief ReleaseSW command produces a motion at minimum speed imposing a direction 00884 * until SW is released. 00885 * 00886 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 00887 * @param L6470_DirId The identifier of the L6470 motion direction. 00888 */ 00889 void L6470::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) 00890 { 00891 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); 00892 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00893 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00894 } 00895 00896 /** 00897 * @brief GoHome command produces a motion to the HOME position (zero position) 00898 * via the shortest path. 00899 * 00900 */ 00901 void L6470::L6470_GoHome(void) 00902 { 00903 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); 00904 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00905 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00906 } 00907 00908 /** 00909 * @brief GoMark command produces a motion to the MARK position performing the 00910 * minimum path. 00911 * 00912 */ 00913 void L6470::L6470_GoMark(void) 00914 { 00915 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); 00916 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00917 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00918 } 00919 00920 /** 00921 * @brief ResetPos command resets the ABS_POS register to zero. 00922 * 00923 */ 00924 void L6470::L6470_ResetPos(void) 00925 { 00926 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); 00927 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00928 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00929 } 00930 00931 /** 00932 * @brief ResetDevice command resets the device to power-up conditions. 00933 * 00934 */ 00935 void L6470::L6470_ResetDevice(void) 00936 { 00937 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); 00938 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00939 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00940 } 00941 00942 /** 00943 * @brief SoftStop command causes an immediate deceleration to zero speed and 00944 * a consequent motor stop; the deceleration value used is the one stored 00945 * in the DEC register. 00946 * 00947 */ 00948 void L6470::L6470_SoftStop(void) 00949 { 00950 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); 00951 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00952 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00953 } 00954 00955 /** 00956 * @brief HardStop command causes an immediate motor stop with infinite deceleration. 00957 * 00958 */ 00959 void L6470::L6470_HardStop(void) 00960 { 00961 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); 00962 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00963 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00964 } 00965 00966 /** 00967 * @brief SoftHiZ command disables the power bridges (high impedance state) 00968 * after a deceleration to zero; the deceleration value used is the one 00969 * stored in the DEC register. 00970 * 00971 */ 00972 void L6470::L6470_SoftHiZ(void) 00973 { 00974 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); 00975 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00976 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00977 } 00978 00979 /** 00980 * @brief HardHiZ command immediately disables the power bridges (high impedance state). 00981 * 00982 */ 00983 void L6470::L6470_HardHiZ(void) 00984 { 00985 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); 00986 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 00987 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 00988 } 00989 00990 /** 00991 * @brief GetStatus command returns the STATUS register value. 00992 * 00993 * 00994 * @retval ReceivedValue The register value. 00995 */ 00996 uint16_t L6470::L6470_GetStatus(void) 00997 { 00998 uint16_t ReceivedValue; 00999 01000 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); 01001 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 01002 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 01003 01004 ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2); 01005 01006 return ReceivedValue; 01007 } 01008 01009 /* End of L6470_AppCMDs */ 01010 01011 /** 01012 * @addtogroup L6470_AppCMDs_ToBePrepared 01013 * @{ 01014 */ 01015 01016 /** 01017 * @brief Prepare to send @ref L6470_SetParam command. 01018 * 01019 * @param L6470_RegId The identifier of the L6470 register to be addressed. 01020 * @param Value The new value. 01021 * 01022 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01023 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01024 */ 01025 void L6470::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) 01026 { 01027 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); 01028 } 01029 01030 /** 01031 * @brief Prepare to send @ref L6470_GetParam command. 01032 * 01033 * @param L6470_Id The L6470 identifier inside the daisy chain. 01034 * @param L6470_RegId The identifier of the L6470 register to be addressed. 01035 * 01036 * @retval ReceivedValue The register value. 01037 * 01038 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01039 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01040 */ 01041 void L6470::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId) 01042 { 01043 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); 01044 } 01045 01046 /** 01047 * @brief Prepare to send @ref L6470_Run command. 01048 * 01049 * @param L6470_DirId The identifier of the L6470 motion direction. 01050 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 01051 * 01052 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01053 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01054 */ 01055 void L6470::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed) 01056 { 01057 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); 01058 } 01059 01060 /** 01061 * @brief Prepare to send @ref L6470_StepClock command. 01062 * 01063 * @param L6470_DirId The identifier of the L6470 motion direction. 01064 * 01065 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01066 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01067 */ 01068 void L6470::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId) 01069 { 01070 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); 01071 } 01072 01073 /** 01074 * @brief Prepare to send @ref L6470_Move command. 01075 * 01076 * @param L6470_DirId The identifier of the L6470 motion direction. 01077 * @param N_Step The number of microsteps. 01078 * 01079 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01080 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01081 */ 01082 void L6470::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step) 01083 { 01084 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); 01085 } 01086 01087 /** 01088 * @brief Prepare to send @ref L6470_GoTo command. 01089 * 01090 * @param AbsPos The target absolute position. 01091 * 01092 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01093 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01094 */ 01095 void L6470::L6470_PrepareGoTo(uint32_t AbsPos) 01096 { 01097 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); 01098 } 01099 01100 /** 01101 * @brief Prepare to send @ref L6470_GoToDIR command. 01102 * 01103 * @param L6470_DirId The identifier of the L6470 motion direction. 01104 * @param AbsPos The target absolute position. 01105 * 01106 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01107 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01108 */ 01109 void L6470::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) 01110 { 01111 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); 01112 } 01113 01114 /** 01115 * @brief Prepare to send @ref L6470_GoUntil command. 01116 * 01117 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 01118 * @param L6470_DirId The identifier of the L6470 motion direction. 01119 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 01120 * 01121 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01122 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01123 */ 01124 void L6470::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) 01125 { 01126 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); 01127 } 01128 01129 /** 01130 * @brief Prepare to send @ref L6470_ReleaseSW. 01131 * 01132 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 01133 * @param L6470_DirId The identifier of the L6470 motion direction. 01134 * 01135 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01136 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01137 */ 01138 void L6470::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) 01139 { 01140 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); 01141 } 01142 01143 /** 01144 * @brief Prepare to send @ref L6470_GoHome command. 01145 * 01146 * 01147 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01148 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01149 */ 01150 void L6470::L6470_PrepareGoHome(void) 01151 { 01152 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); 01153 } 01154 01155 /** 01156 * @brief Prepare to send @ref L6470_GoMark command. 01157 * 01158 * 01159 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01160 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01161 */ 01162 void L6470::L6470_PrepareGoMark(void) 01163 { 01164 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); 01165 } 01166 01167 /** 01168 * @brief Prepare to send @ref L6470_ResetPos command. 01169 * 01170 * 01171 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01172 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01173 */ 01174 void L6470::L6470_PrepareResetPos(void) 01175 { 01176 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); 01177 } 01178 01179 /** 01180 * @brief Prepare to send @ref L6470_ResetDevice command. 01181 * 01182 * 01183 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01184 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01185 */ 01186 void L6470::L6470_PrepareResetDevice(void) 01187 { 01188 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); 01189 } 01190 01191 /** 01192 * @brief Prepare to send @ref L6470_SoftStop command. 01193 * 01194 * 01195 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01196 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01197 */ 01198 void L6470::L6470_PrepareSoftStop(void) 01199 { 01200 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); 01201 } 01202 01203 /** 01204 * @brief Prepare to send @ref L6470_HardStop command. 01205 * 01206 * 01207 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01208 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01209 */ 01210 void L6470::L6470_PrepareHardStop(void) 01211 { 01212 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); 01213 } 01214 01215 /** 01216 * @brief Prepare to send @ref L6470_SoftHiZ command. 01217 * 01218 * 01219 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01220 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01221 */ 01222 void L6470::L6470_PrepareSoftHiZ(void) 01223 { 01224 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); 01225 } 01226 01227 /** 01228 * @brief Prepare to send @ref L6470_HardHiZ command. 01229 * 01230 * 01231 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01232 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01233 */ 01234 void L6470::L6470_PrepareHardHiZ(void) 01235 { 01236 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); 01237 } 01238 01239 /** 01240 * @brief Prepare to send @ref L6470_GetStatus command. 01241 * 01242 * 01243 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 01244 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 01245 */ 01246 void L6470::L6470_PrepareGetStatus(void) 01247 { 01248 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); 01249 } 01250 01251 /* End of L6470_AppCMDs_ToBePrepared */ 01252 01253 /** 01254 * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the 01255 * L6470 daisy chain. 01256 * 01257 * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure 01258 * containing returned values from each L6470 of the daisy chain for each 01259 * sent SPI data. 01260 */ 01261 uint8_t* L6470::L6470_PerformPreparedApplicationCommand(void) 01262 { 01263 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 01264 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 01265 01266 return (uint8_t*)(L6470_DaisyChainSpiRxStruct); 01267 } 01268 01269 /** 01270 * @brief Send command to the L6470 daisy chain via SPI 01271 * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470 01272 * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470 01273 */ 01274 void L6470::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct) 01275 { 01276 uint8_t spibyte; 01277 01278 L6470_DaisyChain_HalfPrepared = ZERO_F; 01279 01280 /* Send all command bytes via SPI */ 01281 for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++) 01282 { 01283 /* Send the command via SPI */ 01284 L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10); 01285 01286 //_DELAY(TDISCS); 01287 uint8_t delay_cnt; 01288 for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS 01289 } 01290 } 01291 01292 /** 01293 * @brief Extracts the data returned by the L6470 from the matrix that 01294 * contains the received SPI data. 01295 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 01296 * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that 01297 * contains the received data by SPI from the L6470 daisy chain. 01298 * @param LengthByte The number of bytes about the received value. 01299 */ 01300 uint32_t L6470::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte) 01301 { 01302 uint32_t value; 01303 uint8_t i; 01304 01305 value = 0x000000; 01306 for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++) 01307 { 01308 value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8); 01309 } 01310 01311 return value; 01312 } 01313 01314 /** 01315 * @brief Check the state of a flag inside the L6470 STATUS register. 01316 * 01317 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 01318 * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked. 01319 * 01320 * @retval state The flag state. 01321 */ 01322 01323 uint8_t L6470::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId) 01324 { 01325 uint8_t state = 0; 01326 01327 *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID); 01328 01329 switch(L6470_StatusRegisterFlagId) 01330 { 01331 case HiZ_ID: 01332 state = pL6470_StatusRegister->HiZ; 01333 break; 01334 case BUSY_ID: 01335 state = pL6470_StatusRegister->BUSY; 01336 break; 01337 case SW_F_ID: 01338 state = pL6470_StatusRegister->SW_F; 01339 break; 01340 case SW_EVN_ID: 01341 state = pL6470_StatusRegister->SW_EVN; 01342 break; 01343 case DIR_ID: 01344 state = pL6470_StatusRegister->DIR; 01345 break; 01346 case MOT_STATUS_ID: 01347 state = pL6470_StatusRegister->MOT_STATUS; 01348 break; 01349 case NOTPERF_CMD_ID: 01350 state = pL6470_StatusRegister->NOTPERF_CMD; 01351 break; 01352 case WRONG_CMD_ID: 01353 state = pL6470_StatusRegister->WRONG_CMD; 01354 break; 01355 case UVLO_ID: 01356 state = pL6470_StatusRegister->UVLO; 01357 break; 01358 case TH_WRN_ID: 01359 state = pL6470_StatusRegister->TH_WRN; 01360 break; 01361 case TH_SD_ID: 01362 state = pL6470_StatusRegister->TH_SD; 01363 break; 01364 case OCD_ID: 01365 state = pL6470_StatusRegister->OCD; 01366 break; 01367 case STEP_LOSS_A_ID: 01368 state = pL6470_StatusRegister->STEP_LOSS_A; 01369 break; 01370 case STEP_LOSS_B_ID: 01371 state = pL6470_StatusRegister->STEP_LOSS_B; 01372 break; 01373 case SCK_MOD_ID: 01374 state = pL6470_StatusRegister->SCK_MOD; 01375 break; 01376 } 01377 01378 return state; 01379 } 01380 01381 /** 01382 * @brief Return the mnemonic name for the L6470 register. 01383 * @param id The identifier of the L6470 register. 01384 */ 01385 uint8_t *L6470::L6470_GetRegisterName(uint8_t id) 01386 { 01387 if (id < L6470REGIDSIZE) 01388 { 01389 return (uint8_t*)L6470_Register[id].Name; 01390 } 01391 else 01392 { 01393 return NULL; 01394 } 01395 } 01396 01397 /** 01398 * @brief Configures the L6470 registers. 01399 * @param init The pointer to the initialization structure. 01400 */ 01401 status_t L6470::L6470_Config(void *init) 01402 { 01403 /* Disable the L6470. */ 01404 L6470_DISABLE(); 01405 01406 /* Enable the L6470. */ 01407 L6470_ENABLE(); 01408 01409 /* Reset devices. */ 01410 reset_device(); 01411 01412 /* Reset Status Register flags. */ 01413 get_status(); 01414 01415 /* Prepare the 'Register' field of StepperMotorDriverHandle */ 01416 L6470_init_t *MotorParameterData = (L6470_init_t *) init; 01417 StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc); 01418 StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec); 01419 StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed); 01420 StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed); 01421 StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd); 01422 StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage))); 01423 StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage))); 01424 StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage))); 01425 StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage))); 01426 StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed); 01427 StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp); 01428 StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc); 01429 StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec); 01430 StepperMotorRegister.K_THERM = MotorParameterData->kterm; 01431 StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth); 01432 StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth); 01433 StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen; 01434 StepperMotorRegister.CONFIG = MotorParameterData->config; 01435 StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel; 01436 01437 /* Write the L6470 registers with the prepared data */ 01438 L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC); 01439 L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC); 01440 L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED); 01441 L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED); 01442 L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD); 01443 L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD); 01444 L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN); 01445 L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC); 01446 L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC); 01447 L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED); 01448 L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP); 01449 L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC); 01450 L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC); 01451 L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM); 01452 L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH); 01453 L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH); 01454 L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN); 01455 L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG); 01456 if (!set_step_mode((StepperMotor::step_mode_t) StepperMotorRegister.STEP_MODE)) 01457 return COMPONENT_ERROR; 01458 01459 return COMPONENT_OK; 01460 } 01461 01462 /////////////////////////////////////////////////////////////////////////////////////////////Fabian 01463 /** 01464 * @brief Array whose elements are a structure in which store information about 01465 * the L6470 Registers (the address, the names, the length in bits, the 01466 * reset value) 01467 */ 01468 const sL6470_Register_t L6470B::_L6470_Register[L6470REGIDSIZE] = { 01469 {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position 01470 {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position 01471 {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position 01472 {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed 01473 {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration 01474 {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration 01475 {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed 01476 {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed 01477 {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed 01478 {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL 01479 {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL 01480 {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL 01481 {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL 01482 {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed 01483 {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope 01484 {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope 01485 {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope 01486 {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor 01487 {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions) 01488 {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold 01489 {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold 01490 {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode 01491 {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable 01492 {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration 01493 {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions) 01494 }; 01495 01496 /** 01497 * @brief Array whose elements are a structure in which store information about 01498 * the L6470 Application Commands (the mnemonic name, the number of 01499 * needed parameters, the related funtion to call) 01500 */ 01501 const sL6470_ApplicationCommand_t L6470B::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = { 01502 {"NOP", 0x00, 0}, 01503 {"SETPARAM", 0x00, 2}, 01504 {"GETPARAM", 0x20, 1}, 01505 {"RUN", 0x50, 2}, 01506 {"STEPCLOCK", 0x58, 1}, 01507 {"MOVE", 0x40, 2}, 01508 {"GOTO", 0x60, 1}, 01509 {"GOTO_DIR", 0x68, 2}, 01510 {"GOUNTIL", 0x82, 3}, 01511 {"RELEASESW", 0x92, 2}, 01512 {"GOHOME", 0x70, 0}, 01513 {"GOMARK", 0x78, 0}, 01514 {"RESETPOS", 0xD8, 0}, 01515 {"RESETDEVICE", 0xC0, 0}, 01516 {"SOFTSTOP", 0xB0, 0}, 01517 {"HARDSTOP", 0xB8, 0}, 01518 {"SOFTHIZ", 0xA0, 0}, 01519 {"HARDHIZ", 0xA8, 0}, 01520 {"GETSTATUS", 0xD0, 0} 01521 }; 01522 01523 /** 01524 * @brief The mnemonic names for the L6470 direction 01525 */ 01526 const sL6470_Direction_t L6470B::_L6470_Direction[L6470DIRIDSIZE] = { 01527 {"REV", 0x00}, //!< Reverse direction 01528 {"FWD", 0x01} //!< Forward direction 01529 }; 01530 01531 /** 01532 * @brief Action taken about ABS_POS register 01533 */ 01534 const sL6470_ACT_t L6470B::_L6470_ACT[L6470ACTIDSIZE] = { 01535 {"RST", 0x00}, //!< ABS_POS register is reset 01536 {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register 01537 }; 01538 01539 /* End of L6470_Private_Constants */ 01540 01541 /** 01542 * @defgroup L6470_Private_Variables 01543 * @brief L6470 Private Variables. 01544 * @{ 01545 */ 01546 01547 /* End of L6470_Private_Variables */ 01548 01549 01550 /** 01551 * @addtogroup L6470_Private_Functions 01552 * @{ 01553 */ 01554 01555 01556 /* Methods -------------------------------------------------------------------*/ 01557 01558 /** 01559 * @brief Reset the structure used to store the identifier of the L6470 01560 * application command and its the needed parameters. 01561 * @param pL6470_AppCmdPkg The structure to be reset. 01562 */ 01563 void L6470B::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg) 01564 { 01565 uint8_t id; 01566 01567 for(id=0; id<L6470DAISYCHAINSIZE; id++) 01568 { 01569 (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0; 01570 (pL6470_AppCmdPkg+id)->p1=0; 01571 (pL6470_AppCmdPkg+id)->p2=0; 01572 (pL6470_AppCmdPkg+id)->p3=0; 01573 } 01574 } 01575 01576 /** 01577 * @brief Fill the structure used to store the identifier of the L6470 01578 * application command and its the needed parameters. 01579 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 01580 * @param pL6470_AppCmdPkg The structure to be filled. 01581 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. 01582 * @param p1 The 1st parameter (if it is not needed it will be not considered). 01583 * @param p2 The 2nd parameter (if it is not needed it will be not considered). 01584 * @param p3 The 3rd parameter (if it is not needed it will be not considered). 01585 */ 01586 void L6470B::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) 01587 { 01588 (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId; 01589 (pL6470_AppCmdPkg+L6470_Id)->p1 = p1; 01590 (pL6470_AppCmdPkg+L6470_Id)->p2 = p2; 01591 (pL6470_AppCmdPkg+L6470_Id)->p3 = p3; 01592 } 01593 01594 /** 01595 * @brief This function will fill the column of the L6470_AppCmdPkg related 01596 * the L6470 to be addressed inside the daisy chain. 01597 * 01598 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 01599 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. 01600 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent. 01601 * @param p1 The 1st parameter (if it is not needed it will be not considered). 01602 * @param p2 The 2nd parameter (if it is not needed it will be not considered). 01603 * @param p3 The 3rd parameter (if it is not needed it will be not considered). 01604 */ 01605 void L6470B::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3) 01606 { 01607 if(!L6470_DaisyChain_HalfPrepared) 01608 { 01609 L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */ 01610 L6470_ResetAppCmdPkg(pL6470_AppCmdPkg); 01611 } 01612 01613 L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3); 01614 } 01615 01616 /** 01617 * @brief This function will translate the data inside the L6470_AppCmdPkg into 01618 * the right data to be sent via SPI to the L6470 daisy chain. 01619 * 01620 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled. 01621 * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands. 01622 */ 01623 void L6470B::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct) 01624 { 01625 uint8_t PkgId; 01626 uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */ 01627 uint8_t spibyte; 01628 01629 /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */ 01630 uint8_t i = 0; 01631 for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++) 01632 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) 01633 *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00; 01634 01635 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++) 01636 { 01637 /* Build the 1st bytes to transmit with the binary code of the command */ 01638 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode); 01639 01640 /* Perform the related L6470_AppCmdId */ 01641 switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId) 01642 { 01643 case L6470_NOP_ID: 01644 break; 01645 case L6470_SETPARAM_ID: 01646 /* Build the 1st bytes to transmit (PARAM) */ 01647 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); 01648 01649 /* The length, in byte, of this register (PARAM) is... */ 01650 PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte; 01651 01652 /* Build the others bytes to transmit (VALUE) */ 01653 for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++) 01654 { 01655 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte))); 01656 } 01657 break; 01658 case L6470_GETPARAM_ID: 01659 /* Build the 1st bytes to transmit (PARAM) */ 01660 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address); 01661 break; 01662 case L6470_RUN_ID: 01663 /* Build the 1st bytes to transmit (DIR) */ 01664 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 01665 01666 /* Build the others bytes to transmit (SPD) */ 01667 for (spibyte=1; spibyte<(3+1); spibyte++) 01668 { 01669 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 01670 } 01671 break; 01672 case L6470_STEPCLOCK_ID: 01673 /* Build the 1st bytes to transmit (DIR) */ 01674 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 01675 break; 01676 case L6470_MOVE_ID: 01677 /* Build the 1st bytes to transmit (DIR) */ 01678 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 01679 01680 /* Build the others bytes to transmit (N_STEP) */ 01681 for (spibyte=1; spibyte<(3+1); spibyte++) 01682 { 01683 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 01684 } 01685 break; 01686 case L6470_GOTO_ID: 01687 /* Build the others bytes to transmit (ABS_POS) */ 01688 for (spibyte=1; spibyte<(3+1); spibyte++) 01689 { 01690 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte))); 01691 } 01692 break; 01693 case L6470_GOTODIR_ID: 01694 /* Build the 1st bytes to transmit (DIR) */ 01695 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode); 01696 01697 /* Build the others bytes to transmit (ABS_POS) */ 01698 for (spibyte=1; spibyte<(3+1); spibyte++) 01699 { 01700 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte))); 01701 } 01702 break; 01703 case L6470_GOUNTIL_ID: 01704 /* Build the 1st bytes to transmit (ACT) */ 01705 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); 01706 /* Build the 1st bytes to transmit (DIR) */ 01707 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); 01708 01709 /* Build the others bytes to transmit (SPD) */ 01710 for (spibyte=1; spibyte<(3+1); spibyte++) 01711 { 01712 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte))); 01713 } 01714 break; 01715 case L6470_RELEASESW_ID: 01716 /* Build the 1st bytes to transmit (ACT) */ 01717 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3); 01718 /* Build the 1st bytes to transmit (DIR) */ 01719 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode); 01720 break; 01721 case L6470_GOHOME_ID: 01722 break; 01723 case L6470_GOMARK_ID: 01724 break; 01725 case L6470_RESETPOS_ID: 01726 break; 01727 case L6470_RESETDEVICE_ID: 01728 break; 01729 case L6470_SOFTSTOP_ID: 01730 break; 01731 case L6470_HARDSTOP_ID: 01732 break; 01733 case L6470_SOFTHIZ_ID: 01734 break; 01735 case L6470_HARDHIZ_ID: 01736 break; 01737 case L6470_GETSTATUS_ID: 01738 break; 01739 } 01740 } 01741 } 01742 01743 /* End of L6470_Private_Functions */ 01744 01745 /** 01746 * @addtogroup L6470_Exported_Functions 01747 * @{ 01748 */ 01749 01750 /** 01751 * @addtogroup L6470_Conversion_Functions 01752 * @brief The following functions act just on one driver inside the L6470 01753 * daisy chain. The command is immediately sent. 01754 * @{ 01755 */ 01756 01757 /** 01758 * @brief Convert the absolute position as 2's complement format into the signed number. 01759 * 01760 * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. 01761 * @retval Position The position as signed number. 01762 */ 01763 int32_t L6470B::L6470_AbsPos_2_Position(uint32_t AbsPos) 01764 { 01765 if (AbsPos > L6470_MAX_POSITION) 01766 return (AbsPos - (L6470_POSITION_RANGE + 1)); 01767 else 01768 return AbsPos; 01769 } 01770 01771 /** 01772 * @brief Convert the position as signed number into absolute position as 2's complement format. 01773 * 01774 * @param Position The position as signed number. 01775 * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1]. 01776 */ 01777 uint32_t L6470B::L6470_Position_2_AbsPos(int32_t Position) 01778 { 01779 if ((Position >= 0) && (Position <= L6470_MAX_POSITION)) 01780 return Position; 01781 else 01782 { 01783 if ((Position >= L6470_MIN_POSITION) && (Position < 0)) 01784 return (Position + (L6470_POSITION_RANGE + 1)); 01785 else 01786 return (L6470_POSITION_RANGE + 1); // OVF 01787 } 01788 } 01789 01790 /** 01791 * @brief Convert the SPEED register value into step/s. 01792 * 01793 * @param Speed The SPEED register value. 01794 * @retval step/s The speed as step/s. 01795 */ 01796 float L6470B::L6470_Speed_2_Step_s(uint32_t Speed) 01797 { 01798 return (Speed * ((float)14.9012e-3)); 01799 } 01800 01801 /** 01802 * @brief Convert the speed as step/s into a right value for SPEED register. 01803 * 01804 * @param step/s The speed as step/s. 01805 * @retval Speed The SPEED register value. 01806 */ 01807 uint32_t L6470B::L6470_Step_s_2_Speed(float Step_s) 01808 { 01809 if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3))) 01810 return (uint32_t)(Step_s / ((float)14.9012e-3)); 01811 else 01812 return 0; // Warning 01813 } 01814 01815 /** 01816 * @brief Convert the ACC register value into step/(s^2). 01817 * 01818 * @param Acc The ACC register value. 01819 * @retval step/(s^2) The acceleration as step/(s^2). 01820 */ 01821 float L6470B::L6470_Acc_2_Step_s2(uint16_t Acc) 01822 { 01823 if (Acc <= L6470_MAX_ACC) 01824 return (Acc * ((float)1.4552e1)); 01825 else 01826 return 0; // Warning 01827 } 01828 01829 /** 01830 * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register. 01831 * 01832 * @param step/(s^2) The acceleration as step/(s^2). 01833 * @retval Acc The ACC register value. 01834 */ 01835 uint16_t L6470B::L6470_Step_s2_2_Acc(float Step_s2) 01836 { 01837 if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1))) 01838 return (uint16_t)(Step_s2 / ((float)1.4552e1)); 01839 else 01840 return 0; // Warning 01841 } 01842 01843 /** 01844 * @brief Convert the DEC register value into step/(s^2). 01845 * 01846 * @param Dec The DEC register value. 01847 * @retval step/(s^2) The deceleration as step/(s^2). 01848 */ 01849 float L6470B::L6470_Dec_2_Step_s2(uint16_t Dec) 01850 { 01851 if (Dec <= L6470_MAX_DEC) 01852 return (Dec * ((float)1.4552e1)); 01853 else 01854 return 0; // Warning 01855 } 01856 01857 /** 01858 * @brief Convert the deceleration as step/(s^2) into a right value for DEC register. 01859 * 01860 * @param step/(s^2) The deceleration as step/(s^2). 01861 * @retval Dec The DEC register value. 01862 */ 01863 uint16_t L6470B::L6470_Step_s2_2_Dec(float Step_s2) 01864 { 01865 if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1))) 01866 return (uint16_t)(Step_s2 / ((float)1.4552e1)); 01867 else 01868 return 0; // Warning 01869 } 01870 01871 /** 01872 * @brief Convert the MAX_SPEED register value into step/s. 01873 * 01874 * @param MaxSpeed The MAX_SPEED register value. 01875 * @retval step/s The max speed as step/s. 01876 */ 01877 float L6470B::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed) 01878 { 01879 if (MaxSpeed <= L6470_MAX_MAX_SPEED) 01880 return (MaxSpeed * ((float)15.2588)); 01881 else 01882 return 0; // Warning 01883 } 01884 01885 /** 01886 * @brief Convert the max speed as step/s into a right value for MAX_SPEED register. 01887 * 01888 * @param step/s The max speed as step/s. 01889 * @retval MaxSpeed The MAX_SPEED register value. 01890 */ 01891 uint16_t L6470B::L6470_Step_s_2_MaxSpeed(float Step_s) 01892 { 01893 if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588))) 01894 return (uint16_t)(Step_s / ((float)15.2588)); 01895 else 01896 return 0; // Warning 01897 } 01898 01899 /** 01900 * @brief Convert the MIN_SPEED register value into step/s. 01901 * 01902 * @param MinSpeed The MIN_SPEED register value. 01903 * @retval step/s The min speed as step/s. 01904 */ 01905 float L6470B::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed) 01906 { 01907 if (MinSpeed <= L6470_MAX_MIN_SPEED) 01908 return (MinSpeed * ((float)238.4186e-3)); 01909 else 01910 return 0; // Warning 01911 } 01912 01913 /** 01914 * @brief Convert the min speed as step/s into a right value for MIN_SPEED register. 01915 * 01916 * @param step/s The min speed as step/s. 01917 * @retval MinSpeed The MIN_SPEED register value. 01918 */ 01919 uint16_t L6470B::L6470_Step_s_2_MinSpeed(float Step_s) 01920 { 01921 if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3))) 01922 return (uint16_t)(Step_s / ((float)238.4186e-3)); 01923 else 01924 return 0; // Warning 01925 } 01926 01927 /** 01928 * @brief Convert the FS_SPD register value into step/s. 01929 * 01930 * @param FsSpd The FS_SPD register value. 01931 * @retval step/s The full-step speed as step/s. 01932 */ 01933 float L6470B::L6470_FsSpd_2_Step_s(uint16_t FsSpd) 01934 { 01935 if (FsSpd <= L6470_MAX_FS_SPD) 01936 return ((FsSpd+0.5) * ((float)15.25)); 01937 else 01938 return 0; // Warning 01939 } 01940 01941 /** 01942 * @brief Convert the full-step speed as step/s into a right value for FS_SPD register. 01943 * 01944 * @param step/s The full-step speed as step/s. 01945 * @retval FsSpd The FS_SPD register value. 01946 */ 01947 uint16_t L6470B::L6470_Step_s_2_FsSpd(float Step_s) 01948 { 01949 if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25))) 01950 return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5); 01951 else 01952 return 0; // Warning 01953 } 01954 01955 /** 01956 * @brief Convert the INT_SPEED register value into step/s. 01957 * 01958 * @param IntSpeed The INT_SPEED register value. 01959 * @retval step/s The intersect speed as step/s. 01960 */ 01961 float L6470B::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed) 01962 { 01963 if (IntSpeed <= L6470_MAX_INT_SPEED) 01964 return (IntSpeed * ((float)59.6046e-3)); 01965 else 01966 return 0; // Warning 01967 } 01968 01969 /** 01970 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 01971 * 01972 * @param step/s The full-step speed as step/s. 01973 * @retval FsSpd The FS_SPD register value. 01974 */ 01975 uint16_t L6470B::L6470_Step_s_2_IntSpeed(float Step_s) 01976 { 01977 if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3))) 01978 return (uint16_t)(Step_s / ((float)59.6046e-3)); 01979 else 01980 return 0; // Warning 01981 } 01982 01983 /** 01984 * @brief Convert the ST_SLP register value into s/step. 01985 * 01986 * @param StartSlope The ST_SLP register value. 01987 * @retval s/step The start slope as s/step. 01988 */ 01989 float L6470B::L6470_StSlp_2_s_Step(uint8_t StSlp) 01990 { 01991 // if (StSlp <= L6470_MAX_ST_SLP) 01992 return (StSlp * ((float)1.5686e-5)); 01993 // else 01994 // return 0; // Warning 01995 } 01996 01997 /** 01998 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 01999 * 02000 * @param step/s The full-step speed as step/s. 02001 * @retval FsSpd The FS_SPD register value. 02002 */ 02003 uint8_t L6470B::L6470_s_Step_2_StSlp(float s_Step) 02004 { 02005 if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5))) 02006 return (uint8_t)(s_Step / ((float)1.5686e-5)); 02007 else 02008 return 0; // Warning 02009 } 02010 02011 /** 02012 * @brief Convert the INT_SPEED register value into step/s. 02013 * 02014 * @param IntSpeed The INT_SPEED register value. 02015 * @retval step/s The intersect speed as step/s. 02016 */ 02017 float L6470B::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc) 02018 { 02019 // if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC) 02020 return (FnSlpAcc * ((float)1.5686e-5)); 02021 // else 02022 // return 0; // Warning 02023 } 02024 02025 /** 02026 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 02027 * 02028 * @param step/s The full-step speed as step/s. 02029 * @retval FsSpd The FS_SPD register value. 02030 */ 02031 uint8_t L6470B::L6470_s_Step_2_FnSlpAcc(float s_Step) 02032 { 02033 if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5))) 02034 return (uint8_t)(s_Step / ((float)1.5686e-5)); 02035 else 02036 return 0; // Warning 02037 } 02038 02039 /** 02040 * @brief Convert the INT_SPEED register value into step/s. 02041 * 02042 * @param IntSpeed The INT_SPEED register value. 02043 * @retval step/s The intersect speed as step/s. 02044 */ 02045 float L6470B::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec) 02046 { 02047 // if (FnSlpDec <= L6470_MAX_FN_SLP_DEC) 02048 return (FnSlpDec * ((float)1.5686e-5)); 02049 // else 02050 // return 0; // Warning 02051 } 02052 02053 /** 02054 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register. 02055 * 02056 * @param step/s The full-step speed as step/s. 02057 * @retval FsSpd The FS_SPD register value. 02058 */ 02059 uint8_t L6470B::L6470_s_Step_2_FnSlpDec(float s_Step) 02060 { 02061 if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5))) 02062 return (uint8_t)(s_Step / ((float)1.5686e-5)); 02063 else 02064 return 0; // Warning 02065 } 02066 02067 /** 02068 * @brief Convert the OCD_TH register value into mA. 02069 * 02070 * @param OcdTh The OCD_TH register value. 02071 * @retval mA The overcurrent threshold as mA. 02072 */ 02073 float L6470B::L6470_OcdTh_2_mA(uint8_t OcdTh) 02074 { 02075 if (OcdTh <= L6470_MAX_OCD_TH) 02076 return ((OcdTh+1) * ((float)375)); 02077 else 02078 return 0; // Warning 02079 } 02080 02081 /** 02082 * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register. 02083 * 02084 * @param mA The overcurrent threshold as mA. 02085 * @retval OcdTh The OCD_TH register value. 02086 */ 02087 uint8_t L6470B::L6470_mA_2_OcdTh(float mA) 02088 { 02089 float result, decimal; 02090 02091 if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375))) 02092 { 02093 result = (mA / ((float)375)); 02094 decimal = result - (uint8_t)result; 02095 02096 if (decimal < (float)0.5) 02097 return ((uint8_t)result - 1); 02098 else 02099 return ((uint8_t)result); 02100 } 02101 else 02102 return 0; // Warning 02103 } 02104 02105 /** 02106 * @brief Convert the STALL_TH register value into mA. 02107 * 02108 * @param StallTh The STALL_TH register value. 02109 * @retval mA The stall detection threshold as mA. 02110 */ 02111 float L6470B::L6470_StallTh_2_mA(uint8_t StallTh) 02112 { 02113 if (StallTh <= L6470_MAX_STALL_TH) 02114 return ((StallTh+1) * ((float)31.25)); 02115 else 02116 return 0; // Warning 02117 } 02118 02119 /** 02120 * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register. 02121 * 02122 * @param mA The stall detection threshold as mA. 02123 * @retval StallTh The STALL_TH register value. 02124 */ 02125 uint8_t L6470B::L6470_mA_2_StallTh(float mA) 02126 { 02127 float result, decimal; 02128 02129 if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25))) 02130 { 02131 result = (mA / ((float)31.25)); 02132 decimal = result - (uint8_t)result; 02133 02134 if (decimal < (float)0.5) 02135 return ((uint8_t)result - 1); 02136 else 02137 return ((uint8_t)result); 02138 } 02139 else 02140 return 0; // Warning 02141 } 02142 02143 /* End of L6470_Conversion_Functions */ 02144 02145 /** 02146 * @addtogroup L6470_AppCMDs 02147 * @{ 02148 */ 02149 02150 /** 02151 * @brief SetParam command sets the register value equal to a new value. 02152 * 02153 * @param L6470_RegId The identifier of the L6470 register to be addressed. 02154 * @param Value The new value. 02155 */ 02156 void L6470B::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) 02157 { 02158 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); 02159 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02160 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02161 } 02162 02163 /** 02164 * @brief GetParam command reads the register value. 02165 * 02166 * @param L6470_RegId The identifier of the L6470 register to be addressed. 02167 * 02168 * @retval ReceivedValue The register value. 02169 */ 02170 uint32_t L6470B::L6470_GetParam(eL6470_RegId_t L6470_RegId) 02171 { 02172 uint8_t ValueLengthByte; 02173 uint32_t ReceivedValue; 02174 02175 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); 02176 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02177 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02178 02179 ValueLengthByte = L6470_Register[L6470_RegId].LengthByte; 02180 02181 ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte); 02182 02183 return ReceivedValue; 02184 } 02185 02186 /** 02187 * @brief Run command produces a motion at fixed speed. 02188 * 02189 * @param L6470_DirId The identifier of the L6470 motion direction. 02190 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 02191 */ 02192 void L6470B::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed) 02193 { 02194 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); 02195 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02196 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02197 } 02198 02199 /** 02200 * @brief StepClock command switches the device in Step-clock mode. 02201 * 02202 * @param L6470_DirId The identifier of the L6470 motion direction. 02203 */ 02204 void L6470B::L6470_StepClock(eL6470_DirId_t L6470_DirId) 02205 { 02206 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); 02207 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02208 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02209 } 02210 02211 /** 02212 * @brief Move command produces a motion of N_STEP microsteps. 02213 * 02214 * @param L6470_DirId The identifier of the L6470 motion direction. 02215 * @param N_Step The number of microsteps. 02216 */ 02217 void L6470B::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step) 02218 { 02219 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); 02220 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02221 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02222 } 02223 02224 /** 02225 * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path. 02226 * 02227 * @param AbsPos The target absolute position. 02228 */ 02229 void L6470B::L6470_GoTo(uint32_t AbsPos) 02230 { 02231 if (AbsPos <= L6470_POSITION_RANGE) 02232 { 02233 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); 02234 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02235 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02236 } 02237 } 02238 02239 /** 02240 * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction. 02241 * 02242 * @param L6470_DirId The identifier of the L6470 motion direction. 02243 * @param AbsPos The target absolute position. 02244 */ 02245 void L6470B::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) 02246 { 02247 if (AbsPos <= L6470_POSITION_RANGE) 02248 { 02249 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); 02250 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02251 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02252 } 02253 } 02254 02255 /** 02256 * @brief GoUntil command produces a motion at fixed speed imposing a direction 02257 * until an external switch turn-on event occurs. 02258 * 02259 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 02260 * @param L6470_DirId The identifier of the L6470 motion direction. 02261 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 02262 */ 02263 void L6470B::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) 02264 { 02265 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); 02266 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02267 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02268 } 02269 02270 /** 02271 * @brief ReleaseSW command produces a motion at minimum speed imposing a direction 02272 * until SW is released. 02273 * 02274 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 02275 * @param L6470_DirId The identifier of the L6470 motion direction. 02276 */ 02277 void L6470B::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) 02278 { 02279 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); 02280 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02281 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02282 } 02283 02284 /** 02285 * @brief GoHome command produces a motion to the HOME position (zero position) 02286 * via the shortest path. 02287 * 02288 */ 02289 void L6470B::L6470_GoHome(void) 02290 { 02291 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); 02292 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02293 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02294 } 02295 02296 /** 02297 * @brief GoMark command produces a motion to the MARK position performing the 02298 * minimum path. 02299 * 02300 */ 02301 void L6470B::L6470_GoMark(void) 02302 { 02303 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); 02304 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02305 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02306 } 02307 02308 /** 02309 * @brief ResetPos command resets the ABS_POS register to zero. 02310 * 02311 */ 02312 void L6470B::L6470_ResetPos(void) 02313 { 02314 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); 02315 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02316 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02317 } 02318 02319 /** 02320 * @brief ResetDevice command resets the device to power-up conditions. 02321 * 02322 */ 02323 void L6470B::L6470_ResetDevice(void) 02324 { 02325 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); 02326 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02327 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02328 } 02329 02330 /** 02331 * @brief SoftStop command causes an immediate deceleration to zero speed and 02332 * a consequent motor stop; the deceleration value used is the one stored 02333 * in the DEC register. 02334 * 02335 */ 02336 void L6470B::L6470_SoftStop(void) 02337 { 02338 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); 02339 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02340 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02341 } 02342 02343 /** 02344 * @brief HardStop command causes an immediate motor stop with infinite deceleration. 02345 * 02346 */ 02347 void L6470B::L6470_HardStop(void) 02348 { 02349 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); 02350 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02351 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02352 } 02353 02354 /** 02355 * @brief SoftHiZ command disables the power bridges (high impedance state) 02356 * after a deceleration to zero; the deceleration value used is the one 02357 * stored in the DEC register. 02358 * 02359 */ 02360 void L6470B::L6470_SoftHiZ(void) 02361 { 02362 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); 02363 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02364 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02365 } 02366 02367 /** 02368 * @brief HardHiZ command immediately disables the power bridges (high impedance state). 02369 * 02370 */ 02371 void L6470B::L6470_HardHiZ(void) 02372 { 02373 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); 02374 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02375 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02376 } 02377 02378 /** 02379 * @brief GetStatus command returns the STATUS register value. 02380 * 02381 * 02382 * @retval ReceivedValue The register value. 02383 */ 02384 uint16_t L6470B::L6470_GetStatus(void) 02385 { 02386 uint16_t ReceivedValue; 02387 02388 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); 02389 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02390 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02391 02392 ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2); 02393 02394 return ReceivedValue; 02395 } 02396 02397 /* End of L6470_AppCMDs */ 02398 02399 /** 02400 * @addtogroup L6470_AppCMDs_ToBePrepared 02401 * @{ 02402 */ 02403 02404 /** 02405 * @brief Prepare to send @ref L6470_SetParam command. 02406 * 02407 * @param L6470_RegId The identifier of the L6470 register to be addressed. 02408 * @param Value The new value. 02409 * 02410 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02411 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02412 */ 02413 void L6470B::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value) 02414 { 02415 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0); 02416 } 02417 02418 /** 02419 * @brief Prepare to send @ref L6470_GetParam command. 02420 * 02421 * @param L6470_Id The L6470 identifier inside the daisy chain. 02422 * @param L6470_RegId The identifier of the L6470 register to be addressed. 02423 * 02424 * @retval ReceivedValue The register value. 02425 * 02426 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02427 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02428 */ 02429 void L6470B::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId) 02430 { 02431 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0); 02432 } 02433 02434 /** 02435 * @brief Prepare to send @ref L6470_Run command. 02436 * 02437 * @param L6470_DirId The identifier of the L6470 motion direction. 02438 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 02439 * 02440 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02441 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02442 */ 02443 void L6470B::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed) 02444 { 02445 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0); 02446 } 02447 02448 /** 02449 * @brief Prepare to send @ref L6470_StepClock command. 02450 * 02451 * @param L6470_DirId The identifier of the L6470 motion direction. 02452 * 02453 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02454 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02455 */ 02456 void L6470B::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId) 02457 { 02458 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0); 02459 } 02460 02461 /** 02462 * @brief Prepare to send @ref L6470_Move command. 02463 * 02464 * @param L6470_DirId The identifier of the L6470 motion direction. 02465 * @param N_Step The number of microsteps. 02466 * 02467 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02468 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02469 */ 02470 void L6470B::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step) 02471 { 02472 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0); 02473 } 02474 02475 /** 02476 * @brief Prepare to send @ref L6470_GoTo command. 02477 * 02478 * @param AbsPos The target absolute position. 02479 * 02480 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02481 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02482 */ 02483 void L6470B::L6470_PrepareGoTo(uint32_t AbsPos) 02484 { 02485 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0); 02486 } 02487 02488 /** 02489 * @brief Prepare to send @ref L6470_GoToDIR command. 02490 * 02491 * @param L6470_DirId The identifier of the L6470 motion direction. 02492 * @param AbsPos The target absolute position. 02493 * 02494 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02495 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02496 */ 02497 void L6470B::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos) 02498 { 02499 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0); 02500 } 02501 02502 /** 02503 * @brief Prepare to send @ref L6470_GoUntil command. 02504 * 02505 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 02506 * @param L6470_DirId The identifier of the L6470 motion direction. 02507 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28) 02508 * 02509 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02510 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02511 */ 02512 void L6470B::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed) 02513 { 02514 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed); 02515 } 02516 02517 /** 02518 * @brief Prepare to send @ref L6470_ReleaseSW. 02519 * 02520 * @param L6470_ActId The identifier of the L6470 action about the absolute position. 02521 * @param L6470_DirId The identifier of the L6470 motion direction. 02522 * 02523 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02524 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02525 */ 02526 void L6470B::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId) 02527 { 02528 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0); 02529 } 02530 02531 /** 02532 * @brief Prepare to send @ref L6470_GoHome command. 02533 * 02534 * 02535 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02536 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02537 */ 02538 void L6470B::L6470_PrepareGoHome(void) 02539 { 02540 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0); 02541 } 02542 02543 /** 02544 * @brief Prepare to send @ref L6470_GoMark command. 02545 * 02546 * 02547 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02548 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02549 */ 02550 void L6470B::L6470_PrepareGoMark(void) 02551 { 02552 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0); 02553 } 02554 02555 /** 02556 * @brief Prepare to send @ref L6470_ResetPos command. 02557 * 02558 * 02559 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02560 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02561 */ 02562 void L6470B::L6470_PrepareResetPos(void) 02563 { 02564 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0); 02565 } 02566 02567 /** 02568 * @brief Prepare to send @ref L6470_ResetDevice command. 02569 * 02570 * 02571 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02572 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02573 */ 02574 void L6470B::L6470_PrepareResetDevice(void) 02575 { 02576 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0); 02577 } 02578 02579 /** 02580 * @brief Prepare to send @ref L6470_SoftStop command. 02581 * 02582 * 02583 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02584 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02585 */ 02586 void L6470B::L6470_PrepareSoftStop(void) 02587 { 02588 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0); 02589 } 02590 02591 /** 02592 * @brief Prepare to send @ref L6470_HardStop command. 02593 * 02594 * 02595 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02596 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02597 */ 02598 void L6470B::L6470_PrepareHardStop(void) 02599 { 02600 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0); 02601 } 02602 02603 /** 02604 * @brief Prepare to send @ref L6470_SoftHiZ command. 02605 * 02606 * 02607 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02608 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02609 */ 02610 void L6470B::L6470_PrepareSoftHiZ(void) 02611 { 02612 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0); 02613 } 02614 02615 /** 02616 * @brief Prepare to send @ref L6470_HardHiZ command. 02617 * 02618 * 02619 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02620 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02621 */ 02622 void L6470B::L6470_PrepareHardHiZ(void) 02623 { 02624 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0); 02625 } 02626 02627 /** 02628 * @brief Prepare to send @ref L6470_GetStatus command. 02629 * 02630 * 02631 * @note This function will properly fill the right column of the L6470_AppCmdPkg. 02632 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand. 02633 */ 02634 void L6470B::L6470_PrepareGetStatus(void) 02635 { 02636 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0); 02637 } 02638 02639 /* End of L6470_AppCMDs_ToBePrepared */ 02640 02641 /** 02642 * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the 02643 * L6470 daisy chain. 02644 * 02645 * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure 02646 * containing returned values from each L6470 of the daisy chain for each 02647 * sent SPI data. 02648 */ 02649 uint8_t* L6470B::L6470_PerformPreparedApplicationCommand(void) 02650 { 02651 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct); 02652 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct); 02653 02654 return (uint8_t*)(L6470_DaisyChainSpiRxStruct); 02655 } 02656 02657 /** 02658 * @brief Send command to the L6470 daisy chain via SPI 02659 * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470 02660 * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470 02661 */ 02662 void L6470B::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct) 02663 { 02664 uint8_t spibyte; 02665 02666 L6470_DaisyChain_HalfPrepared = ZERO_F; 02667 02668 /* Send all command bytes via SPI */ 02669 for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++) 02670 { 02671 /* Send the command via SPI */ 02672 L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10); 02673 02674 //_DELAY(TDISCS); 02675 uint8_t delay_cnt; 02676 for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS 02677 } 02678 } 02679 02680 /** 02681 * @brief Extracts the data returned by the L6470 from the matrix that 02682 * contains the received SPI data. 02683 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 02684 * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that 02685 * contains the received data by SPI from the L6470 daisy chain. 02686 * @param LengthByte The number of bytes about the received value. 02687 */ 02688 uint32_t L6470B::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte) 02689 { 02690 uint32_t value; 02691 uint8_t i; 02692 02693 value = 0x000000; 02694 for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++) 02695 { 02696 value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8); 02697 } 02698 02699 return value; 02700 } 02701 02702 /** 02703 * @brief Check the state of a flag inside the L6470 STATUS register. 02704 * 02705 * @param L6470_Id The identifier of the L6470 target inside the daisy chain. 02706 * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked. 02707 * 02708 * @retval state The flag state. 02709 */ 02710 02711 uint8_t L6470B::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId) 02712 { 02713 uint8_t state = 0; 02714 02715 *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID); 02716 02717 switch(L6470_StatusRegisterFlagId) 02718 { 02719 case HiZ_ID: 02720 state = pL6470_StatusRegister->HiZ; 02721 break; 02722 case BUSY_ID: 02723 state = pL6470_StatusRegister->BUSY; 02724 break; 02725 case SW_F_ID: 02726 state = pL6470_StatusRegister->SW_F; 02727 break; 02728 case SW_EVN_ID: 02729 state = pL6470_StatusRegister->SW_EVN; 02730 break; 02731 case DIR_ID: 02732 state = pL6470_StatusRegister->DIR; 02733 break; 02734 case MOT_STATUS_ID: 02735 state = pL6470_StatusRegister->MOT_STATUS; 02736 break; 02737 case NOTPERF_CMD_ID: 02738 state = pL6470_StatusRegister->NOTPERF_CMD; 02739 break; 02740 case WRONG_CMD_ID: 02741 state = pL6470_StatusRegister->WRONG_CMD; 02742 break; 02743 case UVLO_ID: 02744 state = pL6470_StatusRegister->UVLO; 02745 break; 02746 case TH_WRN_ID: 02747 state = pL6470_StatusRegister->TH_WRN; 02748 break; 02749 case TH_SD_ID: 02750 state = pL6470_StatusRegister->TH_SD; 02751 break; 02752 case OCD_ID: 02753 state = pL6470_StatusRegister->OCD; 02754 break; 02755 case STEP_LOSS_A_ID: 02756 state = pL6470_StatusRegister->STEP_LOSS_A; 02757 break; 02758 case STEP_LOSS_B_ID: 02759 state = pL6470_StatusRegister->STEP_LOSS_B; 02760 break; 02761 case SCK_MOD_ID: 02762 state = pL6470_StatusRegister->SCK_MOD; 02763 break; 02764 } 02765 02766 return state; 02767 } 02768 02769 /** 02770 * @brief Return the mnemonic name for the L6470 register. 02771 * @param id The identifier of the L6470 register. 02772 */ 02773 uint8_t *L6470B::L6470_GetRegisterName(uint8_t id) 02774 { 02775 if (id < L6470REGIDSIZE) 02776 { 02777 return (uint8_t*)L6470_Register[id].Name; 02778 } 02779 else 02780 { 02781 return NULL; 02782 } 02783 } 02784 02785 /** 02786 * @brief Configures the L6470 registers. 02787 * @param init The pointer to the initialization structure. 02788 */ 02789 status_t L6470B::L6470_Config(void *init) 02790 { 02791 /* Disable the L6470. */ 02792 L6470_DISABLE(); 02793 02794 /* Enable the L6470. */ 02795 L6470_ENABLE(); 02796 02797 /* Reset devices. */ 02798 reset_device(); 02799 02800 /* Reset Status Register flags. */ 02801 get_status(); 02802 02803 /* Prepare the 'Register' field of StepperMotorDriverHandle */ 02804 L6470_init_t *MotorParameterData = (L6470_init_t *) init; 02805 StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc); 02806 StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec); 02807 StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed); 02808 StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed); 02809 StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd); 02810 StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage))); 02811 StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage))); 02812 StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage))); 02813 StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage))); 02814 StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed); 02815 StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp); 02816 StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc); 02817 StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec); 02818 StepperMotorRegister.K_THERM = MotorParameterData->kterm; 02819 StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth); 02820 StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth); 02821 StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen; 02822 StepperMotorRegister.CONFIG = MotorParameterData->config; 02823 StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel; 02824 02825 /* Write the L6470 registers with the prepared data */ 02826 L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC); 02827 L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC); 02828 L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED); 02829 L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED); 02830 L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD); 02831 L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD); 02832 L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN); 02833 L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC); 02834 L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC); 02835 L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED); 02836 L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP); 02837 L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC); 02838 L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC); 02839 L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM); 02840 L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH); 02841 L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH); 02842 L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN); 02843 L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG); 02844 if (!set_step_mode((StepperMotor::step_mode_t) StepperMotorRegister.STEP_MODE)) 02845 return COMPONENT_ERROR; 02846 02847 return COMPONENT_OK; 02848 } 02849 02850 02851 02852 /* End of L6470_Exported_Functions */ 02853 02854 /* End of L6470 */ 02855 02856 /* End of Components */ 02857 02858 /* End of BSP */ 02859 02860 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu Jul 14 2022 04:29:28 by
1.7.2