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:
Thu Apr 07 16:55:51 2016 +0000
Revision:
17:4b3dc908724f
Parent:
16:0d5be428b264
+ StepperMotor interface updated: step-modes added, getter/setter methods for parameters removed.

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