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
Child:
1:a68f20f0d233
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.h
Manu_L 0:13bc901c90aa 4 * @author IPC Rennes
Manu_L 0:13bc901c90aa 5 * @version V1.0.0
Manu_L 0:13bc901c90aa 6 * @date April 20th, 2016
Manu_L 0:13bc901c90aa 7 * @brief This file contains the class of a Stspin240_250 Motor Control component.
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 /* Define to prevent recursive inclusion -------------------------------------*/
Manu_L 0:13bc901c90aa 40
Manu_L 0:13bc901c90aa 41 #ifndef __STSPIN240_250_CLASS_H
Manu_L 0:13bc901c90aa 42 #define __STSPIN240_250_CLASS_H
Manu_L 0:13bc901c90aa 43
Manu_L 0:13bc901c90aa 44
Manu_L 0:13bc901c90aa 45 /* Includes ------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 46
Manu_L 0:13bc901c90aa 47 /* ACTION 1 ------------------------------------------------------------------*
Manu_L 0:13bc901c90aa 48 * Include here platform specific header files. *
Manu_L 0:13bc901c90aa 49 *----------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 50 #include "mbed.h"
Manu_L 0:13bc901c90aa 51 /* ACTION 2 ------------------------------------------------------------------*
Manu_L 0:13bc901c90aa 52 * Include here component specific header files. *
Manu_L 0:13bc901c90aa 53 *----------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 54 #include "stspin240_250.h"
Manu_L 0:13bc901c90aa 55 /* ACTION 3 ------------------------------------------------------------------*
Manu_L 0:13bc901c90aa 56 * Include here interface specific header files. *
Manu_L 0:13bc901c90aa 57 * *
Manu_L 0:13bc901c90aa 58 * Example: *
Manu_L 0:13bc901c90aa 59 * #include "../Interfaces/Humidity_class.h" *
Manu_L 0:13bc901c90aa 60 * #include "../Interfaces/Temperature_class.h" *
Manu_L 0:13bc901c90aa 61 *----------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 62 #include "../Interfaces/BDCMotor_class.h"
Manu_L 0:13bc901c90aa 63
Manu_L 0:13bc901c90aa 64 /* Defines -------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 65
Manu_L 0:13bc901c90aa 66 /* MCU wait time in ms after power bridges are enabled */
Manu_L 0:13bc901c90aa 67 #define BRIDGE_TURN_ON_DELAY (1)
Manu_L 0:13bc901c90aa 68
Manu_L 0:13bc901c90aa 69 /* MCU wait time in ms after exit standby mode */
Manu_L 0:13bc901c90aa 70 #define EXIT_STANDBY_MODE_DELAY (1)
Manu_L 0:13bc901c90aa 71
Manu_L 0:13bc901c90aa 72 /* Classes -------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 73
Manu_L 0:13bc901c90aa 74
Manu_L 0:13bc901c90aa 75 /**
Manu_L 0:13bc901c90aa 76 * @brief Class representing a Stspin240_250 component.
Manu_L 0:13bc901c90aa 77 */
Manu_L 0:13bc901c90aa 78 class STSPIN240_250 : public BDCMotor
Manu_L 0:13bc901c90aa 79 {
Manu_L 0:13bc901c90aa 80 public:
Manu_L 0:13bc901c90aa 81
Manu_L 0:13bc901c90aa 82 /*** Constructor and Destructor Methods ***/
Manu_L 0:13bc901c90aa 83
Manu_L 0:13bc901c90aa 84 /**
Manu_L 0:13bc901c90aa 85 * @brief Constructor.
Manu_L 0:13bc901c90aa 86 * @param flag_and_enable_pin pin name of the EN pin of the component.
Manu_L 0:13bc901c90aa 87 * @param standby_reset_pin pin name of the STBY\RST pin of the component.
Manu_L 0:13bc901c90aa 88 * @param pwmA_pin pin name for the PWM input for bridge A
Manu_L 0:13bc901c90aa 89 * @param pwmB_pin pin name for the PWM input for bridge B
Manu_L 0:13bc901c90aa 90 * @param dirA_pin pin name for the direction pinfor bridge A
Manu_L 0:13bc901c90aa 91 * @param dirB_pin pin name for the direction pinfor bridge B
Manu_L 0:13bc901c90aa 92 */
Manu_L 0:13bc901c90aa 93 STSPIN240_250(PinName flag_and_enable_pin, PinName standby_reset_pin, PinName dirA_pin, PinName dirB_pin, PinName pwmA_pin, PinName pwmB_pin, PinName pwmRef_pin) : BDCMotor(), flag_and_enable(flag_and_enable_pin), standby_reset(standby_reset_pin), dirA(dirA_pin), dirB(dirB_pin), pwmA(pwmA_pin), pwmB(pwmB_pin), pwmRef(pwmRef_pin)
Manu_L 0:13bc901c90aa 94 {
Manu_L 0:13bc901c90aa 95 /* Checking stackability. */
Manu_L 0:13bc901c90aa 96 if (!(numberOfDevices < MAX_NUMBER_OF_DEVICES))
Manu_L 0:13bc901c90aa 97 error("Instantiation of the Stpin240_250 component failed: it can be stacked up to %d times.\r\n", MAX_NUMBER_OF_DEVICES);
Manu_L 0:13bc901c90aa 98
Manu_L 0:13bc901c90aa 99 /* ACTION 4 ----------------------------------------------------------*
Manu_L 0:13bc901c90aa 100 * Initialize here the component's member variables, one variable per *
Manu_L 0:13bc901c90aa 101 * line. *
Manu_L 0:13bc901c90aa 102 * *
Manu_L 0:13bc901c90aa 103 * Example: *
Manu_L 0:13bc901c90aa 104 * measure = 0; *
Manu_L 0:13bc901c90aa 105 * instance_id = number_of_instances++; *
Manu_L 0:13bc901c90aa 106 *--------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 107 errorHandlerCallback = 0;
Manu_L 0:13bc901c90aa 108 deviceInstance = numberOfDevices++;
Manu_L 0:13bc901c90aa 109 }
Manu_L 0:13bc901c90aa 110
Manu_L 0:13bc901c90aa 111 /**
Manu_L 0:13bc901c90aa 112 * @brief Destructor.
Manu_L 0:13bc901c90aa 113 */
Manu_L 0:13bc901c90aa 114 virtual ~STSPIN240_250(void) {}
Manu_L 0:13bc901c90aa 115
Manu_L 0:13bc901c90aa 116
Manu_L 0:13bc901c90aa 117 /*** Public Component Related Methods ***/
Manu_L 0:13bc901c90aa 118
Manu_L 0:13bc901c90aa 119 /* ACTION 5 --------------------------------------------------------------*
Manu_L 0:13bc901c90aa 120 * Implement here the component's public methods, as wrappers of the C *
Manu_L 0:13bc901c90aa 121 * component's functions. *
Manu_L 0:13bc901c90aa 122 * They should be: *
Manu_L 0:13bc901c90aa 123 * + Methods with the same name of the C component's virtual table's *
Manu_L 0:13bc901c90aa 124 * functions (1); *
Manu_L 0:13bc901c90aa 125 * + Methods with the same name of the C component's extended virtual *
Manu_L 0:13bc901c90aa 126 * table's functions, if any (2). *
Manu_L 0:13bc901c90aa 127 * *
Manu_L 0:13bc901c90aa 128 * Example: *
Manu_L 0:13bc901c90aa 129 * virtual int GetValue(float *pData) //(1) *
Manu_L 0:13bc901c90aa 130 * { *
Manu_L 0:13bc901c90aa 131 * return COMPONENT_GetValue(float *pfData); *
Manu_L 0:13bc901c90aa 132 * } *
Manu_L 0:13bc901c90aa 133 * *
Manu_L 0:13bc901c90aa 134 * virtual int EnableFeature(void) //(2) *
Manu_L 0:13bc901c90aa 135 * { *
Manu_L 0:13bc901c90aa 136 * return COMPONENT_EnableFeature(); *
Manu_L 0:13bc901c90aa 137 * } *
Manu_L 0:13bc901c90aa 138 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 139
Manu_L 0:13bc901c90aa 140 /**
Manu_L 0:13bc901c90aa 141 * @brief Public functions inherited from the Component Class
Manu_L 0:13bc901c90aa 142 */
Manu_L 0:13bc901c90aa 143
Manu_L 0:13bc901c90aa 144 /**
Manu_L 0:13bc901c90aa 145 * @brief Initialize the component.
Manu_L 0:13bc901c90aa 146 * @param init Pointer to device specific initalization structure.
Manu_L 0:13bc901c90aa 147 * @retval "0" in case of success, an error code otherwise.
Manu_L 0:13bc901c90aa 148 */
Manu_L 0:13bc901c90aa 149 virtual int Init(void *init = NULL)
Manu_L 0:13bc901c90aa 150 {
Manu_L 0:13bc901c90aa 151 return (int) Stspin240_250_Init((void *) init);
Manu_L 0:13bc901c90aa 152 }
Manu_L 0:13bc901c90aa 153
Manu_L 0:13bc901c90aa 154 /**
Manu_L 0:13bc901c90aa 155 * @brief Getting the ID of the component.
Manu_L 0:13bc901c90aa 156 * @param id Pointer to an allocated variable to store the ID into.
Manu_L 0:13bc901c90aa 157 * @retval "0" in case of success, an error code otherwise.
Manu_L 0:13bc901c90aa 158 */
Manu_L 0:13bc901c90aa 159 virtual int ReadID(uint8_t *id = NULL)
Manu_L 0:13bc901c90aa 160 {
Manu_L 0:13bc901c90aa 161 return (int) Stspin240_250_ReadId((uint8_t *) id);
Manu_L 0:13bc901c90aa 162 }
Manu_L 0:13bc901c90aa 163
Manu_L 0:13bc901c90aa 164 /**
Manu_L 0:13bc901c90aa 165 * @brief Public functions inherited from the BCDMotor Class
Manu_L 0:13bc901c90aa 166 */
Manu_L 0:13bc901c90aa 167
Manu_L 0:13bc901c90aa 168 /**
Manu_L 0:13bc901c90aa 169 * @brief Disabling the specified bridge.
Manu_L 0:13bc901c90aa 170 * @param bridgeId from 0 for bridge A to 1 for bridge B.
Manu_L 0:13bc901c90aa 171 * @retval None.
Manu_L 0:13bc901c90aa 172 */
Manu_L 0:13bc901c90aa 173 virtual void DisableBridge(unsigned int bridgeId)
Manu_L 0:13bc901c90aa 174 {
Manu_L 0:13bc901c90aa 175 Stspin240_250_DisableBridge(bridgeId);
Manu_L 0:13bc901c90aa 176 }
Manu_L 0:13bc901c90aa 177
Manu_L 0:13bc901c90aa 178 /**
Manu_L 0:13bc901c90aa 179 * @brief Enabling the specified bridge.
Manu_L 0:13bc901c90aa 180 * @param bridgeId from 0 for bridge A to 1 for bridge B
Manu_L 0:13bc901c90aa 181 * @retval None.
Manu_L 0:13bc901c90aa 182 */
Manu_L 0:13bc901c90aa 183 virtual void EnableBridge(unsigned int bridgeId)
Manu_L 0:13bc901c90aa 184 {
Manu_L 0:13bc901c90aa 185 Stspin240_250_EnableBridge(bridgeId);
Manu_L 0:13bc901c90aa 186 }
Manu_L 0:13bc901c90aa 187
Manu_L 0:13bc901c90aa 188 /**
Manu_L 0:13bc901c90aa 189 * @brief Getting the PWM frequency of the specified bridge;
Manu_L 0:13bc901c90aa 190 * @param bridgeId from 0 for bridge A to 1 for bridge B.
Manu_L 0:13bc901c90aa 191 * @retval The frequency in Hz of the specified bridge input PWM.
Manu_L 0:13bc901c90aa 192 */
Manu_L 0:13bc901c90aa 193 virtual unsigned int GetBridgeInputPwmFreq(unsigned int bridgeId)
Manu_L 0:13bc901c90aa 194 {
Manu_L 0:13bc901c90aa 195 return (unsigned int) Stspin240_250_GetBridgeInputPwmFreq(bridgeId);
Manu_L 0:13bc901c90aa 196 }
Manu_L 0:13bc901c90aa 197
Manu_L 0:13bc901c90aa 198 /**
Manu_L 0:13bc901c90aa 199 * @brief Getting the bridge status.
Manu_L 0:13bc901c90aa 200 * @param bridgeId from 0 for bridge A to 1 for bridge B.
Manu_L 0:13bc901c90aa 201 * @retval The status.
Manu_L 0:13bc901c90aa 202 */
Manu_L 0:13bc901c90aa 203 virtual unsigned int GetBridgeStatus(unsigned int bridgeId)
Manu_L 0:13bc901c90aa 204 {
Manu_L 0:13bc901c90aa 205 return (unsigned int) Stspin240_250_GetBridgeStatus();
Manu_L 0:13bc901c90aa 206 }
Manu_L 0:13bc901c90aa 207
Manu_L 0:13bc901c90aa 208 /**
Manu_L 0:13bc901c90aa 209 * @brief Getting the device State.
Manu_L 0:13bc901c90aa 210 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 211 * @retval The device state (STEADY or INACTIVE)
Manu_L 0:13bc901c90aa 212 */
Manu_L 0:13bc901c90aa 213 virtual motorState_t GetDeviceState(unsigned int motorId)
Manu_L 0:13bc901c90aa 214 {
Manu_L 0:13bc901c90aa 215 return (motorState_t) Stspin240_250_GetDeviceState(motorId);
Manu_L 0:13bc901c90aa 216 }
Manu_L 0:13bc901c90aa 217
Manu_L 0:13bc901c90aa 218 /**
Manu_L 0:13bc901c90aa 219 * @brief Getting the duty cycle of the PWM used for REF.
Manu_L 0:13bc901c90aa 220 * @param refId Id of the reference PWM signal.
Manu_L 0:13bc901c90aa 221 * @retval duty cycle in % (from 0 to 100)
Manu_L 0:13bc901c90aa 222 */
Manu_L 0:13bc901c90aa 223 virtual unsigned int GetRefPwmDc(unsigned int refId)
Manu_L 0:13bc901c90aa 224 {
Manu_L 0:13bc901c90aa 225 return (unsigned int) Stspin240_250_GetRefPwmDc(refId);
Manu_L 0:13bc901c90aa 226 }
Manu_L 0:13bc901c90aa 227
Manu_L 0:13bc901c90aa 228 /**
Manu_L 0:13bc901c90aa 229 * @brief Getting the frequency of the PWM used for REF.
Manu_L 0:13bc901c90aa 230 * @param refId Id of the reference PWM signal.
Manu_L 0:13bc901c90aa 231 * @retval frequency in Hz.
Manu_L 0:13bc901c90aa 232 */
Manu_L 0:13bc901c90aa 233 virtual unsigned int GetRefPwmFreq(unsigned int refId)
Manu_L 0:13bc901c90aa 234 {
Manu_L 0:13bc901c90aa 235 return (unsigned int) Stspin240_250_GetRefPwmFreq(refId);
Manu_L 0:13bc901c90aa 236 }
Manu_L 0:13bc901c90aa 237
Manu_L 0:13bc901c90aa 238 /**
Manu_L 0:13bc901c90aa 239 * @brief Getting the current speed in % of the specified motor.
Manu_L 0:13bc901c90aa 240 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 241 * @retval The current speed in %.
Manu_L 0:13bc901c90aa 242 */
Manu_L 0:13bc901c90aa 243 virtual unsigned int GetSpeed(unsigned int motorId)
Manu_L 0:13bc901c90aa 244 {
Manu_L 0:13bc901c90aa 245 return (unsigned int) Stspin240_250_GetCurrentSpeed(motorId);
Manu_L 0:13bc901c90aa 246 }
Manu_L 0:13bc901c90aa 247
Manu_L 0:13bc901c90aa 248 /**
Manu_L 0:13bc901c90aa 249 * @brief Stopping the motor and disabling the power bridge immediately.
Manu_L 0:13bc901c90aa 250 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 251 * @retval None.
Manu_L 0:13bc901c90aa 252 */
Manu_L 0:13bc901c90aa 253 virtual void HardHiZ(unsigned int motorId)
Manu_L 0:13bc901c90aa 254 {
Manu_L 0:13bc901c90aa 255 Stspin240_250_HardHiz(motorId);
Manu_L 0:13bc901c90aa 256 }
Manu_L 0:13bc901c90aa 257
Manu_L 0:13bc901c90aa 258 /**
Manu_L 0:13bc901c90aa 259 * @brief Stopping the motor immediately.
Manu_L 0:13bc901c90aa 260 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 261 * @retval None.
Manu_L 0:13bc901c90aa 262 */
Manu_L 0:13bc901c90aa 263 virtual void HardStop(unsigned int motorId)
Manu_L 0:13bc901c90aa 264 {
Manu_L 0:13bc901c90aa 265 Stspin240_250_HardStop(motorId);
Manu_L 0:13bc901c90aa 266 }
Manu_L 0:13bc901c90aa 267
Manu_L 0:13bc901c90aa 268 /**
Manu_L 0:13bc901c90aa 269 * @brief Running the motor.
Manu_L 0:13bc901c90aa 270 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 271 * @param direction The direction of rotation.
Manu_L 0:13bc901c90aa 272 * @retval None.
Manu_L 0:13bc901c90aa 273 */
Manu_L 0:13bc901c90aa 274 virtual void Run(unsigned int motorId, direction_t direction)
Manu_L 0:13bc901c90aa 275 {
Manu_L 0:13bc901c90aa 276 Stspin240_250_Run(motorId, (motorDir_t) direction);
Manu_L 0:13bc901c90aa 277 }
Manu_L 0:13bc901c90aa 278
Manu_L 0:13bc901c90aa 279 /**
Manu_L 0:13bc901c90aa 280 * @brief Setting the PWM frequency of the specified bridge.
Manu_L 0:13bc901c90aa 281 * @param bridgeId from 0 for bridge A to 1 for bridge B.
Manu_L 0:13bc901c90aa 282 * @param frequency of the PWM in Hz
Manu_L 0:13bc901c90aa 283 * @retval None.
Manu_L 0:13bc901c90aa 284 */
Manu_L 0:13bc901c90aa 285 virtual void SetBridgeInputPwmFreq(unsigned int bridgeId, unsigned int frequency)
Manu_L 0:13bc901c90aa 286 {
Manu_L 0:13bc901c90aa 287 Stspin240_250_SetBridgeInputPwmFreq(bridgeId, frequency);
Manu_L 0:13bc901c90aa 288 }
Manu_L 0:13bc901c90aa 289
Manu_L 0:13bc901c90aa 290 /**
Manu_L 0:13bc901c90aa 291 * @brief Setting the dual bridge configuration mode.
Manu_L 0:13bc901c90aa 292 * @param configuration. The bridge configuration.
Manu_L 0:13bc901c90aa 293 * @retval None.
Manu_L 0:13bc901c90aa 294 */
Manu_L 0:13bc901c90aa 295 virtual void SetDualFullBridgeconfig(unsigned int configuration)
Manu_L 0:13bc901c90aa 296 {
Manu_L 0:13bc901c90aa 297 Stspin240_250_SetDualFullBridgeconfig(configuration);
Manu_L 0:13bc901c90aa 298 }
Manu_L 0:13bc901c90aa 299
Manu_L 0:13bc901c90aa 300 /**
Manu_L 0:13bc901c90aa 301 * @brief Setting the duty cycle of the PWM used for REF.
Manu_L 0:13bc901c90aa 302 * @param refId Id of the reference PWM signal.
Manu_L 0:13bc901c90aa 303 * @param newDc new duty cycle from 0 to 100
Manu_L 0:13bc901c90aa 304 * @retval None.
Manu_L 0:13bc901c90aa 305 */
Manu_L 0:13bc901c90aa 306 virtual void SetRefPwmDc(unsigned int refId, unsigned int newDc)
Manu_L 0:13bc901c90aa 307 {
Manu_L 0:13bc901c90aa 308 Stspin240_250_SetRefPwmDc(refId, newDc);
Manu_L 0:13bc901c90aa 309 }
Manu_L 0:13bc901c90aa 310
Manu_L 0:13bc901c90aa 311 /**
Manu_L 0:13bc901c90aa 312 * @brief Setting the frequency of the PWM used for REF.
Manu_L 0:13bc901c90aa 313 * @param refId Id of the reference PWM signal.
Manu_L 0:13bc901c90aa 314 * @param frequency in Hz.
Manu_L 0:13bc901c90aa 315 * @retval None.
Manu_L 0:13bc901c90aa 316 */
Manu_L 0:13bc901c90aa 317 virtual void SetRefPwmFreq(unsigned int refId, unsigned int frequency)
Manu_L 0:13bc901c90aa 318 {
Manu_L 0:13bc901c90aa 319 Stspin240_250_SetRefPwmFreq(refId, frequency);
Manu_L 0:13bc901c90aa 320 }
Manu_L 0:13bc901c90aa 321
Manu_L 0:13bc901c90aa 322 /**
Manu_L 0:13bc901c90aa 323 * @brief Setting the speed in %.
Manu_L 0:13bc901c90aa 324 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 325 * @param speed The new speed in %.
Manu_L 0:13bc901c90aa 326 * @retval "true" in case of success, "false" otherwise.
Manu_L 0:13bc901c90aa 327 */
Manu_L 0:13bc901c90aa 328 virtual bool SetSpeed(unsigned int motorId, unsigned int speed)
Manu_L 0:13bc901c90aa 329 {
Manu_L 0:13bc901c90aa 330 return (bool) Stspin240_250_SetMaxSpeed(motorId, speed);
Manu_L 0:13bc901c90aa 331 }
Manu_L 0:13bc901c90aa 332
Manu_L 0:13bc901c90aa 333 /**
Manu_L 0:13bc901c90aa 334 * @brief Public functions NOT inherited
Manu_L 0:13bc901c90aa 335 */
Manu_L 0:13bc901c90aa 336
Manu_L 0:13bc901c90aa 337 /**
Manu_L 0:13bc901c90aa 338 * @brief Attaching an error handler.
Manu_L 0:13bc901c90aa 339 * @param fptr An error handler.
Manu_L 0:13bc901c90aa 340 * @retval None.
Manu_L 0:13bc901c90aa 341 */
Manu_L 0:13bc901c90aa 342 virtual void AttachErrorHandler(void (*fptr)(uint16_t error))
Manu_L 0:13bc901c90aa 343 {
Manu_L 0:13bc901c90aa 344 Stspin240_250_AttachErrorHandler((void (*)(uint16_t error)) fptr);
Manu_L 0:13bc901c90aa 345 }
Manu_L 0:13bc901c90aa 346
Manu_L 0:13bc901c90aa 347 /**
Manu_L 0:13bc901c90aa 348 * @brief Getting the motor current direction.
Manu_L 0:13bc901c90aa 349 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 350 * @retval direction The direction of rotation.
Manu_L 0:13bc901c90aa 351 */
Manu_L 0:13bc901c90aa 352 virtual direction_t GetDirection(unsigned int motorId)
Manu_L 0:13bc901c90aa 353 {
Manu_L 0:13bc901c90aa 354 return (direction_t) Stspin240_250_GetDirection(motorId);
Manu_L 0:13bc901c90aa 355 }
Manu_L 0:13bc901c90aa 356
Manu_L 0:13bc901c90aa 357 /**
Manu_L 0:13bc901c90aa 358 * @brief Getting the version of the firmware.
Manu_L 0:13bc901c90aa 359 * @param None.
Manu_L 0:13bc901c90aa 360 * @retval The version of the firmware.
Manu_L 0:13bc901c90aa 361 */
Manu_L 0:13bc901c90aa 362 virtual unsigned int GetFwVersion(void)
Manu_L 0:13bc901c90aa 363 {
Manu_L 0:13bc901c90aa 364 return (unsigned int) Stspin240_250_GetFwVersion();
Manu_L 0:13bc901c90aa 365 }
Manu_L 0:13bc901c90aa 366
Manu_L 0:13bc901c90aa 367 /**
Manu_L 0:13bc901c90aa 368 * @brief Releasing the reset (exiting standby mode).
Manu_L 0:13bc901c90aa 369 * @param None.
Manu_L 0:13bc901c90aa 370 * @retval None.
Manu_L 0:13bc901c90aa 371 */
Manu_L 0:13bc901c90aa 372 virtual void ReleaseReset(void)
Manu_L 0:13bc901c90aa 373 {
Manu_L 0:13bc901c90aa 374 Stspin240_250_ReleaseReset();
Manu_L 0:13bc901c90aa 375 }
Manu_L 0:13bc901c90aa 376
Manu_L 0:13bc901c90aa 377 /**
Manu_L 0:13bc901c90aa 378 * @brief Reseting (entering standby mode).
Manu_L 0:13bc901c90aa 379 * @param None.
Manu_L 0:13bc901c90aa 380 * @retval None.
Manu_L 0:13bc901c90aa 381 */
Manu_L 0:13bc901c90aa 382 virtual void Reset(void)
Manu_L 0:13bc901c90aa 383 {
Manu_L 0:13bc901c90aa 384 Stspin240_250_Reset();
Manu_L 0:13bc901c90aa 385 }
Manu_L 0:13bc901c90aa 386
Manu_L 0:13bc901c90aa 387 /**
Manu_L 0:13bc901c90aa 388 * @brief Setting the direction of rotation of the firmware.
Manu_L 0:13bc901c90aa 389 * @param motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1).
Manu_L 0:13bc901c90aa 390 * @param direction The direction of rotation.
Manu_L 0:13bc901c90aa 391 * @retval None
Manu_L 0:13bc901c90aa 392 */
Manu_L 0:13bc901c90aa 393 virtual void SetDirection(unsigned int motorId, direction_t direction)
Manu_L 0:13bc901c90aa 394 {
Manu_L 0:13bc901c90aa 395 Stspin240_250_SetDirection(motorId, (motorDir_t) direction);
Manu_L 0:13bc901c90aa 396 }
Manu_L 0:13bc901c90aa 397
Manu_L 0:13bc901c90aa 398 /**
Manu_L 0:13bc901c90aa 399 * @brief Public static functions
Manu_L 0:13bc901c90aa 400 */
Manu_L 0:13bc901c90aa 401 static uint8_t GetNbDevices(void)
Manu_L 0:13bc901c90aa 402 {
Manu_L 0:13bc901c90aa 403 return numberOfDevices;
Manu_L 0:13bc901c90aa 404 }
Manu_L 0:13bc901c90aa 405
Manu_L 0:13bc901c90aa 406 /*** Public Interrupt Related Methods ***/
Manu_L 0:13bc901c90aa 407
Manu_L 0:13bc901c90aa 408 /* ACTION 6 --------------------------------------------------------------*
Manu_L 0:13bc901c90aa 409 * Implement here interrupt related methods, if any. *
Manu_L 0:13bc901c90aa 410 * Note that interrupt handling is platform dependent, e.g.: *
Manu_L 0:13bc901c90aa 411 * + mbed: *
Manu_L 0:13bc901c90aa 412 * InterruptIn feature_irq(pin); //Interrupt object. *
Manu_L 0:13bc901c90aa 413 * feature_irq.rise(callback); //Attach a callback. *
Manu_L 0:13bc901c90aa 414 * feature_irq.mode(PullNone); //Set interrupt mode. *
Manu_L 0:13bc901c90aa 415 * feature_irq.enable_irq(); //Enable interrupt. *
Manu_L 0:13bc901c90aa 416 * feature_irq.disable_irq(); //Disable interrupt. *
Manu_L 0:13bc901c90aa 417 * + Arduino: *
Manu_L 0:13bc901c90aa 418 * attachInterrupt(pin, callback, RISING); //Attach a callback. *
Manu_L 0:13bc901c90aa 419 * detachInterrupt(pin); //Detach a callback. *
Manu_L 0:13bc901c90aa 420 * *
Manu_L 0:13bc901c90aa 421 * Example (mbed): *
Manu_L 0:13bc901c90aa 422 * void AttachFeatureIRQ(void (*fptr) (void)) *
Manu_L 0:13bc901c90aa 423 * { *
Manu_L 0:13bc901c90aa 424 * feature_irq.rise(fptr); *
Manu_L 0:13bc901c90aa 425 * } *
Manu_L 0:13bc901c90aa 426 * *
Manu_L 0:13bc901c90aa 427 * void EnableFeatureIRQ(void) *
Manu_L 0:13bc901c90aa 428 * { *
Manu_L 0:13bc901c90aa 429 * feature_irq.enable_irq(); *
Manu_L 0:13bc901c90aa 430 * } *
Manu_L 0:13bc901c90aa 431 * *
Manu_L 0:13bc901c90aa 432 * void DisableFeatureIRQ(void) *
Manu_L 0:13bc901c90aa 433 * { *
Manu_L 0:13bc901c90aa 434 * feature_irq.disable_irq(); *
Manu_L 0:13bc901c90aa 435 * } *
Manu_L 0:13bc901c90aa 436 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 437 /**
Manu_L 0:13bc901c90aa 438 * @brief Attaching an interrupt handler to the FLAG interrupt.
Manu_L 0:13bc901c90aa 439 * @param fptr An interrupt handler.
Manu_L 0:13bc901c90aa 440 * @retval None.
Manu_L 0:13bc901c90aa 441 */
Manu_L 0:13bc901c90aa 442 void AttachFlagIRQ(void (*fptr)(void))
Manu_L 0:13bc901c90aa 443 {
Manu_L 0:13bc901c90aa 444 flag_and_enable.mode(PullDown);
Manu_L 0:13bc901c90aa 445 flag_and_enable.fall(fptr);
Manu_L 0:13bc901c90aa 446 }
Manu_L 0:13bc901c90aa 447
Manu_L 0:13bc901c90aa 448 /**
Manu_L 0:13bc901c90aa 449 * @brief Enabling the FLAG interrupt handling.
Manu_L 0:13bc901c90aa 450 * @param None.
Manu_L 0:13bc901c90aa 451 * @retval None.
Manu_L 0:13bc901c90aa 452 */
Manu_L 0:13bc901c90aa 453 void EnableFlagIRQ(void)
Manu_L 0:13bc901c90aa 454 {
Manu_L 0:13bc901c90aa 455 flag_and_enable.enable_irq();
Manu_L 0:13bc901c90aa 456 }
Manu_L 0:13bc901c90aa 457
Manu_L 0:13bc901c90aa 458 /**
Manu_L 0:13bc901c90aa 459 * @brief Disabling the FLAG interrupt handling.
Manu_L 0:13bc901c90aa 460 * @param None.
Manu_L 0:13bc901c90aa 461 * @retval None.
Manu_L 0:13bc901c90aa 462 */
Manu_L 0:13bc901c90aa 463 void DisableFlagIRQ(void)
Manu_L 0:13bc901c90aa 464 {
Manu_L 0:13bc901c90aa 465 flag_and_enable.disable_irq();
Manu_L 0:13bc901c90aa 466 }
Manu_L 0:13bc901c90aa 467
Manu_L 0:13bc901c90aa 468 protected:
Manu_L 0:13bc901c90aa 469
Manu_L 0:13bc901c90aa 470 /*** Protected Component Related Methods ***/
Manu_L 0:13bc901c90aa 471
Manu_L 0:13bc901c90aa 472 /* ACTION 7 --------------------------------------------------------------*
Manu_L 0:13bc901c90aa 473 * Declare here the component's specific methods. *
Manu_L 0:13bc901c90aa 474 * They should be: *
Manu_L 0:13bc901c90aa 475 * + Methods with the same name of the C component's virtual table's *
Manu_L 0:13bc901c90aa 476 * functions (1); *
Manu_L 0:13bc901c90aa 477 * + Methods with the same name of the C component's extended virtual *
Manu_L 0:13bc901c90aa 478 * table's functions, if any (2); *
Manu_L 0:13bc901c90aa 479 * + Helper methods, if any, like functions declared in the component's *
Manu_L 0:13bc901c90aa 480 * source files but not pointed by the component's virtual table (3). *
Manu_L 0:13bc901c90aa 481 * *
Manu_L 0:13bc901c90aa 482 * Example: *
Manu_L 0:13bc901c90aa 483 * Status_t COMPONENT_GetValue(float *f); //(1) *
Manu_L 0:13bc901c90aa 484 * Status_t COMPONENT_EnableFeature(void); //(2) *
Manu_L 0:13bc901c90aa 485 * Status_t COMPONENT_ComputeAverage(void); //(3) *
Manu_L 0:13bc901c90aa 486 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 487
Manu_L 0:13bc901c90aa 488 Status_t Stspin240_250_Init(void *init);
Manu_L 0:13bc901c90aa 489 Status_t Stspin240_250_ReadId(uint8_t *id);
Manu_L 0:13bc901c90aa 490 void Stspin240_250_AttachErrorHandler(void (*callback)(uint16_t error));
Manu_L 0:13bc901c90aa 491 void Stspin240_250_DisableBridge(uint8_t bridgeId);
Manu_L 0:13bc901c90aa 492 void Stspin240_250_EnableBridge(uint8_t bridgeId);
Manu_L 0:13bc901c90aa 493 void Stspin240_250_ErrorHandler(uint16_t error);
Manu_L 0:13bc901c90aa 494 uint32_t Stspin240_250_GetBridgeInputPwmFreq(uint8_t bridgeId);
Manu_L 0:13bc901c90aa 495 uint16_t Stspin240_250_GetBridgeStatus(void);
Manu_L 0:13bc901c90aa 496 uint16_t Stspin240_250_GetCurrentSpeed(uint8_t motorId);
Manu_L 0:13bc901c90aa 497 motorState_t Stspin240_250_GetDeviceState(uint8_t motorId);
Manu_L 0:13bc901c90aa 498 motorDir_t Stspin240_250_GetDirection(uint8_t motorId);
Manu_L 0:13bc901c90aa 499 uint32_t Stspin240_250_GetFwVersion(void);
Manu_L 0:13bc901c90aa 500 uint8_t Stspin240_250_GetRefPwmDc(uint8_t refId);
Manu_L 0:13bc901c90aa 501 uint32_t Stspin240_250_GetRefPwmFreq(uint8_t refId);
Manu_L 0:13bc901c90aa 502 void Stspin240_250_HardHiz(uint8_t motorId);
Manu_L 0:13bc901c90aa 503 void Stspin240_250_HardStop(uint8_t motorId);
Manu_L 0:13bc901c90aa 504 void Stspin240_250_ReleaseReset(void);
Manu_L 0:13bc901c90aa 505 void Stspin240_250_Reset(void);
Manu_L 0:13bc901c90aa 506 void Stspin240_250_Run(uint8_t motorId, motorDir_t direction);
Manu_L 0:13bc901c90aa 507 void Stspin240_250_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq);
Manu_L 0:13bc901c90aa 508 void Stspin240_250_SetDirection(uint8_t motorId, motorDir_t dir);
Manu_L 0:13bc901c90aa 509 void Stspin240_250_SetDualFullBridgeconfig(uint8_t enable);
Manu_L 0:13bc901c90aa 510 bool Stspin240_250_SetMaxSpeed(uint8_t motorId,uint16_t newMaxSpeed);
Manu_L 0:13bc901c90aa 511 void Stspin240_250_SetRefPwmDc(uint8_t refId, uint8_t newDc);
Manu_L 0:13bc901c90aa 512 void Stspin240_250_SetRefPwmFreq(uint8_t refId, uint32_t newFreq);
Manu_L 0:13bc901c90aa 513
Manu_L 0:13bc901c90aa 514 /**
Manu_L 0:13bc901c90aa 515 * @brief Functions to initialize the registers
Manu_L 0:13bc901c90aa 516 */
Manu_L 0:13bc901c90aa 517 void Stspin240_250_SetDeviceParamsToGivenValues(Stspin240_250_Init_t *pInitPrm);
Manu_L 0:13bc901c90aa 518 void Stspin240_250_SetDeviceParamsToPredefinedValues(void);
Manu_L 0:13bc901c90aa 519
Manu_L 0:13bc901c90aa 520 /**
Manu_L 0:13bc901c90aa 521 * @brief Get the state of the standby/reset pin
Manu_L 0:13bc901c90aa 522 */
Manu_L 0:13bc901c90aa 523 uint8_t Stspin240_250_GetResetState(void);
Manu_L 0:13bc901c90aa 524
Manu_L 0:13bc901c90aa 525 /*** Component's I/O Methods ***/
Manu_L 0:13bc901c90aa 526
Manu_L 0:13bc901c90aa 527 /* ACTION 8 --------------------------------------------------------------*
Manu_L 0:13bc901c90aa 528 * Implement here other I/O methods beyond those already implemented *
Manu_L 0:13bc901c90aa 529 * above, which are declared extern within the component's header file. *
Manu_L 0:13bc901c90aa 530 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 531 /**
Manu_L 0:13bc901c90aa 532 * @brief Making the CPU wait.
Manu_L 0:13bc901c90aa 533 * @param None.
Manu_L 0:13bc901c90aa 534 * @retval None.
Manu_L 0:13bc901c90aa 535 */
Manu_L 0:13bc901c90aa 536 void Stspin240_250_Board_Delay(uint32_t delay)
Manu_L 0:13bc901c90aa 537 {
Manu_L 0:13bc901c90aa 538 wait_ms(delay);
Manu_L 0:13bc901c90aa 539 }
Manu_L 0:13bc901c90aa 540
Manu_L 0:13bc901c90aa 541 /**
Manu_L 0:13bc901c90aa 542 * @brief Disable bridge.
Manu_L 0:13bc901c90aa 543 * @param None.
Manu_L 0:13bc901c90aa 544 * @retval None.
Manu_L 0:13bc901c90aa 545 */
Manu_L 0:13bc901c90aa 546 void Stspin240_250_Board_DisableBridge(void)
Manu_L 0:13bc901c90aa 547 {
Manu_L 0:13bc901c90aa 548 flag_and_enable.disable_irq();
Manu_L 0:13bc901c90aa 549 flag_and_enable.mode(PullDown);
Manu_L 0:13bc901c90aa 550 }
Manu_L 0:13bc901c90aa 551
Manu_L 0:13bc901c90aa 552 /**
Manu_L 0:13bc901c90aa 553 * @brief Enable bridge.
Manu_L 0:13bc901c90aa 554 * @param addDelay if different from 0, a delay is added after bridge activation..
Manu_L 0:13bc901c90aa 555 * @retval None.
Manu_L 0:13bc901c90aa 556 */
Manu_L 0:13bc901c90aa 557 void Stspin240_250_Board_EnableBridge(uint8_t addDelay)
Manu_L 0:13bc901c90aa 558 {
Manu_L 0:13bc901c90aa 559 flag_and_enable.mode(PullUp);
Manu_L 0:13bc901c90aa 560 if (addDelay)
Manu_L 0:13bc901c90aa 561 {
Manu_L 0:13bc901c90aa 562 Stspin240_250_Board_Delay(BRIDGE_TURN_ON_DELAY);
Manu_L 0:13bc901c90aa 563 }
Manu_L 0:13bc901c90aa 564 flag_and_enable.enable_irq();
Manu_L 0:13bc901c90aa 565 }
Manu_L 0:13bc901c90aa 566
Manu_L 0:13bc901c90aa 567 /**
Manu_L 0:13bc901c90aa 568 * @brief Get the status of the reset Pin.
Manu_L 0:13bc901c90aa 569 * @param None.
Manu_L 0:13bc901c90aa 570 * @retval None.
Manu_L 0:13bc901c90aa 571 */
Manu_L 0:13bc901c90aa 572 uint16_t Stspin240_250_Board_GetResetPinState(void)
Manu_L 0:13bc901c90aa 573 {
Manu_L 0:13bc901c90aa 574 return((uint16_t)flag_and_enable.read());
Manu_L 0:13bc901c90aa 575 }
Manu_L 0:13bc901c90aa 576
Manu_L 0:13bc901c90aa 577 /**
Manu_L 0:13bc901c90aa 578 * @brief Get the status of the flag and enable Pin.
Manu_L 0:13bc901c90aa 579 * @param None.
Manu_L 0:13bc901c90aa 580 * @retval None.
Manu_L 0:13bc901c90aa 581 */
Manu_L 0:13bc901c90aa 582 uint16_t Stspin240_250_Board_GetFaultPinState(void)
Manu_L 0:13bc901c90aa 583 {
Manu_L 0:13bc901c90aa 584 return((uint16_t)flag_and_enable.read());
Manu_L 0:13bc901c90aa 585 }
Manu_L 0:13bc901c90aa 586
Manu_L 0:13bc901c90aa 587 /**
Manu_L 0:13bc901c90aa 588 * @brief Deinitialising the PWM.
Manu_L 0:13bc901c90aa 589 * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
Manu_L 0:13bc901c90aa 590 * @retval None.
Manu_L 0:13bc901c90aa 591 */
Manu_L 0:13bc901c90aa 592 void Stspin240_250_Board_PwmDeInit(uint8_t pwmId)
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 /**
Manu_L 0:13bc901c90aa 598 * @brief Initialising the PWM.
Manu_L 0:13bc901c90aa 599 * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
Manu_L 0:13bc901c90aa 600 * @param onlyChannel.
Manu_L 0:13bc901c90aa 601 * @retval None.
Manu_L 0:13bc901c90aa 602 */
Manu_L 0:13bc901c90aa 603 void Stspin240_250_Board_PwmInit(uint8_t pwmId, uint8_t onlyChannel)
Manu_L 0:13bc901c90aa 604 {
Manu_L 0:13bc901c90aa 605
Manu_L 0:13bc901c90aa 606 }
Manu_L 0:13bc901c90aa 607
Manu_L 0:13bc901c90aa 608 /**
Manu_L 0:13bc901c90aa 609 * @brief Setting the frequency of PWM.
Manu_L 0:13bc901c90aa 610 * The frequency of bridge A and B controls directly the speed of the device.
Manu_L 0:13bc901c90aa 611 * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
Manu_L 0:13bc901c90aa 612 * @param newFreq frequency to apply in Hz.
Manu_L 0:13bc901c90aa 613 * @param duty Duty cycle to use from 0 to 100.
Manu_L 0:13bc901c90aa 614 * @retval None.
Manu_L 0:13bc901c90aa 615 */
Manu_L 0:13bc901c90aa 616 void Stspin240_250_Board_PwmSetFreq(int8_t pwmId, uint32_t newFreq, uint8_t duty)
Manu_L 0:13bc901c90aa 617 {
Manu_L 0:13bc901c90aa 618 /* Computing the period of PWM. */
Manu_L 0:13bc901c90aa 619 double period = 1.0f / newFreq;
Manu_L 0:13bc901c90aa 620
Manu_L 0:13bc901c90aa 621 switch (pwmId)
Manu_L 0:13bc901c90aa 622 {
Manu_L 0:13bc901c90aa 623 case 0:
Manu_L 0:13bc901c90aa 624 default:
Manu_L 0:13bc901c90aa 625 /* Setting the period and the duty-cycle of PWM A. */
Manu_L 0:13bc901c90aa 626 pwmA.period(period);
Manu_L 0:13bc901c90aa 627 pwmA.write((float)(duty / 100.0f));
Manu_L 0:13bc901c90aa 628 break;
Manu_L 0:13bc901c90aa 629 case 1:
Manu_L 0:13bc901c90aa 630 /* Setting the period and the duty-cycle of PWM B. */
Manu_L 0:13bc901c90aa 631 pwmB.period(period);
Manu_L 0:13bc901c90aa 632 pwmB.write((float)(duty / 100.0f));
Manu_L 0:13bc901c90aa 633 break;
Manu_L 0:13bc901c90aa 634 case 2:
Manu_L 0:13bc901c90aa 635 /* Setting the period and the duty-cycle of PWM Ref. */
Manu_L 0:13bc901c90aa 636 pwmRef.period(period);
Manu_L 0:13bc901c90aa 637 pwmRef.write((float)(duty / 100.0f));
Manu_L 0:13bc901c90aa 638 break;
Manu_L 0:13bc901c90aa 639 }
Manu_L 0:13bc901c90aa 640 }
Manu_L 0:13bc901c90aa 641
Manu_L 0:13bc901c90aa 642 /**
Manu_L 0:13bc901c90aa 643 * @brief Stopping the PWM.
Manu_L 0:13bc901c90aa 644 * @param pwmId 0 for bridge A PWM, 1 for bridge B PWM, 2 for REF PWM.
Manu_L 0:13bc901c90aa 645 * @retval None.
Manu_L 0:13bc901c90aa 646 */
Manu_L 0:13bc901c90aa 647 void Stspin240_250_Board_PwmStop(uint8_t pwmId)
Manu_L 0:13bc901c90aa 648 {
Manu_L 0:13bc901c90aa 649 switch (pwmId)
Manu_L 0:13bc901c90aa 650 {
Manu_L 0:13bc901c90aa 651 case 0:
Manu_L 0:13bc901c90aa 652 default:
Manu_L 0:13bc901c90aa 653 pwmA.write(0.0f);
Manu_L 0:13bc901c90aa 654 break;
Manu_L 0:13bc901c90aa 655 case 1:
Manu_L 0:13bc901c90aa 656 pwmB.write(0.0f);
Manu_L 0:13bc901c90aa 657 break;
Manu_L 0:13bc901c90aa 658 case 2:
Manu_L 0:13bc901c90aa 659 pwmRef.write(0.0f);
Manu_L 0:13bc901c90aa 660 break;
Manu_L 0:13bc901c90aa 661 }
Manu_L 0:13bc901c90aa 662 }
Manu_L 0:13bc901c90aa 663
Manu_L 0:13bc901c90aa 664 /**
Manu_L 0:13bc901c90aa 665 * @brief Putting the device in standby mode.
Manu_L 0:13bc901c90aa 666 * @param None.
Manu_L 0:13bc901c90aa 667 * @retval None.
Manu_L 0:13bc901c90aa 668 */
Manu_L 0:13bc901c90aa 669 void Stspin240_250_Board_ReleaseReset(void)
Manu_L 0:13bc901c90aa 670 {
Manu_L 0:13bc901c90aa 671 standby_reset = 1;
Manu_L 0:13bc901c90aa 672 Stspin240_250_Board_Delay(EXIT_STANDBY_MODE_DELAY);
Manu_L 0:13bc901c90aa 673 }
Manu_L 0:13bc901c90aa 674
Manu_L 0:13bc901c90aa 675 /**
Manu_L 0:13bc901c90aa 676 * @brief Putting the device in reset mode.
Manu_L 0:13bc901c90aa 677 * @param None.
Manu_L 0:13bc901c90aa 678 * @retval None.
Manu_L 0:13bc901c90aa 679 */
Manu_L 0:13bc901c90aa 680 void Stspin240_250_Board_Reset(void)
Manu_L 0:13bc901c90aa 681 {
Manu_L 0:13bc901c90aa 682 standby_reset = 0;
Manu_L 0:13bc901c90aa 683 }
Manu_L 0:13bc901c90aa 684
Manu_L 0:13bc901c90aa 685 /**
Manu_L 0:13bc901c90aa 686 * @brief Setting the direction of rotation.
Manu_L 0:13bc901c90aa 687 * @param bridgeId 0 for bridge A, 1 for bridge B.
Manu_L 0:13bc901c90aa 688 * @param gpioState direction of rotation: "1" for forward, "0" for backward.
Manu_L 0:13bc901c90aa 689 * @retval None.
Manu_L 0:13bc901c90aa 690 */
Manu_L 0:13bc901c90aa 691 void Stspin240_250_Board_SetDirectionGpio(uint8_t bridgeId, uint8_t gpioState)
Manu_L 0:13bc901c90aa 692 {
Manu_L 0:13bc901c90aa 693 if (bridgeId == 0)
Manu_L 0:13bc901c90aa 694 {
Manu_L 0:13bc901c90aa 695 dirA = gpioState;
Manu_L 0:13bc901c90aa 696 }
Manu_L 0:13bc901c90aa 697 else
Manu_L 0:13bc901c90aa 698 {
Manu_L 0:13bc901c90aa 699 dirB = gpioState;
Manu_L 0:13bc901c90aa 700 }
Manu_L 0:13bc901c90aa 701 }
Manu_L 0:13bc901c90aa 702
Manu_L 0:13bc901c90aa 703 /*** Component's Instance Variables ***/
Manu_L 0:13bc901c90aa 704
Manu_L 0:13bc901c90aa 705 /* ACTION 9 --------------------------------------------------------------*
Manu_L 0:13bc901c90aa 706 * Declare here interrupt related variables, if needed. *
Manu_L 0:13bc901c90aa 707 * Note that interrupt handling is platform dependent, see *
Manu_L 0:13bc901c90aa 708 * "Interrupt Related Methods" above. *
Manu_L 0:13bc901c90aa 709 * *
Manu_L 0:13bc901c90aa 710 * Example: *
Manu_L 0:13bc901c90aa 711 * + mbed: *
Manu_L 0:13bc901c90aa 712 * InterruptIn feature_irq; *
Manu_L 0:13bc901c90aa 713 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 714 /* Flag Interrupt. */
Manu_L 0:13bc901c90aa 715 InterruptIn flag_and_enable;
Manu_L 0:13bc901c90aa 716
Manu_L 0:13bc901c90aa 717 /* ACTION 10 -------------------------------------------------------------*
Manu_L 0:13bc901c90aa 718 * Declare here other pin related variables, if needed. *
Manu_L 0:13bc901c90aa 719 * *
Manu_L 0:13bc901c90aa 720 * Example: *
Manu_L 0:13bc901c90aa 721 * + mbed: *
Manu_L 0:13bc901c90aa 722 * DigitalOut standby_reset; *
Manu_L 0:13bc901c90aa 723 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 724 /* Standby/reset pin. */
Manu_L 0:13bc901c90aa 725 DigitalOut standby_reset;
Manu_L 0:13bc901c90aa 726
Manu_L 0:13bc901c90aa 727 /* Direction pin of bridge A. */
Manu_L 0:13bc901c90aa 728 DigitalOut dirA;
Manu_L 0:13bc901c90aa 729
Manu_L 0:13bc901c90aa 730 /* Direction pin of bridge B. */
Manu_L 0:13bc901c90aa 731 DigitalOut dirB;
Manu_L 0:13bc901c90aa 732
Manu_L 0:13bc901c90aa 733 /* Pulse Width Modulation pin for bridge A input. */
Manu_L 0:13bc901c90aa 734 PwmOut pwmA;
Manu_L 0:13bc901c90aa 735
Manu_L 0:13bc901c90aa 736 /* Pulse Width Modulation pin for bridge A input. */
Manu_L 0:13bc901c90aa 737 PwmOut pwmB;
Manu_L 0:13bc901c90aa 738
Manu_L 0:13bc901c90aa 739 /* Pulse Width Modulation pin for Ref signal. */
Manu_L 0:13bc901c90aa 740 PwmOut pwmRef;
Manu_L 0:13bc901c90aa 741
Manu_L 0:13bc901c90aa 742 /* ACTION 11 -------------------------------------------------------------*
Manu_L 0:13bc901c90aa 743 * Declare here communication related variables, if needed. *
Manu_L 0:13bc901c90aa 744 * *
Manu_L 0:13bc901c90aa 745 * Example: *
Manu_L 0:13bc901c90aa 746 * + mbed: *
Manu_L 0:13bc901c90aa 747 * DigitalOut ssel; *
Manu_L 0:13bc901c90aa 748 * DevSPI &dev_spi; *
Manu_L 0:13bc901c90aa 749 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 750
Manu_L 0:13bc901c90aa 751 /* ACTION 12 -------------------------------------------------------------*
Manu_L 0:13bc901c90aa 752 * Declare here identity related variables, if needed. *
Manu_L 0:13bc901c90aa 753 * Note that there should be only a unique identifier for each component, *
Manu_L 0:13bc901c90aa 754 * which should be the "who_am_i" parameter. *
Manu_L 0:13bc901c90aa 755 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 756 /* Identity */
Manu_L 0:13bc901c90aa 757 uint8_t who_am_i;
Manu_L 0:13bc901c90aa 758
Manu_L 0:13bc901c90aa 759 /* ACTION 13 -------------------------------------------------------------*
Manu_L 0:13bc901c90aa 760 * Declare here the component's static and non-static data, one variable *
Manu_L 0:13bc901c90aa 761 * per line. *
Manu_L 0:13bc901c90aa 762 * *
Manu_L 0:13bc901c90aa 763 * Example: *
Manu_L 0:13bc901c90aa 764 * float measure; *
Manu_L 0:13bc901c90aa 765 * int instance_id; *
Manu_L 0:13bc901c90aa 766 * static int number_of_instances; *
Manu_L 0:13bc901c90aa 767 *------------------------------------------------------------------------*/
Manu_L 0:13bc901c90aa 768 /* Data. */
Manu_L 0:13bc901c90aa 769 void (*errorHandlerCallback)(uint16_t error);
Manu_L 0:13bc901c90aa 770 deviceParams_t device_prm;
Manu_L 0:13bc901c90aa 771 uint8_t deviceInstance;
Manu_L 0:13bc901c90aa 772
Manu_L 0:13bc901c90aa 773
Manu_L 0:13bc901c90aa 774 /* Static data. */
Manu_L 0:13bc901c90aa 775 static uint8_t numberOfDevices;
Manu_L 0:13bc901c90aa 776 static uint8_t arrayNbMaxMotorsByConfig[2];
Manu_L 0:13bc901c90aa 777
Manu_L 0:13bc901c90aa 778 public:
Manu_L 0:13bc901c90aa 779
Manu_L 0:13bc901c90aa 780 /* Static data. */
Manu_L 0:13bc901c90aa 781
Manu_L 0:13bc901c90aa 782 };
Manu_L 0:13bc901c90aa 783
Manu_L 0:13bc901c90aa 784 #endif // __STSPIN240_250_CLASS_H
Manu_L 0:13bc901c90aa 785
Manu_L 0:13bc901c90aa 786 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/