Library used to control ST Nucleo Evaluation board IHM12A1, based on STSPIN240 low voltage dual brush DC motor control driver.

Dependencies:   ST_INTERFACES

Dependents:   motori prova_motore SchedamotoriIHM12A1 prova_motore_duck ... more

Fork of X-NUCLEO-IHM12A1 by ST Expansion SW Team

Brush DC Motor Control Library

Library to handle the X-NUCLEO-IHM12A1 Motor Control Expansion Board based on the STSPIN240 component.

It allows a complete management of the STSPIN240, a low voltage dual brush DC driver, by providing a complete APIs.

The key features of the library are :

  • Configuration of the STSPIN240 (bridges input and enabling signals)
  • Flag interrupt handling (overcurrent and thermal alarms reporting)
  • Handling of up to two bidirectional Brush DC motors
  • Nucleo and expansion board configuration (GPIOs, PWMs, IRQs…)

To use the STSPIN240 driver library, the user first has to call its initialization method which:

  • Setups the required GPIOs to handle the bridges enable pins, the FLAG interrupt which reports overcurrent detection or thermal protection.
  • Loads the driver parameters with initial values configured by the user or with their predefined values from “stspin240_250_target_config.h”, in order to program the PWMs frequency of the bridges inputs, the number of brush DC motors.

Once the initialization is done, the user can modify the driver parameters by calling specific functions to change the numbers of motors or the PWMs frequency.

The user can also write callback functions and attach them to:

  • The flag interrupt handler depending on the actions he wants to perform when an overcurrent or a thermal alarm is reported.
  • The Error handler which is called by the library when it reports an error.

Then, the user can drive the different brush DC motors by requesting to run in a specified direction and by changing the maximal speed. When a motor is requested to run, the corresponding bridge is automatically enabled.

A motion command can be stopped at any moment:

  • Either by a hard stop which immediately stops the motor.
  • Or by a hardHiz command which immediately stops the motor and disables the bridge which is used by the motor.

The library also provides functions to disable or enable the bridges independently from the run or stop commands.

Arduino Connector Compatibility Warning

Using the X-NUCLEO-IHM12A1 expansion board with the NUCLEO-F429ZI requires adopting the following patch:

  • to connect with a wire the PB_3 Nucleo pin to the PWMB expansion board pin.


Board configuration for HelloWorld_IHM12A1 example

/media/uploads/Manu_L/x_nucleo_ihm12a1.jpg

Committer:
Manu_L
Date:
Thu Apr 28 14:03:11 2016 +0000
Revision:
0:13bc901c90aa
X-NUCLEO-IHM12A1 (STSPIN240) Library creation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Manu_L 0:13bc901c90aa 1 /**
Manu_L 0:13bc901c90aa 2 ******************************************************************************
Manu_L 0:13bc901c90aa 3 * @file stspin240_250_class.cpp
Manu_L 0:13bc901c90aa 4 * @author IPC Rennes
Manu_L 0:13bc901c90aa 5 * @version V1.0.0
Manu_L 0:13bc901c90aa 6 * @date April 25th, 2016
Manu_L 0:13bc901c90aa 7 * @brief Stspin240 motor driver (Dual brush DC motors)
Manu_L 0:13bc901c90aa 8 * @note (C) COPYRIGHT 2016 STMicroelectronics
Manu_L 0:13bc901c90aa 9 ******************************************************************************
Manu_L 0:13bc901c90aa 10 * @attention
Manu_L 0:13bc901c90aa 11 *
Manu_L 0:13bc901c90aa 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
Manu_L 0:13bc901c90aa 13 *
Manu_L 0:13bc901c90aa 14 * Redistribution and use in source and binary forms, with or without modification,
Manu_L 0:13bc901c90aa 15 * are permitted provided that the following conditions are met:
Manu_L 0:13bc901c90aa 16 * 1. Redistributions of source code must retain the above copyright notice,
Manu_L 0:13bc901c90aa 17 * this list of conditions and the following disclaimer.
Manu_L 0:13bc901c90aa 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Manu_L 0:13bc901c90aa 19 * this list of conditions and the following disclaimer in the documentation
Manu_L 0:13bc901c90aa 20 * and/or other materials provided with the distribution.
Manu_L 0:13bc901c90aa 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Manu_L 0:13bc901c90aa 22 * may be used to endorse or promote products derived from this software
Manu_L 0:13bc901c90aa 23 * without specific prior written permission.
Manu_L 0:13bc901c90aa 24 *
Manu_L 0:13bc901c90aa 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Manu_L 0:13bc901c90aa 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Manu_L 0:13bc901c90aa 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Manu_L 0:13bc901c90aa 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Manu_L 0:13bc901c90aa 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Manu_L 0:13bc901c90aa 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Manu_L 0:13bc901c90aa 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Manu_L 0:13bc901c90aa 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Manu_L 0:13bc901c90aa 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Manu_L 0:13bc901c90aa 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Manu_L 0:13bc901c90aa 35 *
Manu_L 0:13bc901c90aa 36 ******************************************************************************
Manu_L 0:13bc901c90aa 37 */
Manu_L 0:13bc901c90aa 38
Manu_L 0:13bc901c90aa 39 /* Includes ------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 40 #include "stspin240_250_class.h"
Manu_L 0:13bc901c90aa 41
Manu_L 0:13bc901c90aa 42 /* Definitions ---------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 43
Manu_L 0:13bc901c90aa 44 /* Error: Access a motor index greater than the one of the current brigde configuration */
Manu_L 0:13bc901c90aa 45 #define STSPIN240_250_ERROR_1 (0xC001)
Manu_L 0:13bc901c90aa 46 /* Error: Use of a bridgeId greater than BRIDGE_B */
Manu_L 0:13bc901c90aa 47 #define STSPIN240_250_ERROR_2 (0xC002)
Manu_L 0:13bc901c90aa 48
Manu_L 0:13bc901c90aa 49 /* Maximum frequency of the PWMs in Hz */
Manu_L 0:13bc901c90aa 50 #define STSPIN240_250_MAX_PWM_FREQ (100000)
Manu_L 0:13bc901c90aa 51
Manu_L 0:13bc901c90aa 52 /* Minimum frequency of the PWMs in Hz */
Manu_L 0:13bc901c90aa 53 #define STSPIN240_250_MIN_PWM_FREQ (2)
Manu_L 0:13bc901c90aa 54
Manu_L 0:13bc901c90aa 55 /* Bridge A */
Manu_L 0:13bc901c90aa 56 #define BRIDGE_A (0)
Manu_L 0:13bc901c90aa 57
Manu_L 0:13bc901c90aa 58 /* Bridge B */
Manu_L 0:13bc901c90aa 59 #define BRIDGE_B (1)
Manu_L 0:13bc901c90aa 60
Manu_L 0:13bc901c90aa 61 /* PWM id for PWM_A */
Manu_L 0:13bc901c90aa 62 #define PWM_A (0)
Manu_L 0:13bc901c90aa 63
Manu_L 0:13bc901c90aa 64 /* PWM id for PWM_B */
Manu_L 0:13bc901c90aa 65 #define PWM_B (1)
Manu_L 0:13bc901c90aa 66
Manu_L 0:13bc901c90aa 67 /* PWM id for PWM_REF */
Manu_L 0:13bc901c90aa 68 #define PWM_REF (2)
Manu_L 0:13bc901c90aa 69
Manu_L 0:13bc901c90aa 70 /* Variables ----------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 71
Manu_L 0:13bc901c90aa 72 /* Number of devices. */
Manu_L 0:13bc901c90aa 73 uint8_t STSPIN240_250::numberOfDevices = 0;
Manu_L 0:13bc901c90aa 74 uint8_t STSPIN240_250::arrayNbMaxMotorsByConfig[2] = {1,2};
Manu_L 0:13bc901c90aa 75 /* Methods -------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 76
Manu_L 0:13bc901c90aa 77 /**********************************************************
Manu_L 0:13bc901c90aa 78 * @brief Starts the STSPIN240_250 library
Manu_L 0:13bc901c90aa 79 * @param[in] pInit pointer to the initialization data
Manu_L 0:13bc901c90aa 80 * @retval COMPONENT_OK in case of success.
Manu_L 0:13bc901c90aa 81 **********************************************************/
Manu_L 0:13bc901c90aa 82 Status_t STSPIN240_250::Stspin240_250_Init(void* pInit)
Manu_L 0:13bc901c90aa 83 {
Manu_L 0:13bc901c90aa 84 /* Standby-reset deactivation */
Manu_L 0:13bc901c90aa 85 Stspin240_250_Board_ReleaseReset();
Manu_L 0:13bc901c90aa 86
Manu_L 0:13bc901c90aa 87 /* Let a delay after reset */
Manu_L 0:13bc901c90aa 88 Stspin240_250_Board_Delay(1);
Manu_L 0:13bc901c90aa 89
Manu_L 0:13bc901c90aa 90 if (pInit == 0)
Manu_L 0:13bc901c90aa 91 {
Manu_L 0:13bc901c90aa 92 // Set all registers to their predefined values
Manu_L 0:13bc901c90aa 93 // from powerstep01_target_config.h
Manu_L 0:13bc901c90aa 94 Stspin240_250_SetDeviceParamsToPredefinedValues();
Manu_L 0:13bc901c90aa 95 }
Manu_L 0:13bc901c90aa 96 else
Manu_L 0:13bc901c90aa 97 {
Manu_L 0:13bc901c90aa 98 Stspin240_250_SetDeviceParamsToGivenValues((Stspin240_250_Init_t *)pInit);
Manu_L 0:13bc901c90aa 99 }
Manu_L 0:13bc901c90aa 100
Manu_L 0:13bc901c90aa 101 /* Initialise input PWM of bridges*/
Manu_L 0:13bc901c90aa 102 Stspin240_250_SetDualFullBridgeconfig(device_prm.dualBridgeEnabled);
Manu_L 0:13bc901c90aa 103
Manu_L 0:13bc901c90aa 104 return COMPONENT_OK;
Manu_L 0:13bc901c90aa 105 }
Manu_L 0:13bc901c90aa 106
Manu_L 0:13bc901c90aa 107 /**********************************************************
Manu_L 0:13bc901c90aa 108 * @brief Read id
Manu_L 0:13bc901c90aa 109 * @param[in] id pointer to the identifier to be read.
Manu_L 0:13bc901c90aa 110 * @retval COMPONENT_OK in case of success.
Manu_L 0:13bc901c90aa 111 **********************************************************/
Manu_L 0:13bc901c90aa 112 Status_t STSPIN240_250::Stspin240_250_ReadId(uint8_t *id)
Manu_L 0:13bc901c90aa 113 {
Manu_L 0:13bc901c90aa 114 *id = deviceInstance;
Manu_L 0:13bc901c90aa 115
Manu_L 0:13bc901c90aa 116 return COMPONENT_OK;
Manu_L 0:13bc901c90aa 117 }
Manu_L 0:13bc901c90aa 118
Manu_L 0:13bc901c90aa 119 /**********************************************************
Manu_L 0:13bc901c90aa 120 * @brief Attaches a user callback to the error Handler.
Manu_L 0:13bc901c90aa 121 * The call back will be then called each time the library
Manu_L 0:13bc901c90aa 122 * detects an error
Manu_L 0:13bc901c90aa 123 * @param[in] callback Name of the callback to attach
Manu_L 0:13bc901c90aa 124 * to the error Hanlder
Manu_L 0:13bc901c90aa 125 * @retval None
Manu_L 0:13bc901c90aa 126 **********************************************************/
Manu_L 0:13bc901c90aa 127 void STSPIN240_250::Stspin240_250_AttachErrorHandler(void (*callback)(uint16_t error))
Manu_L 0:13bc901c90aa 128 {
Manu_L 0:13bc901c90aa 129 errorHandlerCallback = (void (*)(uint16_t error)) callback;
Manu_L 0:13bc901c90aa 130 }
Manu_L 0:13bc901c90aa 131
Manu_L 0:13bc901c90aa 132
Manu_L 0:13bc901c90aa 133 /******************************************************//**
Manu_L 0:13bc901c90aa 134 * @brief Disable the specified bridge
Manu_L 0:13bc901c90aa 135 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
Manu_L 0:13bc901c90aa 136 * @retval None
Manu_L 0:13bc901c90aa 137 * @note Bridge A and bridge B share the same enable pin.
Manu_L 0:13bc901c90aa 138 * When bridge A is disabled, bridge B is disabled and
Manu_L 0:13bc901c90aa 139 * reversely
Manu_L 0:13bc901c90aa 140 **********************************************************/
Manu_L 0:13bc901c90aa 141 void STSPIN240_250::Stspin240_250_DisableBridge(uint8_t bridgeId)
Manu_L 0:13bc901c90aa 142 {
Manu_L 0:13bc901c90aa 143 Stspin240_250_Board_DisableBridge();
Manu_L 0:13bc901c90aa 144 device_prm.bridgeEnabled[BRIDGE_A] = FALSE;
Manu_L 0:13bc901c90aa 145 device_prm.bridgeEnabled[BRIDGE_B] = FALSE;
Manu_L 0:13bc901c90aa 146 }
Manu_L 0:13bc901c90aa 147
Manu_L 0:13bc901c90aa 148 /******************************************************//**
Manu_L 0:13bc901c90aa 149 * @brief Enable the specified bridge
Manu_L 0:13bc901c90aa 150 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B)
Manu_L 0:13bc901c90aa 151 * @retval None
Manu_L 0:13bc901c90aa 152 * @note Bridge A and bridge B share the same enable pin.
Manu_L 0:13bc901c90aa 153 * When bridge A is enabled, bridge B is enabled and
Manu_L 0:13bc901c90aa 154 * reversely
Manu_L 0:13bc901c90aa 155 **********************************************************/
Manu_L 0:13bc901c90aa 156 void STSPIN240_250::Stspin240_250_EnableBridge(uint8_t bridgeId)
Manu_L 0:13bc901c90aa 157 {
Manu_L 0:13bc901c90aa 158 device_prm.bridgeEnabled[BRIDGE_A] = TRUE;
Manu_L 0:13bc901c90aa 159 device_prm.bridgeEnabled[BRIDGE_B] = TRUE;
Manu_L 0:13bc901c90aa 160 Stspin240_250_Board_EnableBridge(1);
Manu_L 0:13bc901c90aa 161 }
Manu_L 0:13bc901c90aa 162
Manu_L 0:13bc901c90aa 163 /**********************************************************
Manu_L 0:13bc901c90aa 164 * @brief Error handler which calls the user callback (if defined)
Manu_L 0:13bc901c90aa 165 * @param[in] error Number of the error
Manu_L 0:13bc901c90aa 166 * @retval None
Manu_L 0:13bc901c90aa 167 **********************************************************/
Manu_L 0:13bc901c90aa 168 void STSPIN240_250::Stspin240_250_ErrorHandler(uint16_t error)
Manu_L 0:13bc901c90aa 169 {
Manu_L 0:13bc901c90aa 170 if (errorHandlerCallback != 0)
Manu_L 0:13bc901c90aa 171 {
Manu_L 0:13bc901c90aa 172 (void) errorHandlerCallback(error);
Manu_L 0:13bc901c90aa 173 }
Manu_L 0:13bc901c90aa 174 else
Manu_L 0:13bc901c90aa 175 {
Manu_L 0:13bc901c90aa 176 /* Aborting the program. */
Manu_L 0:13bc901c90aa 177 exit(EXIT_FAILURE);
Manu_L 0:13bc901c90aa 178 }
Manu_L 0:13bc901c90aa 179 }
Manu_L 0:13bc901c90aa 180
Manu_L 0:13bc901c90aa 181 /******************************************************//**
Manu_L 0:13bc901c90aa 182 * @brief Get the PWM frequency of the specified bridge
Manu_L 0:13bc901c90aa 183 * @param[in] bridgeId 0 for bridge A, 1 for bridge B
Manu_L 0:13bc901c90aa 184 * @retval Freq in Hz
Manu_L 0:13bc901c90aa 185 **********************************************************/
Manu_L 0:13bc901c90aa 186 uint32_t STSPIN240_250::Stspin240_250_GetBridgeInputPwmFreq(uint8_t bridgeId)
Manu_L 0:13bc901c90aa 187 {
Manu_L 0:13bc901c90aa 188 if (bridgeId > BRIDGE_B)
Manu_L 0:13bc901c90aa 189 {
Manu_L 0:13bc901c90aa 190 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_2);
Manu_L 0:13bc901c90aa 191 }
Manu_L 0:13bc901c90aa 192
Manu_L 0:13bc901c90aa 193 return (device_prm.bridgePwmFreq[(bridgeId << 1)]);
Manu_L 0:13bc901c90aa 194 }
Manu_L 0:13bc901c90aa 195
Manu_L 0:13bc901c90aa 196 /******************************************************//**
Manu_L 0:13bc901c90aa 197 * @brief Get the status of the bridge enabling of the corresponding bridge
Manu_L 0:13bc901c90aa 198 * @param[in] bridgeId from 0 for bridge A to 1 for bridge B
Manu_L 0:13bc901c90aa 199 * @retval State of the Enable&Fault pin (shared for bridge A and B)
Manu_L 0:13bc901c90aa 200 **********************************************************/
Manu_L 0:13bc901c90aa 201 uint16_t STSPIN240_250::Stspin240_250_GetBridgeStatus(void)
Manu_L 0:13bc901c90aa 202 {
Manu_L 0:13bc901c90aa 203 uint16_t status = Stspin240_250_Board_GetFaultPinState();
Manu_L 0:13bc901c90aa 204
Manu_L 0:13bc901c90aa 205 return (status);
Manu_L 0:13bc901c90aa 206 }
Manu_L 0:13bc901c90aa 207
Manu_L 0:13bc901c90aa 208 /******************************************************//**
Manu_L 0:13bc901c90aa 209 * @brief Returns the current speed of the specified motor
Manu_L 0:13bc901c90aa 210 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 211 * @retval current speed in % from 0 to 100
Manu_L 0:13bc901c90aa 212 **********************************************************/
Manu_L 0:13bc901c90aa 213 uint16_t STSPIN240_250::Stspin240_250_GetCurrentSpeed(uint8_t motorId)
Manu_L 0:13bc901c90aa 214 {
Manu_L 0:13bc901c90aa 215 uint16_t speed = 0;
Manu_L 0:13bc901c90aa 216
Manu_L 0:13bc901c90aa 217 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 218 {
Manu_L 0:13bc901c90aa 219 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 220 }
Manu_L 0:13bc901c90aa 221 else if (device_prm.motionState[motorId] != INACTIVE)
Manu_L 0:13bc901c90aa 222 {
Manu_L 0:13bc901c90aa 223 speed = device_prm.speed[motorId];
Manu_L 0:13bc901c90aa 224 }
Manu_L 0:13bc901c90aa 225 return (speed);
Manu_L 0:13bc901c90aa 226 }
Manu_L 0:13bc901c90aa 227
Manu_L 0:13bc901c90aa 228 /******************************************************//**
Manu_L 0:13bc901c90aa 229 * @brief Returns the device state
Manu_L 0:13bc901c90aa 230 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 231 * @retval State (STEADY or INACTIVE)
Manu_L 0:13bc901c90aa 232 **********************************************************/
Manu_L 0:13bc901c90aa 233 motorState_t STSPIN240_250::Stspin240_250_GetDeviceState(uint8_t motorId)
Manu_L 0:13bc901c90aa 234 {
Manu_L 0:13bc901c90aa 235 motorState_t state = INACTIVE;
Manu_L 0:13bc901c90aa 236
Manu_L 0:13bc901c90aa 237 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 238 {
Manu_L 0:13bc901c90aa 239 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 240 }
Manu_L 0:13bc901c90aa 241 else
Manu_L 0:13bc901c90aa 242 {
Manu_L 0:13bc901c90aa 243 state = device_prm.motionState[motorId];
Manu_L 0:13bc901c90aa 244 }
Manu_L 0:13bc901c90aa 245 return (state);
Manu_L 0:13bc901c90aa 246 }
Manu_L 0:13bc901c90aa 247
Manu_L 0:13bc901c90aa 248 /******************************************************//**
Manu_L 0:13bc901c90aa 249 * @brief Get the motor current direction
Manu_L 0:13bc901c90aa 250 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 251 * @retval direction
Manu_L 0:13bc901c90aa 252 **********************************************************/
Manu_L 0:13bc901c90aa 253 motorDir_t STSPIN240_250::Stspin240_250_GetDirection(uint8_t motorId)
Manu_L 0:13bc901c90aa 254 {
Manu_L 0:13bc901c90aa 255 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 256 {
Manu_L 0:13bc901c90aa 257 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 258 }
Manu_L 0:13bc901c90aa 259
Manu_L 0:13bc901c90aa 260 return device_prm.direction[motorId];
Manu_L 0:13bc901c90aa 261 }
Manu_L 0:13bc901c90aa 262
Manu_L 0:13bc901c90aa 263 /******************************************************//**
Manu_L 0:13bc901c90aa 264 * @brief Returns the FW version of the library
Manu_L 0:13bc901c90aa 265 * @retval STSPIN240_250_FW_VERSION
Manu_L 0:13bc901c90aa 266 **********************************************************/
Manu_L 0:13bc901c90aa 267 uint32_t STSPIN240_250::Stspin240_250_GetFwVersion(void)
Manu_L 0:13bc901c90aa 268 {
Manu_L 0:13bc901c90aa 269 return (STSPIN240_250_FW_VERSION);
Manu_L 0:13bc901c90aa 270 }
Manu_L 0:13bc901c90aa 271
Manu_L 0:13bc901c90aa 272
Manu_L 0:13bc901c90aa 273 /******************************************************//**
Manu_L 0:13bc901c90aa 274 * @brief Return the duty cycle of PWM used for REF
Manu_L 0:13bc901c90aa 275 * @param[in] refId 0 is the only supported id for Stspin240 or
Manu_L 0:13bc901c90aa 276 * Stspin250
Manu_L 0:13bc901c90aa 277 * @retval duty cycle in % (from 0 to 100)
Manu_L 0:13bc901c90aa 278 **********************************************************/
Manu_L 0:13bc901c90aa 279 uint8_t STSPIN240_250::Stspin240_250_GetRefPwmDc(uint8_t refId)
Manu_L 0:13bc901c90aa 280 {
Manu_L 0:13bc901c90aa 281 uint32_t duty = 0;
Manu_L 0:13bc901c90aa 282
Manu_L 0:13bc901c90aa 283 if (duty == 0)
Manu_L 0:13bc901c90aa 284 {
Manu_L 0:13bc901c90aa 285 duty = device_prm.refPwmDc;
Manu_L 0:13bc901c90aa 286 }
Manu_L 0:13bc901c90aa 287 return (duty);
Manu_L 0:13bc901c90aa 288 }
Manu_L 0:13bc901c90aa 289
Manu_L 0:13bc901c90aa 290 /******************************************************//**
Manu_L 0:13bc901c90aa 291 * @brief Return the frequency of PWM used for REF
Manu_L 0:13bc901c90aa 292 * @param[in] refId 0 is the only supported id for Stspin240 or
Manu_L 0:13bc901c90aa 293 * Stspin250
Manu_L 0:13bc901c90aa 294 * @retval Frequency in Hz
Manu_L 0:13bc901c90aa 295 **********************************************************/
Manu_L 0:13bc901c90aa 296 uint32_t STSPIN240_250::Stspin240_250_GetRefPwmFreq(uint8_t refId)
Manu_L 0:13bc901c90aa 297 {
Manu_L 0:13bc901c90aa 298 uint32_t freq = 0;
Manu_L 0:13bc901c90aa 299
Manu_L 0:13bc901c90aa 300 if (refId == 0)
Manu_L 0:13bc901c90aa 301 {
Manu_L 0:13bc901c90aa 302 freq = device_prm.refPwmFreq;
Manu_L 0:13bc901c90aa 303 }
Manu_L 0:13bc901c90aa 304 return (freq);
Manu_L 0:13bc901c90aa 305 }
Manu_L 0:13bc901c90aa 306
Manu_L 0:13bc901c90aa 307 /******************************************************//**
Manu_L 0:13bc901c90aa 308 * @brief Immediatly stops the motor and disable the power bridge
Manu_L 0:13bc901c90aa 309 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 310 * @retval None
Manu_L 0:13bc901c90aa 311 * @note As all motors uses the same power bridge, the
Manu_L 0:13bc901c90aa 312 * power bridge will be disable only if all motors are
Manu_L 0:13bc901c90aa 313 * stopped
Manu_L 0:13bc901c90aa 314 **********************************************************/
Manu_L 0:13bc901c90aa 315 void STSPIN240_250::Stspin240_250_HardHiz(uint8_t motorId)
Manu_L 0:13bc901c90aa 316 {
Manu_L 0:13bc901c90aa 317 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 318 {
Manu_L 0:13bc901c90aa 319 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 320 }
Manu_L 0:13bc901c90aa 321 else
Manu_L 0:13bc901c90aa 322 {
Manu_L 0:13bc901c90aa 323 if (device_prm.bridgeEnabled[motorId] != FALSE)
Manu_L 0:13bc901c90aa 324 {
Manu_L 0:13bc901c90aa 325 /* Only disable bridges if dual bridge mode is disabled or */
Manu_L 0:13bc901c90aa 326 /* if all motors are inactive as there are sharing the same power stage */
Manu_L 0:13bc901c90aa 327 if ((device_prm.dualBridgeEnabled == 0)||
Manu_L 0:13bc901c90aa 328 ((motorId == 0)&&(device_prm.motionState[1] == INACTIVE))||
Manu_L 0:13bc901c90aa 329 ((motorId == 1)&&(device_prm.motionState[0] == INACTIVE)))
Manu_L 0:13bc901c90aa 330 {
Manu_L 0:13bc901c90aa 331 /* Disable the bridge */
Manu_L 0:13bc901c90aa 332 Stspin240_250_DisableBridge(motorId);
Manu_L 0:13bc901c90aa 333 }
Manu_L 0:13bc901c90aa 334 }
Manu_L 0:13bc901c90aa 335 /* Disable the PWM */
Manu_L 0:13bc901c90aa 336 Stspin240_250_HardStop(motorId);
Manu_L 0:13bc901c90aa 337 }
Manu_L 0:13bc901c90aa 338 }
Manu_L 0:13bc901c90aa 339
Manu_L 0:13bc901c90aa 340 /******************************************************//**
Manu_L 0:13bc901c90aa 341 * @brief Stops the motor without disabling the bridge
Manu_L 0:13bc901c90aa 342 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 343 * @retval none
Manu_L 0:13bc901c90aa 344 **********************************************************/
Manu_L 0:13bc901c90aa 345 void STSPIN240_250::Stspin240_250_HardStop(uint8_t motorId)
Manu_L 0:13bc901c90aa 346 {
Manu_L 0:13bc901c90aa 347 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 348 {
Manu_L 0:13bc901c90aa 349 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 350 }
Manu_L 0:13bc901c90aa 351 else if (device_prm.motionState[motorId] != INACTIVE)
Manu_L 0:13bc901c90aa 352 {
Manu_L 0:13bc901c90aa 353 /* Disable corresponding PWM */
Manu_L 0:13bc901c90aa 354 Stspin240_250_Board_PwmStop(motorId);
Manu_L 0:13bc901c90aa 355
Manu_L 0:13bc901c90aa 356 /* Set inactive state */
Manu_L 0:13bc901c90aa 357 device_prm.motionState[motorId] = INACTIVE;
Manu_L 0:13bc901c90aa 358 }
Manu_L 0:13bc901c90aa 359 }
Manu_L 0:13bc901c90aa 360
Manu_L 0:13bc901c90aa 361 /******************************************************//**
Manu_L 0:13bc901c90aa 362 * @brief Release reset (exit standby mode)
Manu_L 0:13bc901c90aa 363 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
Manu_L 0:13bc901c90aa 364 * @retval None
Manu_L 0:13bc901c90aa 365 **********************************************************/
Manu_L 0:13bc901c90aa 366 void STSPIN240_250::Stspin240_250_ReleaseReset(void)
Manu_L 0:13bc901c90aa 367 {
Manu_L 0:13bc901c90aa 368 Stspin240_250_Board_ReleaseReset();
Manu_L 0:13bc901c90aa 369
Manu_L 0:13bc901c90aa 370 /* Start PWM used for REF pin */
Manu_L 0:13bc901c90aa 371 Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
Manu_L 0:13bc901c90aa 372 }
Manu_L 0:13bc901c90aa 373
Manu_L 0:13bc901c90aa 374 /******************************************************//**
Manu_L 0:13bc901c90aa 375 * @brief Reset (enter standby mode)
Manu_L 0:13bc901c90aa 376 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
Manu_L 0:13bc901c90aa 377 * @retval None
Manu_L 0:13bc901c90aa 378 **********************************************************/
Manu_L 0:13bc901c90aa 379 void STSPIN240_250::Stspin240_250_Reset(void)
Manu_L 0:13bc901c90aa 380 {
Manu_L 0:13bc901c90aa 381 uint8_t loop;
Manu_L 0:13bc901c90aa 382 for (loop = 0; loop < STSPIN240_250_NB_MAX_MOTORS; loop++)
Manu_L 0:13bc901c90aa 383 {
Manu_L 0:13bc901c90aa 384 /* Stop motor if needed*/
Manu_L 0:13bc901c90aa 385 if (device_prm.motionState[loop] != INACTIVE)
Manu_L 0:13bc901c90aa 386 {
Manu_L 0:13bc901c90aa 387 Stspin240_250_HardStop(loop);
Manu_L 0:13bc901c90aa 388 }
Manu_L 0:13bc901c90aa 389 /* Disable bridge if needed */
Manu_L 0:13bc901c90aa 390 if (device_prm.bridgeEnabled[loop] != FALSE)
Manu_L 0:13bc901c90aa 391 {
Manu_L 0:13bc901c90aa 392 Stspin240_250_DisableBridge(loop);
Manu_L 0:13bc901c90aa 393 }
Manu_L 0:13bc901c90aa 394 }
Manu_L 0:13bc901c90aa 395
Manu_L 0:13bc901c90aa 396 /* Stop PWM used for REF pin */
Manu_L 0:13bc901c90aa 397 Stspin240_250_Board_PwmStop(PWM_REF);
Manu_L 0:13bc901c90aa 398
Manu_L 0:13bc901c90aa 399 /* Reset the STBY/RESET pin */
Manu_L 0:13bc901c90aa 400 Stspin240_250_Board_Reset();
Manu_L 0:13bc901c90aa 401 }
Manu_L 0:13bc901c90aa 402
Manu_L 0:13bc901c90aa 403 /******************************************************//**
Manu_L 0:13bc901c90aa 404 * @brief Runs the motor
Manu_L 0:13bc901c90aa 405 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 406 * @param[in] direction FORWARD or BACKWARD
Manu_L 0:13bc901c90aa 407 * @retval None
Manu_L 0:13bc901c90aa 408 * @note For unidirectionnal motor, direction parameter has
Manu_L 0:13bc901c90aa 409 * no effect
Manu_L 0:13bc901c90aa 410 **********************************************************/
Manu_L 0:13bc901c90aa 411 void STSPIN240_250::Stspin240_250_Run(uint8_t motorId, motorDir_t direction)
Manu_L 0:13bc901c90aa 412 {
Manu_L 0:13bc901c90aa 413 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 414 {
Manu_L 0:13bc901c90aa 415 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 416 }
Manu_L 0:13bc901c90aa 417 else if ((device_prm.motionState[motorId] == INACTIVE) ||
Manu_L 0:13bc901c90aa 418 (device_prm.direction[motorId] != direction))
Manu_L 0:13bc901c90aa 419 {
Manu_L 0:13bc901c90aa 420
Manu_L 0:13bc901c90aa 421 /* Release reset if required */
Manu_L 0:13bc901c90aa 422 if (Stspin240_250_GetResetState() == 0)
Manu_L 0:13bc901c90aa 423 {
Manu_L 0:13bc901c90aa 424 Stspin240_250_ReleaseReset();
Manu_L 0:13bc901c90aa 425 }
Manu_L 0:13bc901c90aa 426
Manu_L 0:13bc901c90aa 427 /* Eventually deactivate motor */
Manu_L 0:13bc901c90aa 428 if (device_prm.motionState[motorId] != INACTIVE)
Manu_L 0:13bc901c90aa 429 {
Manu_L 0:13bc901c90aa 430 Stspin240_250_HardStop(motorId);
Manu_L 0:13bc901c90aa 431 }
Manu_L 0:13bc901c90aa 432
Manu_L 0:13bc901c90aa 433 /* Set direction */
Manu_L 0:13bc901c90aa 434 Stspin240_250_SetDirection(motorId, direction);
Manu_L 0:13bc901c90aa 435
Manu_L 0:13bc901c90aa 436 /* Switch to steady state */
Manu_L 0:13bc901c90aa 437 device_prm.motionState[motorId] = STEADY;
Manu_L 0:13bc901c90aa 438
Manu_L 0:13bc901c90aa 439 /* Enable bridge */
Manu_L 0:13bc901c90aa 440 if (device_prm.bridgeEnabled[motorId] == FALSE)
Manu_L 0:13bc901c90aa 441 {
Manu_L 0:13bc901c90aa 442 Stspin240_250_EnableBridge(motorId);
Manu_L 0:13bc901c90aa 443 }
Manu_L 0:13bc901c90aa 444 /* Set PWM */
Manu_L 0:13bc901c90aa 445 Stspin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]);
Manu_L 0:13bc901c90aa 446 }
Manu_L 0:13bc901c90aa 447 }
Manu_L 0:13bc901c90aa 448
Manu_L 0:13bc901c90aa 449 /******************************************************//**
Manu_L 0:13bc901c90aa 450 * @brief Changes the PWM frequency of the bridge input
Manu_L 0:13bc901c90aa 451 * @param[in] bridgeId 0 for bridge A, 1 for bridge B
Manu_L 0:13bc901c90aa 452 * @param[in] newFreq in Hz
Manu_L 0:13bc901c90aa 453 * @retval None
Manu_L 0:13bc901c90aa 454 * @note 1)The PWM is only enabled when the motor is requested
Manu_L 0:13bc901c90aa 455 * to run.
Manu_L 0:13bc901c90aa 456 * 2) If the two bridges share the same timer, their frequency
Manu_L 0:13bc901c90aa 457 * has to be the same
Manu_L 0:13bc901c90aa 458 * 3) If the two bridges share the same timer, the frequency
Manu_L 0:13bc901c90aa 459 * is updated on the fly is there is only one motor running
Manu_L 0:13bc901c90aa 460 * on the targeted bridge.
Manu_L 0:13bc901c90aa 461 **********************************************************/
Manu_L 0:13bc901c90aa 462 void STSPIN240_250::Stspin240_250_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq)
Manu_L 0:13bc901c90aa 463 {
Manu_L 0:13bc901c90aa 464 if (bridgeId > BRIDGE_B)
Manu_L 0:13bc901c90aa 465 {
Manu_L 0:13bc901c90aa 466 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_2);
Manu_L 0:13bc901c90aa 467 }
Manu_L 0:13bc901c90aa 468
Manu_L 0:13bc901c90aa 469 if (newFreq > STSPIN240_250_MAX_PWM_FREQ)
Manu_L 0:13bc901c90aa 470 {
Manu_L 0:13bc901c90aa 471 newFreq = STSPIN240_250_MAX_PWM_FREQ;
Manu_L 0:13bc901c90aa 472 }
Manu_L 0:13bc901c90aa 473
Manu_L 0:13bc901c90aa 474 device_prm.bridgePwmFreq[bridgeId] = newFreq;
Manu_L 0:13bc901c90aa 475
Manu_L 0:13bc901c90aa 476 if (device_prm.motionState[bridgeId] != INACTIVE)
Manu_L 0:13bc901c90aa 477 {
Manu_L 0:13bc901c90aa 478 Stspin240_250_Board_PwmSetFreq(bridgeId, device_prm.bridgePwmFreq[bridgeId],device_prm.speed[bridgeId]);
Manu_L 0:13bc901c90aa 479 }
Manu_L 0:13bc901c90aa 480 }
Manu_L 0:13bc901c90aa 481
Manu_L 0:13bc901c90aa 482 /******************************************************//**
Manu_L 0:13bc901c90aa 483 * @brief Specifies the direction
Manu_L 0:13bc901c90aa 484 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 485 * @param[in] dir FORWARD or BACKWARD
Manu_L 0:13bc901c90aa 486 * @note The direction change is only applied if the device
Manu_L 0:13bc901c90aa 487 * is in INACTIVE state. To change direction while motor is
Manu_L 0:13bc901c90aa 488 * running, use the Run function
Manu_L 0:13bc901c90aa 489 * @retval None
Manu_L 0:13bc901c90aa 490 **********************************************************/
Manu_L 0:13bc901c90aa 491 void STSPIN240_250::Stspin240_250_SetDirection(uint8_t motorId, motorDir_t dir)
Manu_L 0:13bc901c90aa 492 {
Manu_L 0:13bc901c90aa 493 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 494 {
Manu_L 0:13bc901c90aa 495 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 496 }
Manu_L 0:13bc901c90aa 497 else if (device_prm.motionState[motorId] == INACTIVE)
Manu_L 0:13bc901c90aa 498 {
Manu_L 0:13bc901c90aa 499 Stspin240_250_Board_SetDirectionGpio(motorId, dir);
Manu_L 0:13bc901c90aa 500 device_prm.direction[motorId] = dir;
Manu_L 0:13bc901c90aa 501 }
Manu_L 0:13bc901c90aa 502 }
Manu_L 0:13bc901c90aa 503
Manu_L 0:13bc901c90aa 504 /******************************************************//**
Manu_L 0:13bc901c90aa 505 * @brief Set the dual bridge configuration mode
Manu_L 0:13bc901c90aa 506 * @param[in] enable 0 to disable,
Manu_L 0:13bc901c90aa 507 * 1 to enable (not supported by STSPIN250)
Manu_L 0:13bc901c90aa 508 * @retval None
Manu_L 0:13bc901c90aa 509 **********************************************************/
Manu_L 0:13bc901c90aa 510 void STSPIN240_250::Stspin240_250_SetDualFullBridgeconfig(uint8_t enable)
Manu_L 0:13bc901c90aa 511 {
Manu_L 0:13bc901c90aa 512 device_prm.dualBridgeEnabled = enable;
Manu_L 0:13bc901c90aa 513
Manu_L 0:13bc901c90aa 514 /* Check reset pin state*/
Manu_L 0:13bc901c90aa 515 if (Stspin240_250_GetResetState() != 0)
Manu_L 0:13bc901c90aa 516 {
Manu_L 0:13bc901c90aa 517 Stspin240_250_Reset();
Manu_L 0:13bc901c90aa 518 Stspin240_250_ReleaseReset();
Manu_L 0:13bc901c90aa 519 }
Manu_L 0:13bc901c90aa 520 }
Manu_L 0:13bc901c90aa 521
Manu_L 0:13bc901c90aa 522 /******************************************************//**
Manu_L 0:13bc901c90aa 523 * @brief Changes the max speed of the specified device
Manu_L 0:13bc901c90aa 524 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1)
Manu_L 0:13bc901c90aa 525 * @param[in] newMaxSpeed in % from 0 to 100
Manu_L 0:13bc901c90aa 526 * @retval true if the command is successfully executed, else false
Manu_L 0:13bc901c90aa 527 **********************************************************/
Manu_L 0:13bc901c90aa 528 bool STSPIN240_250::Stspin240_250_SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed)
Manu_L 0:13bc901c90aa 529 {
Manu_L 0:13bc901c90aa 530 bool cmdExecuted = FALSE;
Manu_L 0:13bc901c90aa 531
Manu_L 0:13bc901c90aa 532 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled])
Manu_L 0:13bc901c90aa 533 {
Manu_L 0:13bc901c90aa 534 Stspin240_250_ErrorHandler(STSPIN240_250_ERROR_1);
Manu_L 0:13bc901c90aa 535 }
Manu_L 0:13bc901c90aa 536 else
Manu_L 0:13bc901c90aa 537 {
Manu_L 0:13bc901c90aa 538 device_prm.speed[motorId] = newMaxSpeed;
Manu_L 0:13bc901c90aa 539 if (device_prm.motionState[motorId] != INACTIVE)
Manu_L 0:13bc901c90aa 540 {
Manu_L 0:13bc901c90aa 541 /* Set PWM frequency*/
Manu_L 0:13bc901c90aa 542 Stspin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]);
Manu_L 0:13bc901c90aa 543 }
Manu_L 0:13bc901c90aa 544 cmdExecuted = TRUE;
Manu_L 0:13bc901c90aa 545 }
Manu_L 0:13bc901c90aa 546 return cmdExecuted;
Manu_L 0:13bc901c90aa 547 }
Manu_L 0:13bc901c90aa 548
Manu_L 0:13bc901c90aa 549 /******************************************************//**
Manu_L 0:13bc901c90aa 550 * @brief Changes the duty cycle of the PWM used for REF
Manu_L 0:13bc901c90aa 551 * @param[in] refId 0 is the only supported id for Stspin240 or
Manu_L 0:13bc901c90aa 552 * Stspin250
Manu_L 0:13bc901c90aa 553 * @param[in] newDc new duty cycle from 0 to 100
Manu_L 0:13bc901c90aa 554 * @retval None
Manu_L 0:13bc901c90aa 555 **********************************************************/
Manu_L 0:13bc901c90aa 556 void STSPIN240_250::Stspin240_250_SetRefPwmDc(uint8_t refId, uint8_t newDc)
Manu_L 0:13bc901c90aa 557 {
Manu_L 0:13bc901c90aa 558 if (newDc > 100)
Manu_L 0:13bc901c90aa 559 {
Manu_L 0:13bc901c90aa 560 newDc = 100;
Manu_L 0:13bc901c90aa 561 }
Manu_L 0:13bc901c90aa 562
Manu_L 0:13bc901c90aa 563 device_prm.refPwmDc = newDc;
Manu_L 0:13bc901c90aa 564
Manu_L 0:13bc901c90aa 565 if (Stspin240_250_GetResetState() != 0)
Manu_L 0:13bc901c90aa 566 {
Manu_L 0:13bc901c90aa 567 /* Immediatly set the PWM frequency for ref if chip is not in reset */
Manu_L 0:13bc901c90aa 568 Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
Manu_L 0:13bc901c90aa 569 }
Manu_L 0:13bc901c90aa 570 }
Manu_L 0:13bc901c90aa 571
Manu_L 0:13bc901c90aa 572 /******************************************************//**
Manu_L 0:13bc901c90aa 573 * @brief Changes the frequency of PWM used for REF
Manu_L 0:13bc901c90aa 574 * @param[in] refId 0 is the only supported id for Stspin240 or
Manu_L 0:13bc901c90aa 575 * Stspin250
Manu_L 0:13bc901c90aa 576 * @param[in] newFreq in Hz
Manu_L 0:13bc901c90aa 577 * @retval None
Manu_L 0:13bc901c90aa 578 **********************************************************/
Manu_L 0:13bc901c90aa 579 void STSPIN240_250::Stspin240_250_SetRefPwmFreq(uint8_t refId, uint32_t newFreq)
Manu_L 0:13bc901c90aa 580 {
Manu_L 0:13bc901c90aa 581 if (newFreq > STSPIN240_250_MAX_PWM_FREQ)
Manu_L 0:13bc901c90aa 582 {
Manu_L 0:13bc901c90aa 583 newFreq = STSPIN240_250_MAX_PWM_FREQ;
Manu_L 0:13bc901c90aa 584 }
Manu_L 0:13bc901c90aa 585
Manu_L 0:13bc901c90aa 586 device_prm.refPwmFreq = newFreq;
Manu_L 0:13bc901c90aa 587
Manu_L 0:13bc901c90aa 588 if (Stspin240_250_GetResetState() != 0)
Manu_L 0:13bc901c90aa 589 {
Manu_L 0:13bc901c90aa 590 /* Immediatly set the PWM frequency for ref if chip is not in reset */
Manu_L 0:13bc901c90aa 591 Stspin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc);
Manu_L 0:13bc901c90aa 592 }
Manu_L 0:13bc901c90aa 593 }
Manu_L 0:13bc901c90aa 594
Manu_L 0:13bc901c90aa 595
Manu_L 0:13bc901c90aa 596 /******************************************************//**
Manu_L 0:13bc901c90aa 597 * @brief Get the status of the bridge enabling of the corresponding bridge
Manu_L 0:13bc901c90aa 598 * @retval State of the Enable&Fault pin (shared for bridge A and B)
Manu_L 0:13bc901c90aa 599 **********************************************************/
Manu_L 0:13bc901c90aa 600 uint8_t STSPIN240_250::Stspin240_250_GetResetState(void)
Manu_L 0:13bc901c90aa 601 {
Manu_L 0:13bc901c90aa 602 uint8_t status = Stspin240_250_Board_GetResetPinState();
Manu_L 0:13bc901c90aa 603
Manu_L 0:13bc901c90aa 604 return (status);
Manu_L 0:13bc901c90aa 605 }
Manu_L 0:13bc901c90aa 606
Manu_L 0:13bc901c90aa 607 /******************************************************//**
Manu_L 0:13bc901c90aa 608 * @brief Set the parameters of the device to values of pInitPrm structure
Manu_L 0:13bc901c90aa 609 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1)
Manu_L 0:13bc901c90aa 610 * @param pInitPrm pointer to a structure containing the initial device parameters
Manu_L 0:13bc901c90aa 611 * @retval None
Manu_L 0:13bc901c90aa 612 **********************************************************/
Manu_L 0:13bc901c90aa 613 void STSPIN240_250::Stspin240_250_SetDeviceParamsToGivenValues(Stspin240_250_Init_t *pInitPrm)
Manu_L 0:13bc901c90aa 614 {
Manu_L 0:13bc901c90aa 615 uint32_t i;
Manu_L 0:13bc901c90aa 616
Manu_L 0:13bc901c90aa 617 device_prm.dualBridgeEnabled = pInitPrm->dualBridgeEnabled;
Manu_L 0:13bc901c90aa 618
Manu_L 0:13bc901c90aa 619 device_prm.bridgePwmFreq[BRIDGE_A] = pInitPrm->bridgePwmFreq[BRIDGE_A];
Manu_L 0:13bc901c90aa 620 device_prm.bridgePwmFreq[BRIDGE_B] = pInitPrm->bridgePwmFreq[BRIDGE_B];;
Manu_L 0:13bc901c90aa 621
Manu_L 0:13bc901c90aa 622 device_prm.refPwmFreq = pInitPrm->refPwmFreq;
Manu_L 0:13bc901c90aa 623 device_prm.refPwmDc = pInitPrm->refPwmDc;
Manu_L 0:13bc901c90aa 624
Manu_L 0:13bc901c90aa 625 for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
Manu_L 0:13bc901c90aa 626 {
Manu_L 0:13bc901c90aa 627 device_prm.speed[i] = 100;
Manu_L 0:13bc901c90aa 628 device_prm.direction[i] = FORWARD;
Manu_L 0:13bc901c90aa 629 device_prm.motionState[i] = INACTIVE;
Manu_L 0:13bc901c90aa 630 }
Manu_L 0:13bc901c90aa 631 for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++)
Manu_L 0:13bc901c90aa 632 {
Manu_L 0:13bc901c90aa 633 device_prm.bridgeEnabled[i] = FALSE;
Manu_L 0:13bc901c90aa 634 }
Manu_L 0:13bc901c90aa 635 }
Manu_L 0:13bc901c90aa 636 /******************************************************//**
Manu_L 0:13bc901c90aa 637 * @brief Sets the parameters of the device to predefined values
Manu_L 0:13bc901c90aa 638 * from stspin240_250_target_config.h
Manu_L 0:13bc901c90aa 639 * @retval None
Manu_L 0:13bc901c90aa 640 **********************************************************/
Manu_L 0:13bc901c90aa 641 void STSPIN240_250::Stspin240_250_SetDeviceParamsToPredefinedValues(void)
Manu_L 0:13bc901c90aa 642 {
Manu_L 0:13bc901c90aa 643 uint32_t i;
Manu_L 0:13bc901c90aa 644
Manu_L 0:13bc901c90aa 645 device_prm.dualBridgeEnabled = STSPIN240_250_CONF_PARAM_DUAL_BRIDGE_ENABLING;
Manu_L 0:13bc901c90aa 646
Manu_L 0:13bc901c90aa 647 device_prm.bridgePwmFreq[BRIDGE_A] = STSPIN240_250_CONF_PARAM_FREQ_PWM_A;
Manu_L 0:13bc901c90aa 648 device_prm.bridgePwmFreq[BRIDGE_B] = STSPIN240_250_CONF_PARAM_FREQ_PWM_B;
Manu_L 0:13bc901c90aa 649
Manu_L 0:13bc901c90aa 650 device_prm.refPwmFreq = STSPIN240_250_CONF_PARAM_FREQ_PWM_REF;
Manu_L 0:13bc901c90aa 651 device_prm.refPwmDc = STSPIN240_250_CONF_PARAM_DC_PWM_REF;
Manu_L 0:13bc901c90aa 652
Manu_L 0:13bc901c90aa 653 for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++)
Manu_L 0:13bc901c90aa 654 {
Manu_L 0:13bc901c90aa 655 device_prm.speed[i] = 100;
Manu_L 0:13bc901c90aa 656 device_prm.direction[i] = FORWARD;
Manu_L 0:13bc901c90aa 657 device_prm.motionState[i] = INACTIVE;
Manu_L 0:13bc901c90aa 658 }
Manu_L 0:13bc901c90aa 659 for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++)
Manu_L 0:13bc901c90aa 660 {
Manu_L 0:13bc901c90aa 661 device_prm.bridgeEnabled[i] = FALSE;
Manu_L 0:13bc901c90aa 662 }
Manu_L 0:13bc901c90aa 663 }
Manu_L 0:13bc901c90aa 664 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/