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

Dependencies:   X_NUCLEO_COMMON ST_INTERFACES

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

Fork of X_NUCLEO_IHM02A1 by ST Expansion SW Team

Motor Control Library

Introduction

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

Daisy-Chain Configuration

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

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

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

Arduino Connector Compatibility Warning

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

To be fully Arduino compatible the following patch is required:

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

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

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

Example Applications

Committer:
Davidroid
Date:
Mon Feb 15 15:55:48 2016 +0000
Revision:
15:31785d1acd4b
Parent:
14:e614697ebf34
Child:
16:0d5be428b264
+ Updated some comments.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:92706998571a 1 /**
Davidroid 14:e614697ebf34 2 ******************************************************************************
Davidroid 14:e614697ebf34 3 * @file l6470_class.cpp
Davidroid 14:e614697ebf34 4 * @date 01/10/2014 12:00:00
Davidroid 14:e614697ebf34 5 * @brief This file provides set of firmware functions to manage the
Davidroid 14:e614697ebf34 6 * L6470.
Davidroid 14:e614697ebf34 7 ******************************************************************************
Davidroid 14:e614697ebf34 8 *
Davidroid 14:e614697ebf34 9 * COPYRIGHT(c) 2014 STMicroelectronics
Davidroid 14:e614697ebf34 10 *
Davidroid 14:e614697ebf34 11 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 14:e614697ebf34 12 * are permitted provided that the following conditions are met:
Davidroid 14:e614697ebf34 13 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 14:e614697ebf34 14 * this list of conditions and the following disclaimer.
Davidroid 14:e614697ebf34 15 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 14:e614697ebf34 16 * this list of conditions and the following disclaimer in the documentation
Davidroid 14:e614697ebf34 17 * and/or other materials provided with the distribution.
Davidroid 14:e614697ebf34 18 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 14:e614697ebf34 19 * may be used to endorse or promote products derived from this software
Davidroid 14:e614697ebf34 20 * without specific prior written permission.
Davidroid 14:e614697ebf34 21 *
Davidroid 14:e614697ebf34 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 14:e614697ebf34 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 14:e614697ebf34 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 14:e614697ebf34 25 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 14:e614697ebf34 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 14:e614697ebf34 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 14:e614697ebf34 28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 14:e614697ebf34 29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 14:e614697ebf34 30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 14:e614697ebf34 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 14:e614697ebf34 32 *
Davidroid 14:e614697ebf34 33 ******************************************************************************
Davidroid 14:e614697ebf34 34 */
Davidroid 0:92706998571a 35
Davidroid 0:92706998571a 36
Davidroid 15:31785d1acd4b 37 /* Generated with STM32CubeTOO -----------------------------------------------*/
Davidroid 0:92706998571a 38
Davidroid 0:92706998571a 39
Davidroid 0:92706998571a 40 /* Revision ------------------------------------------------------------------*/
Davidroid 0:92706998571a 41 /*
Davidroid 0:92706998571a 42 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
Davidroid 0:92706998571a 43 Branch/Trunk/Tag: trunk
Davidroid 0:92706998571a 44 Based on: X-CUBE-SPN2/trunk/Drivers/BSP/Components/L6470/L6470.c
Davidroid 6:c62aa608a493 45 Revision: 0
Davidroid 0:92706998571a 46 */
Davidroid 0:92706998571a 47
Davidroid 0:92706998571a 48
Davidroid 0:92706998571a 49 /* Includes ------------------------------------------------------------------*/
Davidroid 0:92706998571a 50
Davidroid 0:92706998571a 51 #include "l6470_class.h"
Davidroid 0:92706998571a 52 #include "l6470.h"
Davidroid 0:92706998571a 53
Davidroid 0:92706998571a 54
Davidroid 14:e614697ebf34 55 /* Variables -----------------------------------------------------------------*/
Davidroid 0:92706998571a 56
Davidroid 0:92706998571a 57 /* Number of instantiated devices on an expansion board. */
Davidroid 0:92706998571a 58 uint8_t L6470::number_of_devices = 0;
Davidroid 0:92706998571a 59
Davidroid 0:92706998571a 60 /* SPI Transmission for Daisy-Chain Configuration. */
Davidroid 0:92706998571a 61 eFlagStatus_t L6470::L6470_DaisyChain_HalfPrepared;
Davidroid 0:92706998571a 62 sL6470_AppCmdPkg_t L6470::L6470_AppCmdPkg[L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 63 uint8_t L6470::L6470_DaisyChainSpiTxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 64 uint8_t L6470::L6470_DaisyChainSpiRxStruct[L6470MAXSPICMDBYTESIZE][L6470DAISYCHAINSIZE];
Davidroid 0:92706998571a 65
Davidroid 0:92706998571a 66 /**
Davidroid 0:92706998571a 67 * @brief Array whose elements are a structure in which store information about
Davidroid 0:92706998571a 68 * the L6470 Registers (the address, the names, the length in bits, the
Davidroid 0:92706998571a 69 * reset value)
Davidroid 0:92706998571a 70 */
Davidroid 0:92706998571a 71 const sL6470_Register_t L6470::_L6470_Register[L6470REGIDSIZE] = {
Davidroid 0:92706998571a 72 {0x01 , "ABS_POS", 22, 3, 0x000000}, //!< Current position
Davidroid 0:92706998571a 73 {0x02 , "EL_POS", 9, 2, 0x000}, //!< Electrical position
Davidroid 0:92706998571a 74 {0x03 , "MARK", 22, 3, 0x000000}, //!< Mark position
Davidroid 0:92706998571a 75 {0x04 , "SPEED", 20, 3, 0x0000}, //!< Current speed
Davidroid 0:92706998571a 76 {0x05 , "ACC", 12, 2, 0x08A}, //!< Acceleration
Davidroid 0:92706998571a 77 {0x06 , "DEC", 12, 2, 0x08A}, //!< Deceleration
Davidroid 0:92706998571a 78 {0x07 , "MAX_SPEED", 10, 2, 0x041}, //!< Maximum speed
Davidroid 0:92706998571a 79 {0x08 , "MIN_SPEED", 13, 2, 0x000}, //!< Minimum speed
Davidroid 0:92706998571a 80 {0x15 , "FS_SPD", 10, 2, 0x027}, //!< Full-step speed
Davidroid 0:92706998571a 81 {0x09 , "KVAL_HOLD", 8, 1, 0x29}, //!< Holding KVAL
Davidroid 0:92706998571a 82 {0x0A , "KVAL_RUN", 8, 1, 0x29}, //!< Constant speed KVAL
Davidroid 0:92706998571a 83 {0x0B , "KVAL_ACC", 8, 1, 0x29}, //!< Acceleration starting KVAL
Davidroid 0:92706998571a 84 {0x0C , "KVAL_DEC", 8, 1, 0x29}, //!< Deceleration starting KVAL
Davidroid 0:92706998571a 85 {0x0D , "INT_SPEED", 14, 2, 0x0408}, //!< Intersect speed
Davidroid 0:92706998571a 86 {0x0E , "ST_SLP", 8, 1, 0x19}, //!< Start slope
Davidroid 0:92706998571a 87 {0x0F , "FN_SLP_ACC", 8, 1, 0x29}, //!< Acceleration final slope
Davidroid 0:92706998571a 88 {0x10 , "FN_SLP_DEC", 8, 1, 0x29}, //!< Deceleration final slope
Davidroid 0:92706998571a 89 {0x11 , "K_THERM", 4, 1, 0x0}, //!< Thermal compensation factor
Davidroid 0:92706998571a 90 {0x12 , "ADC_OUT", 5, 1, 0x00}, //!< ADC output, (the reset value is according to startup conditions)
Davidroid 0:92706998571a 91 {0x13 , "OCD_TH", 4, 1, 0x8}, //!< OCD threshold
Davidroid 0:92706998571a 92 {0x14 , "STALL_TH", 7, 1, 0x40}, //!< STALL threshold
Davidroid 0:92706998571a 93 {0x16 , "STEP_MODE", 8, 1, 0x7}, //!< Step mode
Davidroid 0:92706998571a 94 {0x17 , "ALARM_EN", 8, 1, 0xFF}, //!< Alarm enable
Davidroid 0:92706998571a 95 {0x18 , "CONFIG", 16, 2, 0x2E88}, //!< IC configuration
Davidroid 0:92706998571a 96 {0x19 , "STATUS", 16, 2, 0x0000} //!< Status, (the reset value is according to startup conditions)
Davidroid 0:92706998571a 97 };
Davidroid 0:92706998571a 98
Davidroid 0:92706998571a 99 /**
Davidroid 0:92706998571a 100 * @brief Array whose elements are a structure in which store information about
Davidroid 0:92706998571a 101 * the L6470 Application Commands (the mnemonic name, the number of
Davidroid 0:92706998571a 102 * needed parameters, the related funtion to call)
Davidroid 0:92706998571a 103 */
Davidroid 0:92706998571a 104 const sL6470_ApplicationCommand_t L6470::_L6470_ApplicationCommand[L6470APPCMDIDSIZE] = {
Davidroid 0:92706998571a 105 {"NOP", 0x00, 0},
Davidroid 0:92706998571a 106 {"SETPARAM", 0x00, 2},
Davidroid 0:92706998571a 107 {"GETPARAM", 0x20, 1},
Davidroid 0:92706998571a 108 {"RUN", 0x50, 2},
Davidroid 0:92706998571a 109 {"STEPCLOCK", 0x58, 1},
Davidroid 0:92706998571a 110 {"MOVE", 0x40, 2},
Davidroid 0:92706998571a 111 {"GOTO", 0x60, 1},
Davidroid 0:92706998571a 112 {"GOTO_DIR", 0x68, 2},
Davidroid 0:92706998571a 113 {"GOUNTIL", 0x82, 3},
Davidroid 0:92706998571a 114 {"RELEASESW", 0x92, 2},
Davidroid 0:92706998571a 115 {"GOHOME", 0x70, 0},
Davidroid 0:92706998571a 116 {"GOMARK", 0x78, 0},
Davidroid 0:92706998571a 117 {"RESETPOS", 0xD8, 0},
Davidroid 0:92706998571a 118 {"RESETDEVICE", 0xC0, 0},
Davidroid 0:92706998571a 119 {"SOFTSTOP", 0xB0, 0},
Davidroid 0:92706998571a 120 {"HARDSTOP", 0xB8, 0},
Davidroid 0:92706998571a 121 {"SOFTHIZ", 0xA0, 0},
Davidroid 0:92706998571a 122 {"HARDHIZ", 0xA8, 0},
Davidroid 0:92706998571a 123 {"GETSTATUS", 0xD0, 0}
Davidroid 0:92706998571a 124 };
Davidroid 0:92706998571a 125
Davidroid 0:92706998571a 126 /**
Davidroid 0:92706998571a 127 * @brief The mnemonic names for the L6470 direction
Davidroid 0:92706998571a 128 */
Davidroid 0:92706998571a 129 const sL6470_Direction_t L6470::_L6470_Direction[L6470DIRIDSIZE] = {
Davidroid 0:92706998571a 130 {"REV", 0x00}, //!< Reverse direction
Davidroid 0:92706998571a 131 {"FWD", 0x01} //!< Forward direction
Davidroid 0:92706998571a 132 };
Davidroid 0:92706998571a 133
Davidroid 0:92706998571a 134 /**
Davidroid 0:92706998571a 135 * @brief Action taken about ABS_POS register
Davidroid 0:92706998571a 136 */
Davidroid 0:92706998571a 137 const sL6470_ACT_t L6470::_L6470_ACT[L6470ACTIDSIZE] = {
Davidroid 0:92706998571a 138 {"RST", 0x00}, //!< ABS_POS register is reset
Davidroid 0:92706998571a 139 {"CPY", 0x01} //!< ABS_POS register value is copied into the MARK register
Davidroid 0:92706998571a 140 };
Davidroid 0:92706998571a 141
Davidroid 0:92706998571a 142 /* End of L6470_Private_Constants */
Davidroid 0:92706998571a 143
Davidroid 0:92706998571a 144 /**
Davidroid 0:92706998571a 145 * @defgroup L6470_Private_Variables
Davidroid 0:92706998571a 146 * @brief L6470 Private Variables.
Davidroid 0:92706998571a 147 * @{
Davidroid 0:92706998571a 148 */
Davidroid 0:92706998571a 149
Davidroid 0:92706998571a 150 /* End of L6470_Private_Variables */
Davidroid 0:92706998571a 151
Davidroid 0:92706998571a 152
Davidroid 0:92706998571a 153 /**
Davidroid 0:92706998571a 154 * @addtogroup L6470_Private_Functions
Davidroid 0:92706998571a 155 * @{
Davidroid 0:92706998571a 156 */
Davidroid 0:92706998571a 157
Davidroid 14:e614697ebf34 158
Davidroid 14:e614697ebf34 159 /* Methods -------------------------------------------------------------------*/
Davidroid 14:e614697ebf34 160
Davidroid 0:92706998571a 161 /**
Davidroid 0:92706998571a 162 * @brief Reset the structure used to store the identifier of the L6470
Davidroid 0:92706998571a 163 * application command and its the needed parameters.
Davidroid 0:92706998571a 164 * @param pL6470_AppCmdPkg The structure to be reset.
Davidroid 0:92706998571a 165 */
Davidroid 0:92706998571a 166 void L6470::L6470_ResetAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg)
Davidroid 0:92706998571a 167 {
Davidroid 0:92706998571a 168 uint8_t id;
Davidroid 0:92706998571a 169
Davidroid 0:92706998571a 170 for(id=0; id<L6470DAISYCHAINSIZE; id++)
Davidroid 0:92706998571a 171 {
Davidroid 0:92706998571a 172 (pL6470_AppCmdPkg+id)->L6470_AppCmdId=(eL6470_AppCmdId_t)0;
Davidroid 0:92706998571a 173 (pL6470_AppCmdPkg+id)->p1=0;
Davidroid 0:92706998571a 174 (pL6470_AppCmdPkg+id)->p2=0;
Davidroid 0:92706998571a 175 (pL6470_AppCmdPkg+id)->p3=0;
Davidroid 0:92706998571a 176 }
Davidroid 0:92706998571a 177 }
Davidroid 0:92706998571a 178
Davidroid 0:92706998571a 179 /**
Davidroid 0:92706998571a 180 * @brief Fill the structure used to store the identifier of the L6470
Davidroid 0:92706998571a 181 * application command and its the needed parameters.
Davidroid 0:92706998571a 182 * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
Davidroid 0:92706998571a 183 * @param pL6470_AppCmdPkg The structure to be filled.
Davidroid 0:92706998571a 184 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
Davidroid 0:92706998571a 185 * @param p1 The 1st parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 186 * @param p2 The 2nd parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 187 * @param p3 The 3rd parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 188 */
Davidroid 0:92706998571a 189 void L6470::L6470_FillAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
Davidroid 0:92706998571a 190 {
Davidroid 0:92706998571a 191 (pL6470_AppCmdPkg+L6470_Id)->L6470_AppCmdId = L6470_AppCmdId;
Davidroid 0:92706998571a 192 (pL6470_AppCmdPkg+L6470_Id)->p1 = p1;
Davidroid 0:92706998571a 193 (pL6470_AppCmdPkg+L6470_Id)->p2 = p2;
Davidroid 0:92706998571a 194 (pL6470_AppCmdPkg+L6470_Id)->p3 = p3;
Davidroid 0:92706998571a 195 }
Davidroid 0:92706998571a 196
Davidroid 0:92706998571a 197 /**
Davidroid 0:92706998571a 198 * @brief This function will fill the column of the L6470_AppCmdPkg related
Davidroid 0:92706998571a 199 * the L6470 to be addressed inside the daisy chain.
Davidroid 0:92706998571a 200 *
Davidroid 0:92706998571a 201 * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
Davidroid 0:92706998571a 202 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
Davidroid 0:92706998571a 203 * @param L6470_AppCmdId The identifier of the L6470 application command to be sent.
Davidroid 0:92706998571a 204 * @param p1 The 1st parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 205 * @param p2 The 2nd parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 206 * @param p3 The 3rd parameter (if it is not needed it will be not considered).
Davidroid 0:92706998571a 207 */
Davidroid 0:92706998571a 208 void L6470::L6470_PrepareAppCmdPkg(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, eL6470_AppCmdId_t L6470_AppCmdId, uint32_t p1, uint32_t p2, uint32_t p3)
Davidroid 0:92706998571a 209 {
Davidroid 0:92706998571a 210 if(!L6470_DaisyChain_HalfPrepared)
Davidroid 0:92706998571a 211 {
Davidroid 0:92706998571a 212 L6470_DaisyChain_HalfPrepared = ONE_F; /* To avoid to delete the previous entered command */
Davidroid 0:92706998571a 213 L6470_ResetAppCmdPkg(pL6470_AppCmdPkg);
Davidroid 0:92706998571a 214 }
Davidroid 0:92706998571a 215
Davidroid 0:92706998571a 216 L6470_FillAppCmdPkg(pL6470_AppCmdPkg, L6470_AppCmdId, p1, p2, p3);
Davidroid 0:92706998571a 217 }
Davidroid 0:92706998571a 218
Davidroid 0:92706998571a 219 /**
Davidroid 0:92706998571a 220 * @brief This function will translate the data inside the L6470_AppCmdPkg into
Davidroid 0:92706998571a 221 * the right data to be sent via SPI to the L6470 daisy chain.
Davidroid 0:92706998571a 222 *
Davidroid 0:92706998571a 223 * @param pL6470_AppCmdPkg Pointer to the sL6470_AppCmdPkg_t to be filled.
Davidroid 0:92706998571a 224 * @param pL6470_DaisyChainSpiTxStruct Pointer to the structure used by SPI to send the commands.
Davidroid 0:92706998571a 225 */
Davidroid 0:92706998571a 226 void L6470::L6470_PrepareDaisyChainCommand(sL6470_AppCmdPkg_t* pL6470_AppCmdPkg, uint8_t* pL6470_DaisyChainSpiTxStruct)
Davidroid 0:92706998571a 227 {
Davidroid 0:92706998571a 228 uint8_t PkgId;
Davidroid 0:92706998571a 229 uint8_t PARAMLengthBytes; /* The number of bytes related to the numeric value for the addressed register */
Davidroid 0:92706998571a 230 uint8_t spibyte;
Davidroid 0:92706998571a 231
Davidroid 0:92706998571a 232 /* Reset the structure used to send the command to the L6470 Daisy Chain through the SPI */
Davidroid 0:92706998571a 233 uint8_t i = 0;
Davidroid 0:92706998571a 234 for(spibyte=0;spibyte<L6470MAXSPICMDBYTESIZE;spibyte++)
Davidroid 0:92706998571a 235 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
Davidroid 0:92706998571a 236 *(pL6470_DaisyChainSpiTxStruct+(i++)) = 0x00;
Davidroid 0:92706998571a 237
Davidroid 0:92706998571a 238 for(PkgId=0; PkgId<L6470DAISYCHAINSIZE; PkgId++)
Davidroid 0:92706998571a 239 {
Davidroid 0:92706998571a 240 /* Build the 1st bytes to transmit with the binary code of the command */
Davidroid 0:92706998571a 241 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) = (L6470_ApplicationCommand[(pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId].BinaryCode);
Davidroid 0:92706998571a 242
Davidroid 0:92706998571a 243 /* Perform the related L6470_AppCmdId */
Davidroid 0:92706998571a 244 switch((pL6470_AppCmdPkg+PkgId)->L6470_AppCmdId)
Davidroid 0:92706998571a 245 {
Davidroid 0:92706998571a 246 case L6470_NOP_ID:
Davidroid 0:92706998571a 247 break;
Davidroid 0:92706998571a 248 case L6470_SETPARAM_ID:
Davidroid 0:92706998571a 249 /* Build the 1st bytes to transmit (PARAM) */
Davidroid 0:92706998571a 250 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
Davidroid 0:92706998571a 251
Davidroid 0:92706998571a 252 /* The length, in byte, of this register (PARAM) is... */
Davidroid 0:92706998571a 253 PARAMLengthBytes = L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].LengthByte;
Davidroid 0:92706998571a 254
Davidroid 0:92706998571a 255 /* Build the others bytes to transmit (VALUE) */
Davidroid 0:92706998571a 256 for (spibyte=1; spibyte<(PARAMLengthBytes+1); spibyte++)
Davidroid 0:92706998571a 257 {
Davidroid 0:92706998571a 258 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(PARAMLengthBytes-spibyte)));
Davidroid 0:92706998571a 259 }
Davidroid 0:92706998571a 260 break;
Davidroid 0:92706998571a 261 case L6470_GETPARAM_ID:
Davidroid 0:92706998571a 262 /* Build the 1st bytes to transmit (PARAM) */
Davidroid 0:92706998571a 263 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Register[((pL6470_AppCmdPkg+PkgId)->p1)].Address);
Davidroid 0:92706998571a 264 break;
Davidroid 0:92706998571a 265 case L6470_RUN_ID:
Davidroid 0:92706998571a 266 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 267 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
Davidroid 0:92706998571a 268
Davidroid 0:92706998571a 269 /* Build the others bytes to transmit (SPD) */
Davidroid 0:92706998571a 270 for (spibyte=1; spibyte<(3+1); spibyte++)
Davidroid 0:92706998571a 271 {
Davidroid 0:92706998571a 272 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
Davidroid 0:92706998571a 273 }
Davidroid 0:92706998571a 274 break;
Davidroid 0:92706998571a 275 case L6470_STEPCLOCK_ID:
Davidroid 0:92706998571a 276 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 277 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
Davidroid 0:92706998571a 278 break;
Davidroid 0:92706998571a 279 case L6470_MOVE_ID:
Davidroid 0:92706998571a 280 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 281 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
Davidroid 0:92706998571a 282
Davidroid 0:92706998571a 283 /* Build the others bytes to transmit (N_STEP) */
Davidroid 0:92706998571a 284 for (spibyte=1; spibyte<(3+1); spibyte++)
Davidroid 0:92706998571a 285 {
Davidroid 0:92706998571a 286 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
Davidroid 0:92706998571a 287 }
Davidroid 0:92706998571a 288 break;
Davidroid 0:92706998571a 289 case L6470_GOTO_ID:
Davidroid 0:92706998571a 290 /* Build the others bytes to transmit (ABS_POS) */
Davidroid 0:92706998571a 291 for (spibyte=1; spibyte<(3+1); spibyte++)
Davidroid 0:92706998571a 292 {
Davidroid 0:92706998571a 293 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p1) >> (8*(3-spibyte)));
Davidroid 0:92706998571a 294 }
Davidroid 0:92706998571a 295 break;
Davidroid 0:92706998571a 296 case L6470_GOTODIR_ID:
Davidroid 0:92706998571a 297 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 298 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode);
Davidroid 0:92706998571a 299
Davidroid 0:92706998571a 300 /* Build the others bytes to transmit (ABS_POS) */
Davidroid 0:92706998571a 301 for (spibyte=1; spibyte<(3+1); spibyte++)
Davidroid 0:92706998571a 302 {
Davidroid 0:92706998571a 303 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p2) >> (8*(3-spibyte)));
Davidroid 0:92706998571a 304 }
Davidroid 0:92706998571a 305 break;
Davidroid 0:92706998571a 306 case L6470_GOUNTIL_ID:
Davidroid 0:92706998571a 307 /* Build the 1st bytes to transmit (ACT) */
Davidroid 0:92706998571a 308 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
Davidroid 0:92706998571a 309 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 310 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
Davidroid 0:92706998571a 311
Davidroid 0:92706998571a 312 /* Build the others bytes to transmit (SPD) */
Davidroid 0:92706998571a 313 for (spibyte=1; spibyte<(3+1); spibyte++)
Davidroid 0:92706998571a 314 {
Davidroid 0:92706998571a 315 *(pL6470_DaisyChainSpiTxStruct+((spibyte*L6470DAISYCHAINSIZE)+PkgId)) = (uint8_t)(((pL6470_AppCmdPkg+PkgId)->p3) >> (8*(3-spibyte)));
Davidroid 0:92706998571a 316 }
Davidroid 0:92706998571a 317 break;
Davidroid 0:92706998571a 318 case L6470_RELEASESW_ID:
Davidroid 0:92706998571a 319 /* Build the 1st bytes to transmit (ACT) */
Davidroid 0:92706998571a 320 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= ((L6470_ACT[((pL6470_AppCmdPkg+PkgId)->p1)].BinaryCode)<<3);
Davidroid 0:92706998571a 321 /* Build the 1st bytes to transmit (DIR) */
Davidroid 0:92706998571a 322 *(pL6470_DaisyChainSpiTxStruct+((0*L6470DAISYCHAINSIZE)+PkgId)) |= (L6470_Direction[((pL6470_AppCmdPkg+PkgId)->p2)].BinaryCode);
Davidroid 0:92706998571a 323 break;
Davidroid 0:92706998571a 324 case L6470_GOHOME_ID:
Davidroid 0:92706998571a 325 break;
Davidroid 0:92706998571a 326 case L6470_GOMARK_ID:
Davidroid 0:92706998571a 327 break;
Davidroid 0:92706998571a 328 case L6470_RESETPOS_ID:
Davidroid 0:92706998571a 329 break;
Davidroid 0:92706998571a 330 case L6470_RESETDEVICE_ID:
Davidroid 0:92706998571a 331 break;
Davidroid 0:92706998571a 332 case L6470_SOFTSTOP_ID:
Davidroid 0:92706998571a 333 break;
Davidroid 0:92706998571a 334 case L6470_HARDSTOP_ID:
Davidroid 0:92706998571a 335 break;
Davidroid 0:92706998571a 336 case L6470_SOFTHIZ_ID:
Davidroid 0:92706998571a 337 break;
Davidroid 0:92706998571a 338 case L6470_HARDHIZ_ID:
Davidroid 0:92706998571a 339 break;
Davidroid 0:92706998571a 340 case L6470_GETSTATUS_ID:
Davidroid 0:92706998571a 341 break;
Davidroid 0:92706998571a 342 }
Davidroid 0:92706998571a 343 }
Davidroid 0:92706998571a 344 }
Davidroid 0:92706998571a 345
Davidroid 0:92706998571a 346 /* End of L6470_Private_Functions */
Davidroid 0:92706998571a 347
Davidroid 0:92706998571a 348 /**
Davidroid 0:92706998571a 349 * @addtogroup L6470_Exported_Functions
Davidroid 0:92706998571a 350 * @{
Davidroid 0:92706998571a 351 */
Davidroid 0:92706998571a 352
Davidroid 0:92706998571a 353 /**
Davidroid 0:92706998571a 354 * @addtogroup L6470_Conversion_Functions
Davidroid 0:92706998571a 355 * @brief The following functions act just on one driver inside the L6470
Davidroid 0:92706998571a 356 * daisy chain. The command is immediately sent.
Davidroid 0:92706998571a 357 * @{
Davidroid 0:92706998571a 358 */
Davidroid 0:92706998571a 359
Davidroid 0:92706998571a 360 /**
Davidroid 0:92706998571a 361 * @brief Convert the absolute position as 2's complement format into the signed number.
Davidroid 0:92706998571a 362 *
Davidroid 0:92706998571a 363 * @param AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
Davidroid 0:92706998571a 364 * @retval Position The position as signed number.
Davidroid 0:92706998571a 365 */
Davidroid 0:92706998571a 366 int32_t L6470::L6470_AbsPos_2_Position(uint32_t AbsPos)
Davidroid 0:92706998571a 367 {
Davidroid 0:92706998571a 368 if (AbsPos > L6470_MAX_POSITION)
Davidroid 0:92706998571a 369 return (AbsPos - (L6470_POSITION_RANGE + 1));
Davidroid 0:92706998571a 370 else
Davidroid 0:92706998571a 371 return AbsPos;
Davidroid 0:92706998571a 372 }
Davidroid 0:92706998571a 373
Davidroid 0:92706998571a 374 /**
Davidroid 0:92706998571a 375 * @brief Convert the position as signed number into absolute position as 2's complement format.
Davidroid 0:92706998571a 376 *
Davidroid 0:92706998571a 377 * @param Position The position as signed number.
Davidroid 0:92706998571a 378 * @retval AbsPos The absolute position in the range from [-(2^21)] to [+(2^21)-1].
Davidroid 0:92706998571a 379 */
Davidroid 0:92706998571a 380 uint32_t L6470::L6470_Position_2_AbsPos(int32_t Position)
Davidroid 0:92706998571a 381 {
Davidroid 0:92706998571a 382 if ((Position >= 0) && (Position <= L6470_MAX_POSITION))
Davidroid 0:92706998571a 383 return Position;
Davidroid 0:92706998571a 384 else
Davidroid 0:92706998571a 385 {
Davidroid 0:92706998571a 386 if ((Position >= L6470_MIN_POSITION) && (Position < 0))
Davidroid 0:92706998571a 387 return (Position + (L6470_POSITION_RANGE + 1));
Davidroid 0:92706998571a 388 else
Davidroid 0:92706998571a 389 return (L6470_POSITION_RANGE + 1); // OVF
Davidroid 0:92706998571a 390 }
Davidroid 0:92706998571a 391 }
Davidroid 0:92706998571a 392
Davidroid 0:92706998571a 393 /**
Davidroid 0:92706998571a 394 * @brief Convert the SPEED register value into step/s.
Davidroid 0:92706998571a 395 *
Davidroid 0:92706998571a 396 * @param Speed The SPEED register value.
Davidroid 0:92706998571a 397 * @retval step/s The speed as step/s.
Davidroid 0:92706998571a 398 */
Davidroid 0:92706998571a 399 float L6470::L6470_Speed_2_Step_s(uint32_t Speed)
Davidroid 0:92706998571a 400 {
Davidroid 0:92706998571a 401 return (Speed * ((float)14.9012e-3));
Davidroid 0:92706998571a 402 }
Davidroid 0:92706998571a 403
Davidroid 0:92706998571a 404 /**
Davidroid 0:92706998571a 405 * @brief Convert the speed as step/s into a right value for SPEED register.
Davidroid 0:92706998571a 406 *
Davidroid 0:92706998571a 407 * @param step/s The speed as step/s.
Davidroid 0:92706998571a 408 * @retval Speed The SPEED register value.
Davidroid 0:92706998571a 409 */
Davidroid 0:92706998571a 410 uint32_t L6470::L6470_Step_s_2_Speed(float Step_s)
Davidroid 0:92706998571a 411 {
Davidroid 0:92706998571a 412 if (Step_s <= (L6470_MAX_SPEED * ((float)14.9012e-3)))
Davidroid 0:92706998571a 413 return (uint32_t)(Step_s / ((float)14.9012e-3));
Davidroid 0:92706998571a 414 else
Davidroid 0:92706998571a 415 return 0; // Warning
Davidroid 0:92706998571a 416 }
Davidroid 0:92706998571a 417
Davidroid 0:92706998571a 418 /**
Davidroid 0:92706998571a 419 * @brief Convert the ACC register value into step/(s^2).
Davidroid 0:92706998571a 420 *
Davidroid 0:92706998571a 421 * @param Acc The ACC register value.
Davidroid 0:92706998571a 422 * @retval step/(s^2) The acceleration as step/(s^2).
Davidroid 0:92706998571a 423 */
Davidroid 0:92706998571a 424 float L6470::L6470_Acc_2_Step_s2(uint16_t Acc)
Davidroid 0:92706998571a 425 {
Davidroid 0:92706998571a 426 if (Acc <= L6470_MAX_ACC)
Davidroid 0:92706998571a 427 return (Acc * ((float)1.4552e1));
Davidroid 0:92706998571a 428 else
Davidroid 0:92706998571a 429 return 0; // Warning
Davidroid 0:92706998571a 430 }
Davidroid 0:92706998571a 431
Davidroid 0:92706998571a 432 /**
Davidroid 0:92706998571a 433 * @brief Convert the acceleartion as step/(s^2) into a right value for ACC register.
Davidroid 0:92706998571a 434 *
Davidroid 0:92706998571a 435 * @param step/(s^2) The acceleration as step/(s^2).
Davidroid 0:92706998571a 436 * @retval Acc The ACC register value.
Davidroid 0:92706998571a 437 */
Davidroid 0:92706998571a 438 uint16_t L6470::L6470_Step_s2_2_Acc(float Step_s2)
Davidroid 0:92706998571a 439 {
Davidroid 0:92706998571a 440 if (Step_s2 <= (L6470_MAX_ACC * ((float)1.4552e1)))
Davidroid 0:92706998571a 441 return (uint16_t)(Step_s2 / ((float)1.4552e1));
Davidroid 0:92706998571a 442 else
Davidroid 0:92706998571a 443 return 0; // Warning
Davidroid 0:92706998571a 444 }
Davidroid 0:92706998571a 445
Davidroid 0:92706998571a 446 /**
Davidroid 0:92706998571a 447 * @brief Convert the DEC register value into step/(s^2).
Davidroid 0:92706998571a 448 *
Davidroid 0:92706998571a 449 * @param Dec The DEC register value.
Davidroid 0:92706998571a 450 * @retval step/(s^2) The deceleration as step/(s^2).
Davidroid 0:92706998571a 451 */
Davidroid 0:92706998571a 452 float L6470::L6470_Dec_2_Step_s2(uint16_t Dec)
Davidroid 0:92706998571a 453 {
Davidroid 0:92706998571a 454 if (Dec <= L6470_MAX_DEC)
Davidroid 0:92706998571a 455 return (Dec * ((float)1.4552e1));
Davidroid 0:92706998571a 456 else
Davidroid 0:92706998571a 457 return 0; // Warning
Davidroid 0:92706998571a 458 }
Davidroid 0:92706998571a 459
Davidroid 0:92706998571a 460 /**
Davidroid 0:92706998571a 461 * @brief Convert the deceleration as step/(s^2) into a right value for DEC register.
Davidroid 0:92706998571a 462 *
Davidroid 0:92706998571a 463 * @param step/(s^2) The deceleration as step/(s^2).
Davidroid 0:92706998571a 464 * @retval Dec The DEC register value.
Davidroid 0:92706998571a 465 */
Davidroid 0:92706998571a 466 uint16_t L6470::L6470_Step_s2_2_Dec(float Step_s2)
Davidroid 0:92706998571a 467 {
Davidroid 0:92706998571a 468 if (Step_s2 <= (L6470_MAX_DEC * ((float)1.4552e1)))
Davidroid 0:92706998571a 469 return (uint16_t)(Step_s2 / ((float)1.4552e1));
Davidroid 0:92706998571a 470 else
Davidroid 0:92706998571a 471 return 0; // Warning
Davidroid 0:92706998571a 472 }
Davidroid 0:92706998571a 473
Davidroid 0:92706998571a 474 /**
Davidroid 0:92706998571a 475 * @brief Convert the MAX_SPEED register value into step/s.
Davidroid 0:92706998571a 476 *
Davidroid 0:92706998571a 477 * @param MaxSpeed The MAX_SPEED register value.
Davidroid 0:92706998571a 478 * @retval step/s The max speed as step/s.
Davidroid 0:92706998571a 479 */
Davidroid 0:92706998571a 480 float L6470::L6470_MaxSpeed_2_Step_s(uint16_t MaxSpeed)
Davidroid 0:92706998571a 481 {
Davidroid 0:92706998571a 482 if (MaxSpeed <= L6470_MAX_MAX_SPEED)
Davidroid 0:92706998571a 483 return (MaxSpeed * ((float)15.2588));
Davidroid 0:92706998571a 484 else
Davidroid 0:92706998571a 485 return 0; // Warning
Davidroid 0:92706998571a 486 }
Davidroid 0:92706998571a 487
Davidroid 0:92706998571a 488 /**
Davidroid 0:92706998571a 489 * @brief Convert the max speed as step/s into a right value for MAX_SPEED register.
Davidroid 0:92706998571a 490 *
Davidroid 0:92706998571a 491 * @param step/s The max speed as step/s.
Davidroid 0:92706998571a 492 * @retval MaxSpeed The MAX_SPEED register value.
Davidroid 0:92706998571a 493 */
Davidroid 0:92706998571a 494 uint16_t L6470::L6470_Step_s_2_MaxSpeed(float Step_s)
Davidroid 0:92706998571a 495 {
Davidroid 0:92706998571a 496 if (Step_s <= (L6470_MAX_MAX_SPEED * ((float)15.2588)))
Davidroid 0:92706998571a 497 return (uint16_t)(Step_s / ((float)15.2588));
Davidroid 0:92706998571a 498 else
Davidroid 0:92706998571a 499 return 0; // Warning
Davidroid 0:92706998571a 500 }
Davidroid 0:92706998571a 501
Davidroid 0:92706998571a 502 /**
Davidroid 0:92706998571a 503 * @brief Convert the MIN_SPEED register value into step/s.
Davidroid 0:92706998571a 504 *
Davidroid 0:92706998571a 505 * @param MinSpeed The MIN_SPEED register value.
Davidroid 0:92706998571a 506 * @retval step/s The min speed as step/s.
Davidroid 0:92706998571a 507 */
Davidroid 0:92706998571a 508 float L6470::L6470_MinSpeed_2_Step_s(uint16_t MinSpeed)
Davidroid 0:92706998571a 509 {
Davidroid 0:92706998571a 510 if (MinSpeed <= L6470_MAX_MIN_SPEED)
Davidroid 0:92706998571a 511 return (MinSpeed * ((float)238.4186e-3));
Davidroid 0:92706998571a 512 else
Davidroid 0:92706998571a 513 return 0; // Warning
Davidroid 0:92706998571a 514 }
Davidroid 0:92706998571a 515
Davidroid 0:92706998571a 516 /**
Davidroid 0:92706998571a 517 * @brief Convert the min speed as step/s into a right value for MIN_SPEED register.
Davidroid 0:92706998571a 518 *
Davidroid 0:92706998571a 519 * @param step/s The min speed as step/s.
Davidroid 0:92706998571a 520 * @retval MinSpeed The MIN_SPEED register value.
Davidroid 0:92706998571a 521 */
Davidroid 0:92706998571a 522 uint16_t L6470::L6470_Step_s_2_MinSpeed(float Step_s)
Davidroid 0:92706998571a 523 {
Davidroid 0:92706998571a 524 if (Step_s <= (L6470_MAX_MIN_SPEED * ((float)238.4186e-3)))
Davidroid 0:92706998571a 525 return (uint16_t)(Step_s / ((float)238.4186e-3));
Davidroid 0:92706998571a 526 else
Davidroid 0:92706998571a 527 return 0; // Warning
Davidroid 0:92706998571a 528 }
Davidroid 0:92706998571a 529
Davidroid 0:92706998571a 530 /**
Davidroid 0:92706998571a 531 * @brief Convert the FS_SPD register value into step/s.
Davidroid 0:92706998571a 532 *
Davidroid 0:92706998571a 533 * @param FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 534 * @retval step/s The full-step speed as step/s.
Davidroid 0:92706998571a 535 */
Davidroid 0:92706998571a 536 float L6470::L6470_FsSpd_2_Step_s(uint16_t FsSpd)
Davidroid 0:92706998571a 537 {
Davidroid 0:92706998571a 538 if (FsSpd <= L6470_MAX_FS_SPD)
Davidroid 0:92706998571a 539 return ((FsSpd+0.5) * ((float)15.25));
Davidroid 0:92706998571a 540 else
Davidroid 0:92706998571a 541 return 0; // Warning
Davidroid 0:92706998571a 542 }
Davidroid 0:92706998571a 543
Davidroid 0:92706998571a 544 /**
Davidroid 0:92706998571a 545 * @brief Convert the full-step speed as step/s into a right value for FS_SPD register.
Davidroid 0:92706998571a 546 *
Davidroid 0:92706998571a 547 * @param step/s The full-step speed as step/s.
Davidroid 0:92706998571a 548 * @retval FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 549 */
Davidroid 0:92706998571a 550 uint16_t L6470::L6470_Step_s_2_FsSpd(float Step_s)
Davidroid 0:92706998571a 551 {
Davidroid 0:92706998571a 552 if (Step_s <= ((L6470_MAX_FS_SPD+0.5) * ((float)15.25)))
Davidroid 0:92706998571a 553 return (uint16_t)((float)(Step_s / ((float)15.25)) - (float)0.5);
Davidroid 0:92706998571a 554 else
Davidroid 0:92706998571a 555 return 0; // Warning
Davidroid 0:92706998571a 556 }
Davidroid 0:92706998571a 557
Davidroid 0:92706998571a 558 /**
Davidroid 0:92706998571a 559 * @brief Convert the INT_SPEED register value into step/s.
Davidroid 0:92706998571a 560 *
Davidroid 0:92706998571a 561 * @param IntSpeed The INT_SPEED register value.
Davidroid 0:92706998571a 562 * @retval step/s The intersect speed as step/s.
Davidroid 0:92706998571a 563 */
Davidroid 0:92706998571a 564 float L6470::L6470_IntSpeed_2_Step_s(uint16_t IntSpeed)
Davidroid 0:92706998571a 565 {
Davidroid 0:92706998571a 566 if (IntSpeed <= L6470_MAX_INT_SPEED)
Davidroid 0:92706998571a 567 return (IntSpeed * ((float)59.6046e-3));
Davidroid 0:92706998571a 568 else
Davidroid 0:92706998571a 569 return 0; // Warning
Davidroid 0:92706998571a 570 }
Davidroid 0:92706998571a 571
Davidroid 0:92706998571a 572 /**
Davidroid 0:92706998571a 573 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
Davidroid 0:92706998571a 574 *
Davidroid 0:92706998571a 575 * @param step/s The full-step speed as step/s.
Davidroid 0:92706998571a 576 * @retval FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 577 */
Davidroid 0:92706998571a 578 uint16_t L6470::L6470_Step_s_2_IntSpeed(float Step_s)
Davidroid 0:92706998571a 579 {
Davidroid 0:92706998571a 580 if (Step_s <= (L6470_MAX_INT_SPEED * ((float)59.6046e-3)))
Davidroid 0:92706998571a 581 return (uint16_t)(Step_s / ((float)59.6046e-3));
Davidroid 0:92706998571a 582 else
Davidroid 0:92706998571a 583 return 0; // Warning
Davidroid 0:92706998571a 584 }
Davidroid 0:92706998571a 585
Davidroid 0:92706998571a 586 /**
Davidroid 0:92706998571a 587 * @brief Convert the ST_SLP register value into s/step.
Davidroid 0:92706998571a 588 *
Davidroid 0:92706998571a 589 * @param StartSlope The ST_SLP register value.
Davidroid 0:92706998571a 590 * @retval s/step The start slope as s/step.
Davidroid 0:92706998571a 591 */
Davidroid 0:92706998571a 592 float L6470::L6470_StSlp_2_s_Step(uint8_t StSlp)
Davidroid 0:92706998571a 593 {
Davidroid 0:92706998571a 594 // if (StSlp <= L6470_MAX_ST_SLP)
Davidroid 0:92706998571a 595 return (StSlp * ((float)1.5686e-5));
Davidroid 0:92706998571a 596 // else
Davidroid 0:92706998571a 597 // return 0; // Warning
Davidroid 0:92706998571a 598 }
Davidroid 0:92706998571a 599
Davidroid 0:92706998571a 600 /**
Davidroid 0:92706998571a 601 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
Davidroid 0:92706998571a 602 *
Davidroid 0:92706998571a 603 * @param step/s The full-step speed as step/s.
Davidroid 0:92706998571a 604 * @retval FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 605 */
Davidroid 0:92706998571a 606 uint8_t L6470::L6470_s_Step_2_StSlp(float s_Step)
Davidroid 0:92706998571a 607 {
Davidroid 0:92706998571a 608 if (s_Step <= (L6470_MAX_ST_SLP * ((float)1.5686e-5)))
Davidroid 0:92706998571a 609 return (uint8_t)(s_Step / ((float)1.5686e-5));
Davidroid 0:92706998571a 610 else
Davidroid 0:92706998571a 611 return 0; // Warning
Davidroid 0:92706998571a 612 }
Davidroid 0:92706998571a 613
Davidroid 0:92706998571a 614 /**
Davidroid 0:92706998571a 615 * @brief Convert the INT_SPEED register value into step/s.
Davidroid 0:92706998571a 616 *
Davidroid 0:92706998571a 617 * @param IntSpeed The INT_SPEED register value.
Davidroid 0:92706998571a 618 * @retval step/s The intersect speed as step/s.
Davidroid 0:92706998571a 619 */
Davidroid 0:92706998571a 620 float L6470::L6470_FnSlpAcc_2_s_Step(uint8_t FnSlpAcc)
Davidroid 0:92706998571a 621 {
Davidroid 0:92706998571a 622 // if (FnSlpAcc <= L6470_MAX_FN_SLP_ACC)
Davidroid 0:92706998571a 623 return (FnSlpAcc * ((float)1.5686e-5));
Davidroid 0:92706998571a 624 // else
Davidroid 0:92706998571a 625 // return 0; // Warning
Davidroid 0:92706998571a 626 }
Davidroid 0:92706998571a 627
Davidroid 0:92706998571a 628 /**
Davidroid 0:92706998571a 629 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
Davidroid 0:92706998571a 630 *
Davidroid 0:92706998571a 631 * @param step/s The full-step speed as step/s.
Davidroid 0:92706998571a 632 * @retval FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 633 */
Davidroid 0:92706998571a 634 uint8_t L6470::L6470_s_Step_2_FnSlpAcc(float s_Step)
Davidroid 0:92706998571a 635 {
Davidroid 0:92706998571a 636 if (s_Step <= (L6470_MAX_FN_SLP_ACC * ((float)1.5686e-5)))
Davidroid 0:92706998571a 637 return (uint8_t)(s_Step / ((float)1.5686e-5));
Davidroid 0:92706998571a 638 else
Davidroid 0:92706998571a 639 return 0; // Warning
Davidroid 0:92706998571a 640 }
Davidroid 0:92706998571a 641
Davidroid 0:92706998571a 642 /**
Davidroid 0:92706998571a 643 * @brief Convert the INT_SPEED register value into step/s.
Davidroid 0:92706998571a 644 *
Davidroid 0:92706998571a 645 * @param IntSpeed The INT_SPEED register value.
Davidroid 0:92706998571a 646 * @retval step/s The intersect speed as step/s.
Davidroid 0:92706998571a 647 */
Davidroid 0:92706998571a 648 float L6470::L6470_FnSlpDec_2_s_Step(uint8_t FnSlpDec)
Davidroid 0:92706998571a 649 {
Davidroid 0:92706998571a 650 // if (FnSlpDec <= L6470_MAX_FN_SLP_DEC)
Davidroid 0:92706998571a 651 return (FnSlpDec * ((float)1.5686e-5));
Davidroid 0:92706998571a 652 // else
Davidroid 0:92706998571a 653 // return 0; // Warning
Davidroid 0:92706998571a 654 }
Davidroid 0:92706998571a 655
Davidroid 0:92706998571a 656 /**
Davidroid 0:92706998571a 657 * @brief Convert the intersect speed as step/s into a right value for INT_SPEED register.
Davidroid 0:92706998571a 658 *
Davidroid 0:92706998571a 659 * @param step/s The full-step speed as step/s.
Davidroid 0:92706998571a 660 * @retval FsSpd The FS_SPD register value.
Davidroid 0:92706998571a 661 */
Davidroid 0:92706998571a 662 uint8_t L6470::L6470_s_Step_2_FnSlpDec(float s_Step)
Davidroid 0:92706998571a 663 {
Davidroid 0:92706998571a 664 if (s_Step <= (L6470_MAX_FN_SLP_DEC * ((float)1.5686e-5)))
Davidroid 0:92706998571a 665 return (uint8_t)(s_Step / ((float)1.5686e-5));
Davidroid 0:92706998571a 666 else
Davidroid 0:92706998571a 667 return 0; // Warning
Davidroid 0:92706998571a 668 }
Davidroid 0:92706998571a 669
Davidroid 0:92706998571a 670 /**
Davidroid 0:92706998571a 671 * @brief Convert the OCD_TH register value into mA.
Davidroid 0:92706998571a 672 *
Davidroid 0:92706998571a 673 * @param OcdTh The OCD_TH register value.
Davidroid 0:92706998571a 674 * @retval mA The overcurrent threshold as mA.
Davidroid 0:92706998571a 675 */
Davidroid 0:92706998571a 676 float L6470::L6470_OcdTh_2_mA(uint8_t OcdTh)
Davidroid 0:92706998571a 677 {
Davidroid 0:92706998571a 678 if (OcdTh <= L6470_MAX_OCD_TH)
Davidroid 0:92706998571a 679 return ((OcdTh+1) * ((float)375));
Davidroid 0:92706998571a 680 else
Davidroid 0:92706998571a 681 return 0; // Warning
Davidroid 0:92706998571a 682 }
Davidroid 0:92706998571a 683
Davidroid 0:92706998571a 684 /**
Davidroid 0:92706998571a 685 * @brief Convert the overcurrent threshold as mA into a right value for OCD_TH register.
Davidroid 0:92706998571a 686 *
Davidroid 0:92706998571a 687 * @param mA The overcurrent threshold as mA.
Davidroid 0:92706998571a 688 * @retval OcdTh The OCD_TH register value.
Davidroid 0:92706998571a 689 */
Davidroid 0:92706998571a 690 uint8_t L6470::L6470_mA_2_OcdTh(float mA)
Davidroid 0:92706998571a 691 {
Davidroid 0:92706998571a 692 float result, decimal;
Davidroid 0:92706998571a 693
Davidroid 0:92706998571a 694 if (mA <= ((L6470_MAX_OCD_TH+1) * ((float)375)))
Davidroid 0:92706998571a 695 {
Davidroid 0:92706998571a 696 result = (mA / ((float)375));
Davidroid 0:92706998571a 697 decimal = result - (uint8_t)result;
Davidroid 0:92706998571a 698
Davidroid 0:92706998571a 699 if (decimal < (float)0.5)
Davidroid 0:92706998571a 700 return ((uint8_t)result - 1);
Davidroid 0:92706998571a 701 else
Davidroid 0:92706998571a 702 return ((uint8_t)result);
Davidroid 0:92706998571a 703 }
Davidroid 0:92706998571a 704 else
Davidroid 0:92706998571a 705 return 0; // Warning
Davidroid 0:92706998571a 706 }
Davidroid 0:92706998571a 707
Davidroid 0:92706998571a 708 /**
Davidroid 0:92706998571a 709 * @brief Convert the STALL_TH register value into mA.
Davidroid 0:92706998571a 710 *
Davidroid 0:92706998571a 711 * @param StallTh The STALL_TH register value.
Davidroid 0:92706998571a 712 * @retval mA The stall detection threshold as mA.
Davidroid 0:92706998571a 713 */
Davidroid 0:92706998571a 714 float L6470::L6470_StallTh_2_mA(uint8_t StallTh)
Davidroid 0:92706998571a 715 {
Davidroid 0:92706998571a 716 if (StallTh <= L6470_MAX_STALL_TH)
Davidroid 0:92706998571a 717 return ((StallTh+1) * ((float)31.25));
Davidroid 0:92706998571a 718 else
Davidroid 0:92706998571a 719 return 0; // Warning
Davidroid 0:92706998571a 720 }
Davidroid 0:92706998571a 721
Davidroid 0:92706998571a 722 /**
Davidroid 0:92706998571a 723 * @brief Convert the stall detection threshold as mA into a right value for STALL_TH register.
Davidroid 0:92706998571a 724 *
Davidroid 0:92706998571a 725 * @param mA The stall detection threshold as mA.
Davidroid 0:92706998571a 726 * @retval StallTh The STALL_TH register value.
Davidroid 0:92706998571a 727 */
Davidroid 0:92706998571a 728 uint8_t L6470::L6470_mA_2_StallTh(float mA)
Davidroid 0:92706998571a 729 {
Davidroid 0:92706998571a 730 float result, decimal;
Davidroid 0:92706998571a 731
Davidroid 0:92706998571a 732 if (mA <= ((L6470_MAX_STALL_TH+1) * ((float)31.25)))
Davidroid 0:92706998571a 733 {
Davidroid 0:92706998571a 734 result = (mA / ((float)31.25));
Davidroid 0:92706998571a 735 decimal = result - (uint8_t)result;
Davidroid 0:92706998571a 736
Davidroid 0:92706998571a 737 if (decimal < (float)0.5)
Davidroid 0:92706998571a 738 return ((uint8_t)result - 1);
Davidroid 0:92706998571a 739 else
Davidroid 0:92706998571a 740 return ((uint8_t)result);
Davidroid 0:92706998571a 741 }
Davidroid 0:92706998571a 742 else
Davidroid 0:92706998571a 743 return 0; // Warning
Davidroid 0:92706998571a 744 }
Davidroid 0:92706998571a 745
Davidroid 0:92706998571a 746 /* End of L6470_Conversion_Functions */
Davidroid 0:92706998571a 747
Davidroid 0:92706998571a 748 /**
Davidroid 0:92706998571a 749 * @addtogroup L6470_AppCMDs
Davidroid 0:92706998571a 750 * @{
Davidroid 0:92706998571a 751 */
Davidroid 0:92706998571a 752
Davidroid 0:92706998571a 753 /**
Davidroid 0:92706998571a 754 * @brief SetParam command sets the register value equal to a new value.
Davidroid 0:92706998571a 755 *
Davidroid 0:92706998571a 756 * @param L6470_RegId The identifier of the L6470 register to be addressed.
Davidroid 0:92706998571a 757 * @param Value The new value.
Davidroid 0:92706998571a 758 */
Davidroid 0:92706998571a 759 void L6470::L6470_SetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
Davidroid 0:92706998571a 760 {
Davidroid 0:92706998571a 761 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
Davidroid 0:92706998571a 762 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 763 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 764 }
Davidroid 0:92706998571a 765
Davidroid 0:92706998571a 766 /**
Davidroid 0:92706998571a 767 * @brief GetParam command reads the register value.
Davidroid 0:92706998571a 768 *
Davidroid 0:92706998571a 769 * @param L6470_RegId The identifier of the L6470 register to be addressed.
Davidroid 0:92706998571a 770 *
Davidroid 0:92706998571a 771 * @retval ReceivedValue The register value.
Davidroid 0:92706998571a 772 */
Davidroid 0:92706998571a 773 uint32_t L6470::L6470_GetParam(eL6470_RegId_t L6470_RegId)
Davidroid 0:92706998571a 774 {
Davidroid 0:92706998571a 775 uint8_t ValueLengthByte;
Davidroid 0:92706998571a 776 uint32_t ReceivedValue;
Davidroid 0:92706998571a 777
Davidroid 0:92706998571a 778 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
Davidroid 0:92706998571a 779 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 780 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 781
Davidroid 0:92706998571a 782 ValueLengthByte = L6470_Register[L6470_RegId].LengthByte;
Davidroid 0:92706998571a 783
Davidroid 0:92706998571a 784 ReceivedValue = L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, ValueLengthByte);
Davidroid 0:92706998571a 785
Davidroid 0:92706998571a 786 return ReceivedValue;
Davidroid 0:92706998571a 787 }
Davidroid 0:92706998571a 788
Davidroid 0:92706998571a 789 /**
Davidroid 0:92706998571a 790 * @brief Run command produces a motion at fixed speed.
Davidroid 0:92706998571a 791 *
Davidroid 0:92706998571a 792 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 793 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
Davidroid 0:92706998571a 794 */
Davidroid 0:92706998571a 795 void L6470::L6470_Run(eL6470_DirId_t L6470_DirId, uint32_t Speed)
Davidroid 0:92706998571a 796 {
Davidroid 0:92706998571a 797 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
Davidroid 0:92706998571a 798 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 799 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 800 }
Davidroid 0:92706998571a 801
Davidroid 0:92706998571a 802 /**
Davidroid 0:92706998571a 803 * @brief StepClock command switches the device in Step-clock mode.
Davidroid 0:92706998571a 804 *
Davidroid 0:92706998571a 805 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 806 */
Davidroid 0:92706998571a 807 void L6470::L6470_StepClock(eL6470_DirId_t L6470_DirId)
Davidroid 0:92706998571a 808 {
Davidroid 0:92706998571a 809 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
Davidroid 0:92706998571a 810 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 811 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 812 }
Davidroid 0:92706998571a 813
Davidroid 0:92706998571a 814 /**
Davidroid 0:92706998571a 815 * @brief Move command produces a motion of N_STEP microsteps.
Davidroid 0:92706998571a 816 *
Davidroid 0:92706998571a 817 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 818 * @param N_Step The number of microsteps.
Davidroid 0:92706998571a 819 */
Davidroid 0:92706998571a 820 void L6470::L6470_Move(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
Davidroid 0:92706998571a 821 {
Davidroid 0:92706998571a 822 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
Davidroid 0:92706998571a 823 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 824 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 825 }
Davidroid 0:92706998571a 826
Davidroid 0:92706998571a 827 /**
Davidroid 0:92706998571a 828 * @brief GoTo command produces a motion to ABS_POS absolute position through the shortest path.
Davidroid 0:92706998571a 829 *
Davidroid 0:92706998571a 830 * @param AbsPos The target absolute position.
Davidroid 0:92706998571a 831 */
Davidroid 0:92706998571a 832 void L6470::L6470_GoTo(uint32_t AbsPos)
Davidroid 0:92706998571a 833 {
Davidroid 0:92706998571a 834 if (AbsPos <= L6470_POSITION_RANGE)
Davidroid 0:92706998571a 835 {
Davidroid 0:92706998571a 836 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
Davidroid 0:92706998571a 837 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 838 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 839 }
Davidroid 0:92706998571a 840 }
Davidroid 0:92706998571a 841
Davidroid 0:92706998571a 842 /**
Davidroid 0:92706998571a 843 * @brief GoTo_DIR command produces a motion to ABS_POS absolute position imposing a direction.
Davidroid 0:92706998571a 844 *
Davidroid 0:92706998571a 845 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 846 * @param AbsPos The target absolute position.
Davidroid 0:92706998571a 847 */
Davidroid 0:92706998571a 848 void L6470::L6470_GoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
Davidroid 0:92706998571a 849 {
Davidroid 0:92706998571a 850 if (AbsPos <= L6470_POSITION_RANGE)
Davidroid 0:92706998571a 851 {
Davidroid 0:92706998571a 852 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
Davidroid 0:92706998571a 853 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 854 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 855 }
Davidroid 0:92706998571a 856 }
Davidroid 0:92706998571a 857
Davidroid 0:92706998571a 858 /**
Davidroid 0:92706998571a 859 * @brief GoUntil command produces a motion at fixed speed imposing a direction
Davidroid 0:92706998571a 860 * until an external switch turn-on event occurs.
Davidroid 0:92706998571a 861 *
Davidroid 0:92706998571a 862 * @param L6470_ActId The identifier of the L6470 action about the absolute position.
Davidroid 0:92706998571a 863 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 864 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
Davidroid 0:92706998571a 865 */
Davidroid 0:92706998571a 866 void L6470::L6470_GoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
Davidroid 0:92706998571a 867 {
Davidroid 0:92706998571a 868 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
Davidroid 0:92706998571a 869 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 870 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 871 }
Davidroid 0:92706998571a 872
Davidroid 0:92706998571a 873 /**
Davidroid 0:92706998571a 874 * @brief ReleaseSW command produces a motion at minimum speed imposing a direction
Davidroid 0:92706998571a 875 * until SW is released.
Davidroid 0:92706998571a 876 *
Davidroid 0:92706998571a 877 * @param L6470_ActId The identifier of the L6470 action about the absolute position.
Davidroid 0:92706998571a 878 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 879 */
Davidroid 0:92706998571a 880 void L6470::L6470_ReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
Davidroid 0:92706998571a 881 {
Davidroid 0:92706998571a 882 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
Davidroid 0:92706998571a 883 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 884 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 885 }
Davidroid 0:92706998571a 886
Davidroid 0:92706998571a 887 /**
Davidroid 0:92706998571a 888 * @brief GoHome command produces a motion to the HOME position (zero position)
Davidroid 0:92706998571a 889 * via the shortest path.
Davidroid 0:92706998571a 890 *
Davidroid 0:92706998571a 891 */
Davidroid 0:92706998571a 892 void L6470::L6470_GoHome(void)
Davidroid 0:92706998571a 893 {
Davidroid 0:92706998571a 894 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
Davidroid 0:92706998571a 895 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 896 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 897 }
Davidroid 0:92706998571a 898
Davidroid 0:92706998571a 899 /**
Davidroid 0:92706998571a 900 * @brief GoMark command produces a motion to the MARK position performing the
Davidroid 0:92706998571a 901 * minimum path.
Davidroid 0:92706998571a 902 *
Davidroid 0:92706998571a 903 */
Davidroid 0:92706998571a 904 void L6470::L6470_GoMark(void)
Davidroid 0:92706998571a 905 {
Davidroid 0:92706998571a 906 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
Davidroid 0:92706998571a 907 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 908 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 909 }
Davidroid 0:92706998571a 910
Davidroid 0:92706998571a 911 /**
Davidroid 0:92706998571a 912 * @brief ResetPos command resets the ABS_POS register to zero.
Davidroid 0:92706998571a 913 *
Davidroid 0:92706998571a 914 */
Davidroid 0:92706998571a 915 void L6470::L6470_ResetPos(void)
Davidroid 0:92706998571a 916 {
Davidroid 0:92706998571a 917 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
Davidroid 0:92706998571a 918 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 919 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 920 }
Davidroid 0:92706998571a 921
Davidroid 0:92706998571a 922 /**
Davidroid 0:92706998571a 923 * @brief ResetDevice command resets the device to power-up conditions.
Davidroid 0:92706998571a 924 *
Davidroid 0:92706998571a 925 */
Davidroid 0:92706998571a 926 void L6470::L6470_ResetDevice(void)
Davidroid 0:92706998571a 927 {
Davidroid 0:92706998571a 928 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
Davidroid 0:92706998571a 929 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 930 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 931 }
Davidroid 0:92706998571a 932
Davidroid 0:92706998571a 933 /**
Davidroid 0:92706998571a 934 * @brief SoftStop command causes an immediate deceleration to zero speed and
Davidroid 0:92706998571a 935 * a consequent motor stop; the deceleration value used is the one stored
Davidroid 0:92706998571a 936 * in the DEC register.
Davidroid 0:92706998571a 937 *
Davidroid 0:92706998571a 938 */
Davidroid 0:92706998571a 939 void L6470::L6470_SoftStop(void)
Davidroid 0:92706998571a 940 {
Davidroid 0:92706998571a 941 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
Davidroid 0:92706998571a 942 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 943 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 944 }
Davidroid 0:92706998571a 945
Davidroid 0:92706998571a 946 /**
Davidroid 0:92706998571a 947 * @brief HardStop command causes an immediate motor stop with infinite deceleration.
Davidroid 0:92706998571a 948 *
Davidroid 0:92706998571a 949 */
Davidroid 0:92706998571a 950 void L6470::L6470_HardStop(void)
Davidroid 0:92706998571a 951 {
Davidroid 0:92706998571a 952 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
Davidroid 0:92706998571a 953 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 954 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 955 }
Davidroid 0:92706998571a 956
Davidroid 0:92706998571a 957 /**
Davidroid 0:92706998571a 958 * @brief SoftHiZ command disables the power bridges (high impedance state)
Davidroid 0:92706998571a 959 * after a deceleration to zero; the deceleration value used is the one
Davidroid 0:92706998571a 960 * stored in the DEC register.
Davidroid 0:92706998571a 961 *
Davidroid 0:92706998571a 962 */
Davidroid 0:92706998571a 963 void L6470::L6470_SoftHiZ(void)
Davidroid 0:92706998571a 964 {
Davidroid 0:92706998571a 965 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
Davidroid 0:92706998571a 966 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 967 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 968 }
Davidroid 0:92706998571a 969
Davidroid 0:92706998571a 970 /**
Davidroid 0:92706998571a 971 * @brief HardHiZ command immediately disables the power bridges (high impedance state).
Davidroid 0:92706998571a 972 *
Davidroid 0:92706998571a 973 */
Davidroid 0:92706998571a 974 void L6470::L6470_HardHiZ(void)
Davidroid 0:92706998571a 975 {
Davidroid 0:92706998571a 976 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
Davidroid 0:92706998571a 977 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 978 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 979 }
Davidroid 0:92706998571a 980
Davidroid 0:92706998571a 981 /**
Davidroid 0:92706998571a 982 * @brief GetStatus command returns the STATUS register value.
Davidroid 0:92706998571a 983 *
Davidroid 0:92706998571a 984 *
Davidroid 0:92706998571a 985 * @retval ReceivedValue The register value.
Davidroid 0:92706998571a 986 */
Davidroid 0:92706998571a 987 uint16_t L6470::L6470_GetStatus(void)
Davidroid 0:92706998571a 988 {
Davidroid 0:92706998571a 989 uint16_t ReceivedValue;
Davidroid 0:92706998571a 990
Davidroid 0:92706998571a 991 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
Davidroid 0:92706998571a 992 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 993 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 994
Davidroid 0:92706998571a 995 ReceivedValue = (uint16_t)L6470_ExtractReturnedData((uint8_t*)L6470_DaisyChainSpiRxStruct, 2);
Davidroid 0:92706998571a 996
Davidroid 0:92706998571a 997 return ReceivedValue;
Davidroid 0:92706998571a 998 }
Davidroid 0:92706998571a 999
Davidroid 0:92706998571a 1000 /* End of L6470_AppCMDs */
Davidroid 0:92706998571a 1001
Davidroid 0:92706998571a 1002 /**
Davidroid 0:92706998571a 1003 * @addtogroup L6470_AppCMDs_ToBePrepared
Davidroid 0:92706998571a 1004 * @{
Davidroid 0:92706998571a 1005 */
Davidroid 0:92706998571a 1006
Davidroid 0:92706998571a 1007 /**
Davidroid 0:92706998571a 1008 * @brief Prepare to send @ref L6470_SetParam command.
Davidroid 0:92706998571a 1009 *
Davidroid 0:92706998571a 1010 * @param L6470_RegId The identifier of the L6470 register to be addressed.
Davidroid 0:92706998571a 1011 * @param Value The new value.
Davidroid 0:92706998571a 1012 *
Davidroid 0:92706998571a 1013 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1014 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1015 */
Davidroid 0:92706998571a 1016 void L6470::L6470_PrepareSetParam(eL6470_RegId_t L6470_RegId, uint32_t Value)
Davidroid 0:92706998571a 1017 {
Davidroid 14:e614697ebf34 1018 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SETPARAM_ID, L6470_RegId, Value, 0);
Davidroid 0:92706998571a 1019 }
Davidroid 0:92706998571a 1020
Davidroid 0:92706998571a 1021 /**
Davidroid 0:92706998571a 1022 * @brief Prepare to send @ref L6470_GetParam command.
Davidroid 0:92706998571a 1023 *
Davidroid 0:92706998571a 1024 * @param L6470_Id The L6470 identifier inside the daisy chain.
Davidroid 0:92706998571a 1025 * @param L6470_RegId The identifier of the L6470 register to be addressed.
Davidroid 0:92706998571a 1026 *
Davidroid 0:92706998571a 1027 * @retval ReceivedValue The register value.
Davidroid 0:92706998571a 1028 *
Davidroid 0:92706998571a 1029 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1030 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1031 */
Davidroid 0:92706998571a 1032 void L6470::L6470_PrepareGetParam(eL6470_RegId_t L6470_RegId)
Davidroid 0:92706998571a 1033 {
Davidroid 14:e614697ebf34 1034 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETPARAM_ID, L6470_RegId, 0, 0);
Davidroid 0:92706998571a 1035 }
Davidroid 0:92706998571a 1036
Davidroid 0:92706998571a 1037 /**
Davidroid 0:92706998571a 1038 * @brief Prepare to send @ref L6470_Run command.
Davidroid 0:92706998571a 1039 *
Davidroid 0:92706998571a 1040 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1041 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
Davidroid 0:92706998571a 1042 *
Davidroid 0:92706998571a 1043 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1044 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1045 */
Davidroid 0:92706998571a 1046 void L6470::L6470_PrepareRun(eL6470_DirId_t L6470_DirId, uint32_t Speed)
Davidroid 0:92706998571a 1047 {
Davidroid 0:92706998571a 1048 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RUN_ID, L6470_DirId, Speed, 0);
Davidroid 0:92706998571a 1049 }
Davidroid 0:92706998571a 1050
Davidroid 0:92706998571a 1051 /**
Davidroid 0:92706998571a 1052 * @brief Prepare to send @ref L6470_StepClock command.
Davidroid 0:92706998571a 1053 *
Davidroid 0:92706998571a 1054 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1055 *
Davidroid 0:92706998571a 1056 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1057 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1058 */
Davidroid 0:92706998571a 1059 void L6470::L6470_PrepareStepClock(eL6470_DirId_t L6470_DirId)
Davidroid 0:92706998571a 1060 {
Davidroid 0:92706998571a 1061 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_STEPCLOCK_ID, L6470_DirId, 0, 0);
Davidroid 0:92706998571a 1062 }
Davidroid 0:92706998571a 1063
Davidroid 0:92706998571a 1064 /**
Davidroid 0:92706998571a 1065 * @brief Prepare to send @ref L6470_Move command.
Davidroid 0:92706998571a 1066 *
Davidroid 0:92706998571a 1067 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1068 * @param N_Step The number of microsteps.
Davidroid 0:92706998571a 1069 *
Davidroid 0:92706998571a 1070 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1071 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1072 */
Davidroid 0:92706998571a 1073 void L6470::L6470_PrepareMove(eL6470_DirId_t L6470_DirId, uint32_t N_Step)
Davidroid 0:92706998571a 1074 {
Davidroid 0:92706998571a 1075 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_MOVE_ID, L6470_DirId, N_Step, 0);
Davidroid 0:92706998571a 1076 }
Davidroid 0:92706998571a 1077
Davidroid 0:92706998571a 1078 /**
Davidroid 0:92706998571a 1079 * @brief Prepare to send @ref L6470_GoTo command.
Davidroid 0:92706998571a 1080 *
Davidroid 0:92706998571a 1081 * @param AbsPos The target absolute position.
Davidroid 0:92706998571a 1082 *
Davidroid 0:92706998571a 1083 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1084 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1085 */
Davidroid 0:92706998571a 1086 void L6470::L6470_PrepareGoTo(uint32_t AbsPos)
Davidroid 0:92706998571a 1087 {
Davidroid 0:92706998571a 1088 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTO_ID, AbsPos, 0, 0);
Davidroid 0:92706998571a 1089 }
Davidroid 0:92706998571a 1090
Davidroid 0:92706998571a 1091 /**
Davidroid 0:92706998571a 1092 * @brief Prepare to send @ref L6470_GoToDIR command.
Davidroid 0:92706998571a 1093 *
Davidroid 0:92706998571a 1094 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1095 * @param AbsPos The target absolute position.
Davidroid 0:92706998571a 1096 *
Davidroid 0:92706998571a 1097 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1098 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1099 */
Davidroid 0:92706998571a 1100 void L6470::L6470_PrepareGoToDir(eL6470_DirId_t L6470_DirId, uint32_t AbsPos)
Davidroid 0:92706998571a 1101 {
Davidroid 0:92706998571a 1102 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOTODIR_ID, L6470_DirId, AbsPos, 0);
Davidroid 0:92706998571a 1103 }
Davidroid 0:92706998571a 1104
Davidroid 0:92706998571a 1105 /**
Davidroid 0:92706998571a 1106 * @brief Prepare to send @ref L6470_GoUntil command.
Davidroid 0:92706998571a 1107 *
Davidroid 0:92706998571a 1108 * @param L6470_ActId The identifier of the L6470 action about the absolute position.
Davidroid 0:92706998571a 1109 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1110 * @param Speed The speed value as (([step/s] * 250e-9) / 2^-28)
Davidroid 0:92706998571a 1111 *
Davidroid 0:92706998571a 1112 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1113 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1114 */
Davidroid 0:92706998571a 1115 void L6470::L6470_PrepareGoUntil(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId, uint32_t Speed)
Davidroid 0:92706998571a 1116 {
Davidroid 0:92706998571a 1117 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOUNTIL_ID, L6470_ActId, L6470_DirId, Speed);
Davidroid 0:92706998571a 1118 }
Davidroid 0:92706998571a 1119
Davidroid 0:92706998571a 1120 /**
Davidroid 0:92706998571a 1121 * @brief Prepare to send @ref L6470_ReleaseSW.
Davidroid 0:92706998571a 1122 *
Davidroid 0:92706998571a 1123 * @param L6470_ActId The identifier of the L6470 action about the absolute position.
Davidroid 0:92706998571a 1124 * @param L6470_DirId The identifier of the L6470 motion direction.
Davidroid 0:92706998571a 1125 *
Davidroid 0:92706998571a 1126 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1127 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1128 */
Davidroid 0:92706998571a 1129 void L6470::L6470_PrepareReleaseSW(eL6470_ActId_t L6470_ActId, eL6470_DirId_t L6470_DirId)
Davidroid 0:92706998571a 1130 {
Davidroid 0:92706998571a 1131 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RELEASESW_ID, L6470_ActId, L6470_DirId, 0);
Davidroid 0:92706998571a 1132 }
Davidroid 0:92706998571a 1133
Davidroid 0:92706998571a 1134 /**
Davidroid 0:92706998571a 1135 * @brief Prepare to send @ref L6470_GoHome command.
Davidroid 0:92706998571a 1136 *
Davidroid 0:92706998571a 1137 *
Davidroid 0:92706998571a 1138 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1139 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1140 */
Davidroid 0:92706998571a 1141 void L6470::L6470_PrepareGoHome(void)
Davidroid 0:92706998571a 1142 {
Davidroid 0:92706998571a 1143 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOHOME_ID, 0, 0, 0);
Davidroid 0:92706998571a 1144 }
Davidroid 0:92706998571a 1145
Davidroid 0:92706998571a 1146 /**
Davidroid 0:92706998571a 1147 * @brief Prepare to send @ref L6470_GoMark command.
Davidroid 0:92706998571a 1148 *
Davidroid 0:92706998571a 1149 *
Davidroid 0:92706998571a 1150 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1151 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1152 */
Davidroid 0:92706998571a 1153 void L6470::L6470_PrepareGoMark(void)
Davidroid 0:92706998571a 1154 {
Davidroid 0:92706998571a 1155 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GOMARK_ID, 0, 0, 0);
Davidroid 0:92706998571a 1156 }
Davidroid 0:92706998571a 1157
Davidroid 0:92706998571a 1158 /**
Davidroid 0:92706998571a 1159 * @brief Prepare to send @ref L6470_ResetPos command.
Davidroid 0:92706998571a 1160 *
Davidroid 0:92706998571a 1161 *
Davidroid 0:92706998571a 1162 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1163 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1164 */
Davidroid 0:92706998571a 1165 void L6470::L6470_PrepareResetPos(void)
Davidroid 0:92706998571a 1166 {
Davidroid 0:92706998571a 1167 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETPOS_ID, 0, 0, 0);
Davidroid 0:92706998571a 1168 }
Davidroid 0:92706998571a 1169
Davidroid 0:92706998571a 1170 /**
Davidroid 0:92706998571a 1171 * @brief Prepare to send @ref L6470_ResetDevice command.
Davidroid 0:92706998571a 1172 *
Davidroid 0:92706998571a 1173 *
Davidroid 0:92706998571a 1174 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1175 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1176 */
Davidroid 0:92706998571a 1177 void L6470::L6470_PrepareResetDevice(void)
Davidroid 0:92706998571a 1178 {
Davidroid 0:92706998571a 1179 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_RESETDEVICE_ID, 0, 0, 0);
Davidroid 0:92706998571a 1180 }
Davidroid 0:92706998571a 1181
Davidroid 0:92706998571a 1182 /**
Davidroid 0:92706998571a 1183 * @brief Prepare to send @ref L6470_SoftStop command.
Davidroid 0:92706998571a 1184 *
Davidroid 0:92706998571a 1185 *
Davidroid 0:92706998571a 1186 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1187 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1188 */
Davidroid 0:92706998571a 1189 void L6470::L6470_PrepareSoftStop(void)
Davidroid 0:92706998571a 1190 {
Davidroid 0:92706998571a 1191 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTSTOP_ID, 0, 0, 0);
Davidroid 0:92706998571a 1192 }
Davidroid 0:92706998571a 1193
Davidroid 0:92706998571a 1194 /**
Davidroid 0:92706998571a 1195 * @brief Prepare to send @ref L6470_HardStop command.
Davidroid 0:92706998571a 1196 *
Davidroid 0:92706998571a 1197 *
Davidroid 0:92706998571a 1198 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1199 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1200 */
Davidroid 0:92706998571a 1201 void L6470::L6470_PrepareHardStop(void)
Davidroid 0:92706998571a 1202 {
Davidroid 0:92706998571a 1203 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDSTOP_ID, 0, 0, 0);
Davidroid 0:92706998571a 1204 }
Davidroid 0:92706998571a 1205
Davidroid 0:92706998571a 1206 /**
Davidroid 0:92706998571a 1207 * @brief Prepare to send @ref L6470_SoftHiZ command.
Davidroid 0:92706998571a 1208 *
Davidroid 0:92706998571a 1209 *
Davidroid 0:92706998571a 1210 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1211 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1212 */
Davidroid 0:92706998571a 1213 void L6470::L6470_PrepareSoftHiZ(void)
Davidroid 0:92706998571a 1214 {
Davidroid 0:92706998571a 1215 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_SOFTHIZ_ID, 0, 0, 0);
Davidroid 0:92706998571a 1216 }
Davidroid 0:92706998571a 1217
Davidroid 0:92706998571a 1218 /**
Davidroid 0:92706998571a 1219 * @brief Prepare to send @ref L6470_HardHiZ command.
Davidroid 0:92706998571a 1220 *
Davidroid 0:92706998571a 1221 *
Davidroid 0:92706998571a 1222 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1223 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1224 */
Davidroid 0:92706998571a 1225 void L6470::L6470_PrepareHardHiZ(void)
Davidroid 0:92706998571a 1226 {
Davidroid 0:92706998571a 1227 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_HARDHIZ_ID, 0, 0, 0);
Davidroid 0:92706998571a 1228 }
Davidroid 0:92706998571a 1229
Davidroid 0:92706998571a 1230 /**
Davidroid 0:92706998571a 1231 * @brief Prepare to send @ref L6470_GetStatus command.
Davidroid 0:92706998571a 1232 *
Davidroid 0:92706998571a 1233 *
Davidroid 0:92706998571a 1234 * @note This function will properly fill the right column of the L6470_AppCmdPkg.
Davidroid 0:92706998571a 1235 * @note The commad will be sent by @ref L6470_PerformPreparedApplicationCommand.
Davidroid 0:92706998571a 1236 */
Davidroid 0:92706998571a 1237 void L6470::L6470_PrepareGetStatus(void)
Davidroid 0:92706998571a 1238 {
Davidroid 0:92706998571a 1239 L6470_PrepareAppCmdPkg(L6470_AppCmdPkg, L6470_GETSTATUS_ID, 0, 0, 0);
Davidroid 0:92706998571a 1240 }
Davidroid 0:92706998571a 1241
Davidroid 0:92706998571a 1242 /* End of L6470_AppCMDs_ToBePrepared */
Davidroid 0:92706998571a 1243
Davidroid 0:92706998571a 1244 /**
Davidroid 0:92706998571a 1245 * @brief Send via SPI the command stored inside the L6470_AppCmdPkg to the
Davidroid 0:92706998571a 1246 * L6470 daisy chain.
Davidroid 0:92706998571a 1247 *
Davidroid 0:92706998571a 1248 * @retval (uint8_t*)data->L6470_DaisyChainSpiRxStruct The pointer to the structure
Davidroid 0:92706998571a 1249 * containing returned values from each L6470 of the daisy chain for each
Davidroid 0:92706998571a 1250 * sent SPI data.
Davidroid 0:92706998571a 1251 */
Davidroid 0:92706998571a 1252 uint8_t* L6470::L6470_PerformPreparedApplicationCommand(void)
Davidroid 0:92706998571a 1253 {
Davidroid 0:92706998571a 1254 L6470_PrepareDaisyChainCommand(L6470_AppCmdPkg, (uint8_t*)L6470_DaisyChainSpiTxStruct);
Davidroid 0:92706998571a 1255 L6470_DaisyChainCommand((uint8_t*)L6470_DaisyChainSpiTxStruct, (uint8_t*)L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 1256
Davidroid 0:92706998571a 1257 return (uint8_t*)(L6470_DaisyChainSpiRxStruct);
Davidroid 0:92706998571a 1258 }
Davidroid 0:92706998571a 1259
Davidroid 0:92706998571a 1260 /**
Davidroid 0:92706998571a 1261 * @brief Send command to the L6470 daisy chain via SPI
Davidroid 0:92706998571a 1262 * @param pL6470_DaisyChainSpiTxStruct Pointer to the matrix array of bytes to be sent to the daisy chain L6470
Davidroid 0:92706998571a 1263 * @param pL6470_DaisyChainSpiRxStruct Pointer to the matrix array of bytes to be received from the daisy chain L6470
Davidroid 0:92706998571a 1264 */
Davidroid 0:92706998571a 1265 void L6470::L6470_DaisyChainCommand(uint8_t* pL6470_DaisyChainSpiTxStruct, uint8_t* pL6470_DaisyChainSpiRxStruct)
Davidroid 0:92706998571a 1266 {
Davidroid 0:92706998571a 1267 uint8_t spibyte;
Davidroid 0:92706998571a 1268
Davidroid 0:92706998571a 1269 L6470_DaisyChain_HalfPrepared = ZERO_F;
Davidroid 0:92706998571a 1270
Davidroid 0:92706998571a 1271 /* Send all command bytes via SPI */
Davidroid 0:92706998571a 1272 for(spibyte=0; spibyte < L6470MAXSPICMDBYTESIZE; spibyte++)
Davidroid 0:92706998571a 1273 {
Davidroid 0:92706998571a 1274 /* Send the command via SPI */
Davidroid 0:92706998571a 1275 L6470_SPI_Communication((pL6470_DaisyChainSpiTxStruct+(spibyte * L6470DAISYCHAINSIZE)), (pL6470_DaisyChainSpiRxStruct+(spibyte * L6470DAISYCHAINSIZE)), L6470DAISYCHAINSIZE, 10);
Davidroid 0:92706998571a 1276
Davidroid 0:92706998571a 1277 //_DELAY(TDISCS);
Davidroid 0:92706998571a 1278 uint8_t delay_cnt;
Davidroid 0:92706998571a 1279 for (delay_cnt=0; delay_cnt<20; delay_cnt++) __NOP(); //!<Simply deselect time delay for SPI nCS
Davidroid 0:92706998571a 1280 }
Davidroid 0:92706998571a 1281 }
Davidroid 0:92706998571a 1282
Davidroid 0:92706998571a 1283 /**
Davidroid 0:92706998571a 1284 * @brief Extracts the data returned by the L6470 from the matrix that
Davidroid 0:92706998571a 1285 * contains the received SPI data.
Davidroid 0:92706998571a 1286 * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
Davidroid 0:92706998571a 1287 * @param pL6470_DaisyChainSpiRxStruct uint8_t-pointer to the matrix that
Davidroid 0:92706998571a 1288 * contains the received data by SPI from the L6470 daisy chain.
Davidroid 0:92706998571a 1289 * @param LengthByte The number of bytes about the received value.
Davidroid 0:92706998571a 1290 */
Davidroid 0:92706998571a 1291 uint32_t L6470::L6470_ExtractReturnedData(uint8_t* pL6470_DaisyChainSpiRxStruct, uint8_t LengthByte)
Davidroid 0:92706998571a 1292 {
Davidroid 0:92706998571a 1293 uint32_t value;
Davidroid 0:92706998571a 1294 uint8_t i;
Davidroid 0:92706998571a 1295
Davidroid 0:92706998571a 1296 value = 0x000000;
Davidroid 0:92706998571a 1297 for (i=1; i<=(L6470MAXSPICMDBYTESIZE-1); i++)
Davidroid 0:92706998571a 1298 {
Davidroid 0:92706998571a 1299 value |= (*(pL6470_DaisyChainSpiRxStruct+(i*L6470DAISYCHAINSIZE)+L6470_Id))<<((LengthByte-i)*8);
Davidroid 0:92706998571a 1300 }
Davidroid 1:b78dab6d2c58 1301
Davidroid 0:92706998571a 1302 return value;
Davidroid 0:92706998571a 1303 }
Davidroid 0:92706998571a 1304
Davidroid 0:92706998571a 1305 /**
Davidroid 0:92706998571a 1306 * @brief Check the state of a flag inside the L6470 STATUS register.
Davidroid 0:92706998571a 1307 *
Davidroid 0:92706998571a 1308 * @param L6470_Id The identifier of the L6470 target inside the daisy chain.
Davidroid 0:92706998571a 1309 * @param L6470_StatusRegisterFlagId The identifier of the L6470 STATUS flag to be checked.
Davidroid 0:92706998571a 1310 *
Davidroid 0:92706998571a 1311 * @retval state The flag state.
Davidroid 0:92706998571a 1312 */
Davidroid 0:92706998571a 1313
Davidroid 0:92706998571a 1314 uint8_t L6470::L6470_CheckStatusRegisterFlag(uint8_t L6470_StatusRegisterFlagId)
Davidroid 0:92706998571a 1315 {
Davidroid 0:92706998571a 1316 uint8_t state = 0;
Davidroid 0:92706998571a 1317
Davidroid 0:92706998571a 1318 *((uint16_t*)pL6470_StatusRegister) = L6470_GetParam(L6470_STATUS_ID);
Davidroid 0:92706998571a 1319
Davidroid 0:92706998571a 1320 switch(L6470_StatusRegisterFlagId)
Davidroid 0:92706998571a 1321 {
Davidroid 0:92706998571a 1322 case HiZ_ID:
Davidroid 0:92706998571a 1323 state = pL6470_StatusRegister->HiZ;
Davidroid 0:92706998571a 1324 break;
Davidroid 0:92706998571a 1325 case BUSY_ID:
Davidroid 0:92706998571a 1326 state = pL6470_StatusRegister->BUSY;
Davidroid 0:92706998571a 1327 break;
Davidroid 0:92706998571a 1328 case SW_F_ID:
Davidroid 0:92706998571a 1329 state = pL6470_StatusRegister->SW_F;
Davidroid 0:92706998571a 1330 break;
Davidroid 0:92706998571a 1331 case SW_EVN_ID:
Davidroid 0:92706998571a 1332 state = pL6470_StatusRegister->SW_EVN;
Davidroid 0:92706998571a 1333 break;
Davidroid 0:92706998571a 1334 case DIR_ID:
Davidroid 0:92706998571a 1335 state = pL6470_StatusRegister->DIR;
Davidroid 0:92706998571a 1336 break;
Davidroid 0:92706998571a 1337 case MOT_STATUS_ID:
Davidroid 0:92706998571a 1338 state = pL6470_StatusRegister->MOT_STATUS;
Davidroid 0:92706998571a 1339 break;
Davidroid 0:92706998571a 1340 case NOTPERF_CMD_ID:
Davidroid 0:92706998571a 1341 state = pL6470_StatusRegister->NOTPERF_CMD;
Davidroid 0:92706998571a 1342 break;
Davidroid 0:92706998571a 1343 case WRONG_CMD_ID:
Davidroid 0:92706998571a 1344 state = pL6470_StatusRegister->WRONG_CMD;
Davidroid 0:92706998571a 1345 break;
Davidroid 0:92706998571a 1346 case UVLO_ID:
Davidroid 0:92706998571a 1347 state = pL6470_StatusRegister->UVLO;
Davidroid 0:92706998571a 1348 break;
Davidroid 0:92706998571a 1349 case TH_WRN_ID:
Davidroid 0:92706998571a 1350 state = pL6470_StatusRegister->TH_WRN;
Davidroid 0:92706998571a 1351 break;
Davidroid 0:92706998571a 1352 case TH_SD_ID:
Davidroid 0:92706998571a 1353 state = pL6470_StatusRegister->TH_SD;
Davidroid 0:92706998571a 1354 break;
Davidroid 0:92706998571a 1355 case OCD_ID:
Davidroid 0:92706998571a 1356 state = pL6470_StatusRegister->OCD;
Davidroid 0:92706998571a 1357 break;
Davidroid 0:92706998571a 1358 case STEP_LOSS_A_ID:
Davidroid 0:92706998571a 1359 state = pL6470_StatusRegister->STEP_LOSS_A;
Davidroid 0:92706998571a 1360 break;
Davidroid 0:92706998571a 1361 case STEP_LOSS_B_ID:
Davidroid 0:92706998571a 1362 state = pL6470_StatusRegister->STEP_LOSS_B;
Davidroid 0:92706998571a 1363 break;
Davidroid 0:92706998571a 1364 case SCK_MOD_ID:
Davidroid 0:92706998571a 1365 state = pL6470_StatusRegister->SCK_MOD;
Davidroid 0:92706998571a 1366 break;
Davidroid 0:92706998571a 1367 }
Davidroid 0:92706998571a 1368
Davidroid 0:92706998571a 1369 return state;
Davidroid 0:92706998571a 1370 }
Davidroid 0:92706998571a 1371
Davidroid 0:92706998571a 1372 /**
Davidroid 0:92706998571a 1373 * @brief Return the mnemonic name for the L6470 register.
Davidroid 0:92706998571a 1374 * @param id The identifier of the L6470 register.
Davidroid 0:92706998571a 1375 */
Davidroid 0:92706998571a 1376 uint8_t *L6470::L6470_GetRegisterName(uint8_t id)
Davidroid 0:92706998571a 1377 {
Davidroid 0:92706998571a 1378 if (id < L6470REGIDSIZE)
Davidroid 0:92706998571a 1379 {
Davidroid 0:92706998571a 1380 return (uint8_t*)L6470_Register[id].Name;
Davidroid 0:92706998571a 1381 }
Davidroid 0:92706998571a 1382 else
Davidroid 0:92706998571a 1383 {
Davidroid 0:92706998571a 1384 return NULL;
Davidroid 0:92706998571a 1385 }
Davidroid 0:92706998571a 1386 }
Davidroid 0:92706998571a 1387
Davidroid 0:92706998571a 1388 /**
Davidroid 0:92706998571a 1389 * @brief Configures the L6470 registers.
Davidroid 12:a942d51c488b 1390 * @param init The pointer to the initialization structure.
Davidroid 0:92706998571a 1391 */
Davidroid 14:e614697ebf34 1392 Status_t L6470::L6470_Config(void *init)
Davidroid 0:92706998571a 1393 {
Davidroid 0:92706998571a 1394 /* Disable the L6470. */
Davidroid 0:92706998571a 1395 L6470_DISABLE();
Davidroid 0:92706998571a 1396
Davidroid 0:92706998571a 1397 /* Enable the L6470. */
Davidroid 0:92706998571a 1398 L6470_ENABLE();
Davidroid 0:92706998571a 1399
Davidroid 0:92706998571a 1400 /* Reset devices. */
Davidroid 0:92706998571a 1401 ResetDevice();
Davidroid 0:92706998571a 1402
Davidroid 0:92706998571a 1403 /* Reset Status Register flags. */
Davidroid 0:92706998571a 1404 GetStatus();
Davidroid 0:92706998571a 1405
Davidroid 0:92706998571a 1406 /* Prepare the 'Register' field of StepperMotorDriverHandle */
Davidroid 14:e614697ebf34 1407 L6470_Init_t *MotorParameterData = (L6470_Init_t *) init;
Davidroid 0:92706998571a 1408 StepperMotorRegister.ACC = L6470_Step_s2_2_Acc(MotorParameterData->acc);
Davidroid 0:92706998571a 1409 StepperMotorRegister.DEC = L6470_Step_s2_2_Dec(MotorParameterData->dec);
Davidroid 0:92706998571a 1410 StepperMotorRegister.MAX_SPEED = L6470_Step_s_2_MaxSpeed(MotorParameterData->maxspeed);
Davidroid 0:92706998571a 1411 StepperMotorRegister.MIN_SPEED = L6470_Step_s_2_MinSpeed(MotorParameterData->minspeed);
Davidroid 0:92706998571a 1412 StepperMotorRegister.FS_SPD = L6470_Step_s_2_FsSpd(MotorParameterData->fsspd);
Davidroid 0:92706998571a 1413 StepperMotorRegister.KVAL_HOLD = (uint8_t)((float)((float)(MotorParameterData->kvalhold * 256) / (MotorParameterData->motorvoltage)));
Davidroid 0:92706998571a 1414 StepperMotorRegister.KVAL_RUN = (uint8_t)((float)((float)(MotorParameterData->kvalrun * 256) / (MotorParameterData->motorvoltage)));
Davidroid 0:92706998571a 1415 StepperMotorRegister.KVAL_ACC = (uint8_t)((float)((float)(MotorParameterData->kvalacc * 256) / (MotorParameterData->motorvoltage)));
Davidroid 0:92706998571a 1416 StepperMotorRegister.KVAL_DEC = (uint8_t)((float)((float)(MotorParameterData->kvaldec * 256) / (MotorParameterData->motorvoltage)));
Davidroid 0:92706998571a 1417 StepperMotorRegister.INT_SPEED = L6470_Step_s_2_IntSpeed(MotorParameterData->intspeed);
Davidroid 0:92706998571a 1418 StepperMotorRegister.ST_SLP = L6470_s_Step_2_StSlp(MotorParameterData->stslp);
Davidroid 0:92706998571a 1419 StepperMotorRegister.FN_SLP_ACC = L6470_s_Step_2_FnSlpAcc(MotorParameterData->fnslpacc);
Davidroid 0:92706998571a 1420 StepperMotorRegister.FN_SLP_DEC = L6470_s_Step_2_FnSlpDec(MotorParameterData->fnslpdec);
Davidroid 0:92706998571a 1421 StepperMotorRegister.K_THERM = MotorParameterData->kterm;
Davidroid 0:92706998571a 1422 StepperMotorRegister.OCD_TH = L6470_mA_2_OcdTh(MotorParameterData->ocdth);
Davidroid 0:92706998571a 1423 StepperMotorRegister.STALL_TH = L6470_mA_2_StallTh(MotorParameterData->stallth);
Davidroid 0:92706998571a 1424 StepperMotorRegister.STEP_MODE = MotorParameterData->step_sel;
Davidroid 0:92706998571a 1425 StepperMotorRegister.ALARM_EN = MotorParameterData->alarmen;
Davidroid 0:92706998571a 1426 StepperMotorRegister.CONFIG = MotorParameterData->config;
Davidroid 0:92706998571a 1427
Davidroid 0:92706998571a 1428 /* Write the L6470 registers with the prepared data */
Davidroid 0:92706998571a 1429 L6470_SetParam(L6470_ACC_ID, StepperMotorRegister.ACC);
Davidroid 0:92706998571a 1430 L6470_SetParam(L6470_DEC_ID, StepperMotorRegister.DEC);
Davidroid 0:92706998571a 1431 L6470_SetParam(L6470_MAX_SPEED_ID, StepperMotorRegister.MAX_SPEED);
Davidroid 0:92706998571a 1432 L6470_SetParam(L6470_MIN_SPEED_ID, StepperMotorRegister.MIN_SPEED);
Davidroid 0:92706998571a 1433 L6470_SetParam(L6470_FS_SPD_ID, StepperMotorRegister.FS_SPD);
Davidroid 0:92706998571a 1434 L6470_SetParam(L6470_KVAL_HOLD_ID, StepperMotorRegister.KVAL_HOLD);
Davidroid 0:92706998571a 1435 L6470_SetParam(L6470_KVAL_RUN_ID, StepperMotorRegister.KVAL_RUN);
Davidroid 0:92706998571a 1436 L6470_SetParam(L6470_KVAL_ACC_ID, StepperMotorRegister.KVAL_ACC);
Davidroid 0:92706998571a 1437 L6470_SetParam(L6470_KVAL_DEC_ID, StepperMotorRegister.KVAL_DEC);
Davidroid 0:92706998571a 1438 L6470_SetParam(L6470_INT_SPEED_ID, StepperMotorRegister.INT_SPEED);
Davidroid 0:92706998571a 1439 L6470_SetParam(L6470_ST_SLP_ID, StepperMotorRegister.ST_SLP);
Davidroid 0:92706998571a 1440 L6470_SetParam(L6470_FN_SLP_ACC_ID, StepperMotorRegister.FN_SLP_ACC);
Davidroid 0:92706998571a 1441 L6470_SetParam(L6470_FN_SLP_DEC_ID, StepperMotorRegister.FN_SLP_DEC);
Davidroid 0:92706998571a 1442 L6470_SetParam(L6470_K_THERM_ID, StepperMotorRegister.K_THERM);
Davidroid 0:92706998571a 1443 L6470_SetParam(L6470_OCD_TH_ID, StepperMotorRegister.OCD_TH);
Davidroid 0:92706998571a 1444 L6470_SetParam(L6470_STALL_TH_ID, StepperMotorRegister.STALL_TH);
Davidroid 0:92706998571a 1445 L6470_SetParam(L6470_STEP_MODE_ID, StepperMotorRegister.STEP_MODE);
Davidroid 0:92706998571a 1446 L6470_SetParam(L6470_ALARM_EN_ID, StepperMotorRegister.ALARM_EN);
Davidroid 0:92706998571a 1447 L6470_SetParam(L6470_CONFIG_ID, StepperMotorRegister.CONFIG);
Davidroid 0:92706998571a 1448
Davidroid 0:92706998571a 1449 return COMPONENT_OK;
Davidroid 0:92706998571a 1450 }
Davidroid 0:92706998571a 1451
Davidroid 0:92706998571a 1452 /* End of L6470_Exported_Functions */
Davidroid 0:92706998571a 1453
Davidroid 0:92706998571a 1454 /* End of L6470 */
Davidroid 0:92706998571a 1455
Davidroid 0:92706998571a 1456 /* End of Components */
Davidroid 0:92706998571a 1457
Davidroid 0:92706998571a 1458 /* End of BSP */
Davidroid 0:92706998571a 1459
Davidroid 0:92706998571a 1460 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/