Expansion SW library to control a bipolar stepper motor using X-NUCLEO-IHM05A1 expansion board based on L6208.
Dependencies: ST_INTERFACES
Dependents: HelloWorld_IHM05A1 TAU_ROTATING_PLATFORM_IHM05A1 Amaldi_13_Exercise_IHM05A1 Amaldi_13_Exercise_IHM05A1motore ... more
Fork of X-NUCLEO-IHM05A1 by
Motor Control Library
Library to handle the X-NUCLEO-IHM05A1 Motor Control Expansion Board based on the L6208 component.
It features the:
- Read and write of device parameters
- Configuration of GPIOs and IRQs (for enabling, direction, current decay and microstepping)
- Control of position, speed, acceleration and deceleration
- Command locking until the device completes movement
- Handling of overcurrent and thermal alarms (flag interrupt handling)
The API allows to easily:
- perform various positioning, moves and stops
- get/set or monitor the motor positions
- set home position and mark another position
- get/set minimum and maximum speed
- get current speed
- get/set acceleration and deceleration
- get/set the step mode (up to 1/16)
Board configuration
Platform compatibility
Compatible platforms have been tested with the configurations provided by the HelloWorld_IHM05A1 example.
Components/L6208/L6208_def.h@6:c73faac7197f, 2017-07-28 (annotated)
- Committer:
- Davidroid
- Date:
- Fri Jul 28 13:06:36 2017 +0000
- Revision:
- 6:c73faac7197f
- Parent:
- 4:0b52159554b5
Aligning to ARM mbed coding style.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
davide.aliprandi@st.com | 3:63a8d672fe5e | 1 | /******************************************************//** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 2 | * @file L6208_def.h |
davide.aliprandi@st.com | 3:63a8d672fe5e | 3 | * @author IPC Rennes |
davide.aliprandi@st.com | 3:63a8d672fe5e | 4 | * @version V1.1.0 |
davide.aliprandi@st.com | 3:63a8d672fe5e | 5 | * @date February 11th, 2016 |
davide.aliprandi@st.com | 3:63a8d672fe5e | 6 | * @brief Header for l6208.c module |
davide.aliprandi@st.com | 3:63a8d672fe5e | 7 | * @note (C) COPYRIGHT 2016 STMicroelectronics |
davide.aliprandi@st.com | 3:63a8d672fe5e | 8 | ****************************************************************************** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 9 | * @attention |
davide.aliprandi@st.com | 3:63a8d672fe5e | 10 | * |
davide.aliprandi@st.com | 3:63a8d672fe5e | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
davide.aliprandi@st.com | 3:63a8d672fe5e | 12 | * |
davide.aliprandi@st.com | 3:63a8d672fe5e | 13 | * Redistribution and use in source and binary forms, with or without modification, |
davide.aliprandi@st.com | 3:63a8d672fe5e | 14 | * are permitted provided that the following conditions are met: |
davide.aliprandi@st.com | 3:63a8d672fe5e | 15 | * 1. Redistributions of source code must retain the above copyright notice, |
davide.aliprandi@st.com | 3:63a8d672fe5e | 16 | * this list of conditions and the following disclaimer. |
davide.aliprandi@st.com | 3:63a8d672fe5e | 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
davide.aliprandi@st.com | 3:63a8d672fe5e | 18 | * this list of conditions and the following disclaimer in the documentation |
davide.aliprandi@st.com | 3:63a8d672fe5e | 19 | * and/or other materials provided with the distribution. |
davide.aliprandi@st.com | 3:63a8d672fe5e | 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
davide.aliprandi@st.com | 3:63a8d672fe5e | 21 | * may be used to endorse or promote products derived from this software |
davide.aliprandi@st.com | 3:63a8d672fe5e | 22 | * without specific prior written permission. |
davide.aliprandi@st.com | 3:63a8d672fe5e | 23 | * |
davide.aliprandi@st.com | 3:63a8d672fe5e | 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
davide.aliprandi@st.com | 3:63a8d672fe5e | 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
davide.aliprandi@st.com | 3:63a8d672fe5e | 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
davide.aliprandi@st.com | 3:63a8d672fe5e | 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
davide.aliprandi@st.com | 3:63a8d672fe5e | 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
davide.aliprandi@st.com | 3:63a8d672fe5e | 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
davide.aliprandi@st.com | 3:63a8d672fe5e | 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
davide.aliprandi@st.com | 3:63a8d672fe5e | 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
davide.aliprandi@st.com | 3:63a8d672fe5e | 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
davide.aliprandi@st.com | 3:63a8d672fe5e | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
davide.aliprandi@st.com | 3:63a8d672fe5e | 34 | * |
davide.aliprandi@st.com | 3:63a8d672fe5e | 35 | ****************************************************************************** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 36 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 37 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 39 | #ifndef _L6208_H_INCLUDED |
davide.aliprandi@st.com | 3:63a8d672fe5e | 40 | #define _L6208_H_INCLUDED |
davide.aliprandi@st.com | 3:63a8d672fe5e | 41 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 42 | #ifdef __cplusplus |
davide.aliprandi@st.com | 3:63a8d672fe5e | 43 | extern "C" { |
davide.aliprandi@st.com | 3:63a8d672fe5e | 44 | #endif |
davide.aliprandi@st.com | 3:63a8d672fe5e | 45 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 46 | /* Includes ------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 47 | #include "L6208_config.h" |
davide.aliprandi@st.com | 3:63a8d672fe5e | 48 | #include "motor_def.h" |
davide.aliprandi@st.com | 3:63a8d672fe5e | 49 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 50 | /* Definitions ---------------------------------------------------------------*/ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 51 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 52 | /** @addtogroup Components |
davide.aliprandi@st.com | 3:63a8d672fe5e | 53 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 54 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 55 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 56 | /** @defgroup L6208 |
davide.aliprandi@st.com | 3:63a8d672fe5e | 57 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 58 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 59 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 60 | /** @defgroup L6208_Exported_Defines L6208 Exported Defines |
davide.aliprandi@st.com | 3:63a8d672fe5e | 61 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 62 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 63 | /// Current FW major version |
davide.aliprandi@st.com | 3:63a8d672fe5e | 64 | #define L6208_FW_MAJOR_VERSION (uint8_t)(1) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 65 | /// Current FW minor version |
davide.aliprandi@st.com | 3:63a8d672fe5e | 66 | #define L6208_FW_MINOR_VERSION (uint8_t)(1) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 67 | /// Current FW patch version |
davide.aliprandi@st.com | 3:63a8d672fe5e | 68 | #define L6208_FW_PATCH_VERSION (uint8_t)(0) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 69 | /// Current FW version |
davide.aliprandi@st.com | 3:63a8d672fe5e | 70 | #define L6208_FW_VERSION (uint32_t)((L6208_FW_MAJOR_VERSION<<16)|\ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 71 | (L6208_FW_MINOR_VERSION<<8)|\ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 72 | (L6208_FW_PATCH_VERSION)) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 73 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 74 | /// Exponent used to scale the sine function for the RefMicroTable |
davide.aliprandi@st.com | 3:63a8d672fe5e | 75 | #define L6208_SINE_WAVEFORM_POWER_OF_TWO_MAX_VALUE (15) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 76 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 77 | /// Tick frequency (Hz) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 78 | #define TIMER_TICK_FREQUENCY (10000) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 79 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 80 | /// MCU wait time after power bridges are enabled |
davide.aliprandi@st.com | 3:63a8d672fe5e | 81 | #define BRIDGE_TURN_ON_DELAY (10) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 82 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 83 | /// The maximum number of devices |
davide.aliprandi@st.com | 3:63a8d672fe5e | 84 | #define MAX_NUMBER_OF_DEVICES (1) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 85 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 86 | /// Max position |
davide.aliprandi@st.com | 3:63a8d672fe5e | 87 | #define L6208_MAX_POSITION (0x7FFFFFFF) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 88 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 89 | /// Min position |
davide.aliprandi@st.com | 3:63a8d672fe5e | 90 | #define L6208_MIN_POSITION (0x80000000) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 91 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 92 | /// Position range |
davide.aliprandi@st.com | 3:63a8d672fe5e | 93 | #define L6208_POSITION_RANGE ((uint32_t)(L6208_MAX_POSITION -\ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 94 | L6208_MIN_POSITION)) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 95 | /// micro step samples per period/4 |
davide.aliprandi@st.com | 3:63a8d672fe5e | 96 | #define L6208_USTEPS_PER_QUARTER_PERIOD (16) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 97 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 98 | /// minimum speed |
davide.aliprandi@st.com | 3:63a8d672fe5e | 99 | #define L6208_MIN_SPEED (16) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 100 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 101 | /// minimum acceleration and deceleration rate |
davide.aliprandi@st.com | 3:63a8d672fe5e | 102 | #define L6208_MIN_ACC_DEC_RATE (24) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 103 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 104 | /// Mask for HiZ bit in motorDecayMode_t enum |
davide.aliprandi@st.com | 3:63a8d672fe5e | 105 | #define L6208_FAST_DECAY_MODE_MASK (0x1) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 106 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 107 | /// L6208 error base number |
davide.aliprandi@st.com | 3:63a8d672fe5e | 108 | #define L6208_ERROR_BASE (0x9000) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 109 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 110 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 111 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 112 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 113 | /* Types ---------------------------------------------------------------------*/ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 114 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 115 | /** @defgroup L6208_Exported_Types L6208 Exported Types |
davide.aliprandi@st.com | 3:63a8d672fe5e | 116 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 117 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 118 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 119 | /** @defgroup Error_Types Error Types |
davide.aliprandi@st.com | 3:63a8d672fe5e | 120 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 121 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 122 | /// Errors |
davide.aliprandi@st.com | 3:63a8d672fe5e | 123 | typedef enum { |
davide.aliprandi@st.com | 3:63a8d672fe5e | 124 | L6208_ERROR_SET_HOME = L6208_ERROR_BASE, /// Error while setting home position |
davide.aliprandi@st.com | 3:63a8d672fe5e | 125 | L6208_ERROR_SET_MAX_SPEED = L6208_ERROR_BASE + 1, /// Error while setting max speed |
davide.aliprandi@st.com | 3:63a8d672fe5e | 126 | L6208_ERROR_SET_MIN_SPEED = L6208_ERROR_BASE + 2, /// Error while setting min speed |
davide.aliprandi@st.com | 3:63a8d672fe5e | 127 | L6208_ERROR_SET_ACCELERATION = L6208_ERROR_BASE + 3, /// Error while setting acceleration |
davide.aliprandi@st.com | 3:63a8d672fe5e | 128 | L6208_ERROR_SET_DECELERATION = L6208_ERROR_BASE + 4, /// Error while setting decelaration |
davide.aliprandi@st.com | 3:63a8d672fe5e | 129 | L6208_ERROR_MCU_OSC_CONFIG = L6208_ERROR_BASE + 5, /// Error while configuring mcu oscillator |
davide.aliprandi@st.com | 3:63a8d672fe5e | 130 | L6208_ERROR_MCU_CLOCK_CONFIG = L6208_ERROR_BASE + 6, /// Error while configuring mcu clock |
davide.aliprandi@st.com | 3:63a8d672fe5e | 131 | L6208_ERROR_POSITION = L6208_ERROR_BASE + 7, /// Unexpected current position (wrong number of steps) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 132 | L6208_ERROR_SPEED = L6208_ERROR_BASE + 8, /// Unexpected current speed |
davide.aliprandi@st.com | 3:63a8d672fe5e | 133 | L6208_ERROR_INIT = L6208_ERROR_BASE + 9, /// Unexpected number of devices |
davide.aliprandi@st.com | 3:63a8d672fe5e | 134 | L6208_ERROR_SET_DIRECTION = L6208_ERROR_BASE + 10,/// Error while setting direction |
davide.aliprandi@st.com | 3:63a8d672fe5e | 135 | L6208_ERROR_SET_STEP_MODE = L6208_ERROR_BASE + 11,/// Attempt to set an unsupported step mode |
davide.aliprandi@st.com | 3:63a8d672fe5e | 136 | L6208_ERROR_SET_PWM = L6208_ERROR_BASE + 12,/// Error while setting a PWM parameter |
davide.aliprandi@st.com | 3:63a8d672fe5e | 137 | }errorTypes_t; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 138 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 139 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 140 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 141 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 142 | /** @defgroup Device_Parameters Device Parameters |
davide.aliprandi@st.com | 3:63a8d672fe5e | 143 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 144 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 145 | /// Device Parameters Structure Type |
davide.aliprandi@st.com | 3:63a8d672fe5e | 146 | typedef struct |
davide.aliprandi@st.com | 3:63a8d672fe5e | 147 | { |
davide.aliprandi@st.com | 3:63a8d672fe5e | 148 | /// dwelling waiting time counter (tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 149 | volatile uint32_t dwellCounter; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 150 | /// motor position indicator (tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 151 | uint32_t ticks; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 152 | /// LSByte copy of the previous position (tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 153 | uint8_t lsbOldTicks; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 154 | /// LSByte copy of the previous position (tick) ( micro stepping ) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 155 | uint8_t lsbOldUSteppingTicks; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 156 | /// LSByte copy of the current position (tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 157 | uint8_t lsbTicks; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 158 | /// P1 = acceleration phase steps number (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 159 | uint32_t positionTarget1; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 160 | /// P2 = constant speed steps number (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 161 | uint32_t positionTarget2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 162 | /// P3 = deceleration phase steps number (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 163 | uint32_t positionTarget3; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 164 | /// P = total move distance in steps (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 165 | uint32_t positionTarget; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 166 | /// absolute motor position in microsteps (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 167 | volatile int32_t absolutePos; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 168 | /// mark position in microsteps (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 169 | volatile int32_t markPos; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 170 | /// motor position in microsteps (motor position control mode) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 171 | volatile uint32_t step; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 172 | /// dwelling time after position got (ms) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 173 | volatile uint16_t moveDwellTime; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 174 | /// number of micro stepping waveform samples to be rescaled according to selected torque value |
davide.aliprandi@st.com | 3:63a8d672fe5e | 175 | volatile uint8_t uStepsample2scale; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 176 | /// number of micro stepping waveform samples to be updated into the waveform scanning table |
davide.aliprandi@st.com | 3:63a8d672fe5e | 177 | volatile uint8_t uStepsample2update; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 178 | /// microstepping waveform sample index |
davide.aliprandi@st.com | 3:63a8d672fe5e | 179 | volatile uint8_t uStepSample; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 180 | /// system status flags |
davide.aliprandi@st.com | 3:63a8d672fe5e | 181 | volatile uint32_t flags; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 182 | /// current stepper state machine index |
davide.aliprandi@st.com | 3:63a8d672fe5e | 183 | volatile motorState_t motionState; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 184 | /// current step mode |
davide.aliprandi@st.com | 3:63a8d672fe5e | 185 | volatile motorStepMode_t stepMode; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 186 | /// micro stepping waveform scanning sample index increment |
davide.aliprandi@st.com | 3:63a8d672fe5e | 187 | uint8_t uStepInc; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 188 | /// frequency of the VREFA and VREFB PWM |
davide.aliprandi@st.com | 3:63a8d672fe5e | 189 | uint32_t vrefPwmFreq; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 190 | /// period of the VREFA and VREFB PWM in 1/256th of a microsecond |
davide.aliprandi@st.com | 3:63a8d672fe5e | 191 | uint16_t vrefPwmPeriod; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 192 | /// pulse width target of the VREFA PWM in 1/256th of a microsecond |
davide.aliprandi@st.com | 3:63a8d672fe5e | 193 | volatile uint16_t vrefPwmPulseWidthTargetA; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 194 | /// pulse width target of the VREFB PWM in 1/256th of a microsecond |
davide.aliprandi@st.com | 3:63a8d672fe5e | 195 | volatile uint16_t vrefPwmPulseWidthTargetB; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 196 | /// pulse width to be generated for VREFA PWM in 1/256th of a microsecond |
davide.aliprandi@st.com | 3:63a8d672fe5e | 197 | volatile int16_t vrefPwmPulseWidthToBeGeneratedA; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 198 | /// pulse width to be generated for VREFB PWM in 1/256th of a microsecond |
davide.aliprandi@st.com | 3:63a8d672fe5e | 199 | volatile int16_t vrefPwmPulseWidthToBeGeneratedB; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 200 | /// current selected torque value |
davide.aliprandi@st.com | 3:63a8d672fe5e | 201 | volatile uint16_t curTorqueScaler; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 202 | /// selected VREFA value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 203 | volatile uint16_t vRefAVal; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 204 | /// selected VREFB value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 205 | volatile uint16_t vRefBVal; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 206 | /// constant speed phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 207 | volatile uint8_t runTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 208 | /// acceleration phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 209 | volatile uint8_t accelTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 210 | /// deceleration phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 211 | volatile uint8_t decelTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 212 | /// holding phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 213 | volatile uint8_t holdTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 214 | /// acceleration (steps/s^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 215 | volatile uint16_t accelerationSps2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 216 | /// deceleration (steps/s^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 217 | volatile uint16_t decelerationSps2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 218 | /// acceleration (steps/tick^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 219 | volatile uint16_t accelerationSpt2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 220 | /// deceleration (steps/tick^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 221 | volatile uint16_t decelerationSpt2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 222 | /// maximum speed (steps/s) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 223 | volatile uint16_t maxSpeedSps; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 224 | /// minimum speed (steps/s) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 225 | volatile uint16_t minSpeedSps; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 226 | /// current speed (steps/s) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 227 | volatile uint16_t speedSps; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 228 | /// maximum speed (steps/tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 229 | volatile uint32_t maxSpeedSpt; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 230 | /// minimum speed (steps/tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 231 | volatile uint32_t minSpeedSpt; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 232 | /// current speed (steps/tick) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 233 | volatile uint32_t speedSpt; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 234 | }deviceParams_t; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 235 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 236 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 237 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 238 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 239 | /// Motor driver initialization structure definition |
davide.aliprandi@st.com | 3:63a8d672fe5e | 240 | typedef struct |
davide.aliprandi@st.com | 3:63a8d672fe5e | 241 | { |
davide.aliprandi@st.com | 3:63a8d672fe5e | 242 | /// acceleration (steps/s^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 243 | uint16_t accelerationSps2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 244 | /// acceleration phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 245 | uint8_t accelTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 246 | /// deceleration (steps/s^2) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 247 | uint16_t decelerationSps2; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 248 | /// deceleration phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 249 | uint8_t decelTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 250 | /// maximum speed (steps/s) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 251 | uint16_t maxSpeedSps; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 252 | /// constant speed phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 253 | uint8_t runTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 254 | /// holding phase torque value (%) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 255 | uint8_t holdTorque; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 256 | /// current step mode |
davide.aliprandi@st.com | 3:63a8d672fe5e | 257 | motorStepMode_t stepMode; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 258 | /// current decay mode (SLOW_DECAY or FAST_DECAY) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 259 | motorDecayMode_t decayMode; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 260 | /// dwelling time after position got (ms) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 261 | uint16_t moveDwellTime; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 262 | /// automatic HiZ on stop |
davide.aliprandi@st.com | 3:63a8d672fe5e | 263 | bool autoHiZstop; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 264 | /// frequency of the VREFA and VREFB PWM |
davide.aliprandi@st.com | 3:63a8d672fe5e | 265 | uint32_t vrefPwmFreq; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 266 | } l6208_init_t; |
davide.aliprandi@st.com | 3:63a8d672fe5e | 267 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 268 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 269 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 270 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 271 | /* Functions --------------------------------------------------------*/ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 272 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 273 | /** @defgroup MotorControl_Board_Linked_Functions MotorControl Board Linked Functions |
davide.aliprandi@st.com | 3:63a8d672fe5e | 274 | * @{ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 275 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 276 | ///Delay of the requested number of milliseconds |
davide.aliprandi@st.com | 3:63a8d672fe5e | 277 | extern void L6208_Board_Delay(uint32_t delay); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 278 | ///Enable Irq |
davide.aliprandi@st.com | 3:63a8d672fe5e | 279 | extern void L6208_Board_EnableIrq(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 280 | ///Disable Irq |
davide.aliprandi@st.com | 3:63a8d672fe5e | 281 | extern void L6208_Board_DisableIrq(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 282 | //Initialize the VREFA or VREFB PWM |
davide.aliprandi@st.com | 3:63a8d672fe5e | 283 | extern bool L6208_Board_VrefPwmInit(uint8_t bridgeId, uint32_t pwmFreq); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 284 | ///Initialize the tick |
davide.aliprandi@st.com | 3:63a8d672fe5e | 285 | extern void L6208_Board_TickInit(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 286 | ///Release the reset pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 287 | extern void L6208_Board_Releasereset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 288 | ///Set the reset pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 289 | extern void L6208_Board_reset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 290 | ///Set the control pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 291 | extern void L6208_Board_CONTROL_PIN_Set(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 292 | ///Reset the control pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 293 | extern void L6208_Board_CONTROL_PIN_reset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 294 | ///Set the clock pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 295 | extern void L6208_Board_CLOCK_PIN_Set(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 296 | ///Reset the clock pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 297 | extern void L6208_Board_CLOCK_PIN_reset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 298 | ///Set the half full pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 299 | extern void L6208_Board_HALF_FULL_PIN_Set(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 300 | ///Reset the half full pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 301 | extern void L6208_Board_HALF_FULL_PIN_reset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 302 | ///Set the dir pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 303 | extern void L6208_Board_DIR_PIN_Set(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 304 | ///Reset the dir pin |
davide.aliprandi@st.com | 3:63a8d672fe5e | 305 | extern void L6208_Board_DIR_PIN_reset(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 306 | ///Enable the power bridges (leave the output bridges HiZ) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 307 | extern void L6208_Board_enable(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 308 | ///Disable the power bridges (leave the output bridges HiZ) |
davide.aliprandi@st.com | 3:63a8d672fe5e | 309 | extern void L6208_Board_disable(void); |
davide.aliprandi@st.com | 3:63a8d672fe5e | 310 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 311 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 312 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 313 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 314 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 315 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 316 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 317 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 318 | /** |
davide.aliprandi@st.com | 3:63a8d672fe5e | 319 | * @} |
davide.aliprandi@st.com | 3:63a8d672fe5e | 320 | */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 321 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 322 | #ifdef __cplusplus |
davide.aliprandi@st.com | 3:63a8d672fe5e | 323 | } |
davide.aliprandi@st.com | 3:63a8d672fe5e | 324 | #endif |
davide.aliprandi@st.com | 3:63a8d672fe5e | 325 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 326 | #endif /* __L6208_H */ |
davide.aliprandi@st.com | 3:63a8d672fe5e | 327 | |
davide.aliprandi@st.com | 3:63a8d672fe5e | 328 | /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/ |