Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of X_NUCLEO_IHM04A1 by
l6206_class.h
00001 /** 00002 ****************************************************************************** 00003 * @file l6206_class.h 00004 * @author IPC Rennes 00005 * @version V1.1.0 00006 * @date March 02, 2016 00007 * @brief L6206 driver (dual full bridge driver) 00008 * @note (C) COPYRIGHT 2015 STMicroelectronics 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 00040 /* Generated with STM32CubeTOO -----------------------------------------------*/ 00041 00042 00043 /* Revision ------------------------------------------------------------------*/ 00044 /* 00045 Repository: http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev 00046 Branch/Trunk/Tag: trunk 00047 Based on: X-CUBE-SPN4/trunk/Drivers/BSP/Components/l6206/l6206.h 00048 Revision: 0 00049 */ 00050 00051 00052 /* Define to prevent recursive inclusion -------------------------------------*/ 00053 00054 #ifndef __L6206_CLASS_H 00055 #define __L6206_CLASS_H 00056 00057 00058 /* Includes ------------------------------------------------------------------*/ 00059 00060 /* ACTION 1 ------------------------------------------------------------------* 00061 * Include here platform specific header files. * 00062 *----------------------------------------------------------------------------*/ 00063 #include "mbed.h" 00064 /* ACTION 2 ------------------------------------------------------------------* 00065 * Include here component specific header files. * 00066 *----------------------------------------------------------------------------*/ 00067 #include "l6206.h" 00068 /* ACTION 3 ------------------------------------------------------------------* 00069 * Include here interface specific header files. * 00070 * * 00071 * Example: * 00072 * #include "HumiditySensor.h" * 00073 * #include "TemperatureSensor.h" * 00074 *----------------------------------------------------------------------------*/ 00075 #include "BCDMotor.h" 00076 00077 00078 /* Private constants ---------------------------------------------------------*/ 00079 00080 /** @defgroup L6206_Private_Constants L6206 Private Constants 00081 * @{ 00082 */ 00083 00084 /// The Number of L6206 devices required for initialisation is not supported 00085 #define L6206_ERROR_0 (0x8000) 00086 /// Error: Access a motor index greater than the one of the current brigde configuration 00087 #define L6206_ERROR_1 (0x8001) 00088 /// Error: Access a motor index which is not bidirectionnal 00089 #define L6206_ERROR_2 (0x8002) 00090 00091 /// Maximum frequency of the PWMs in Hz 00092 #define L6206_MAX_PWM_FREQ (100000) 00093 00094 /// Minimum frequency of the PWMs in Hz 00095 #define L6206_MIN_PWM_FREQ (2) 00096 00097 /// Bridge Input 1A 00098 #define INPUT_1A (0) 00099 /// Bridge Input 2A 00100 #define INPUT_2A (1) 00101 /// Bridge Input 1B 00102 #define INPUT_1B (2) 00103 /// Bridge Input 2B 00104 #define INPUT_2B (3) 00105 00106 /// Bridge A 00107 #define BRIDGE_A (0) 00108 /// Bridge B 00109 #define BRIDGE_B (1) 00110 00111 00112 00113 00114 00115 /* Classes -------------------------------------------------------------------*/ 00116 00117 /** 00118 * @brief Class representing a L6206 component. 00119 */ 00120 class L6206 : public BDCMotor 00121 { 00122 public: 00123 00124 /*** Constructor and Destructor Methods ***/ 00125 00126 /** 00127 * @brief Constructor. 00128 */ 00129 L6206(PinName EN_flag_A, PinName EN_flag_B, PinName pwm_1A, PinName pwm_2A, PinName pwm_1B, PinName pwm_2B) : BDCMotor(), flag_A_irq(EN_flag_A), flag_B_irq(EN_flag_B), EN_flag_A(EN_flag_A), EN_flag_B(EN_flag_B), pwm_1A(pwm_1A), pwm_2A(pwm_2A), pwm_1B(pwm_1B), pwm_2B(pwm_2B) 00130 { 00131 /* ACTION 4 ----------------------------------------------------------* 00132 * Initialize here the component's member variables, one variable per * 00133 * line. * 00134 * * 00135 * Example: * 00136 * measure = 0; * 00137 * instance_id = number_of_instances++; * 00138 *--------------------------------------------------------------------*/ 00139 00140 flagInterruptCallback = 0; 00141 errorHandlerCallback = 0; 00142 numberOfDevices = 0; 00143 deviceInstance = 0; 00144 } 00145 00146 /** 00147 * @brief Destructor. 00148 */ 00149 virtual ~L6206(void) {} 00150 00151 00152 /*** Public Component Related Methods ***/ 00153 00154 /* ACTION 5 --------------------------------------------------------------* 00155 * Implement here the component's public methods, as wrappers of the C * 00156 * component's functions. * 00157 * They should be: * 00158 * + Methods with the same name of the C component's virtual table's * 00159 * functions (1); * 00160 * + Methods with the same name of the C component's extended virtual * 00161 * table's functions, if any (2). * 00162 * * 00163 * Example: * 00164 * virtual int GetValue(float *f) //(1) * 00165 * { * 00166 * return COMPONENT_GetValue(float *f); * 00167 * } * 00168 * * 00169 * virtual int EnableFeature(void) //(2) * 00170 * { * 00171 * return COMPONENT_EnableFeature(); * 00172 * } * 00173 *------------------------------------------------------------------------*/ 00174 00175 /** 00176 * @brief Initializing the component. 00177 * @param init Pointer to device specific initalization structure. 00178 * @retval "0" in case of success, an error code otherwise. 00179 */ 00180 virtual int Init(void *init = NULL) 00181 { 00182 return (int) L6206_Init((void *) init); 00183 } 00184 00185 /** 00186 * @brief Getting the ID of the component. 00187 * @param id Pointer to an allocated variable to store the ID into. 00188 * @retval "0" in case of success, an error code otherwise. 00189 */ 00190 virtual int ReadID(uint8_t *id = NULL) 00191 { 00192 return (int) L6206_ReadId((uint8_t *) id); 00193 } 00194 00195 00196 /** 00197 * @brief Attaches a user callback to the error Handler. 00198 * The call back will be then called each time the library detects an error 00199 * @param[in] callback Name of the callback to attach to the error Hanlder 00200 * @retval None 00201 */ 00202 virtual void AttachErrorHandler(void (*callback)(uint16_t error)) 00203 { 00204 L6206_AttachErrorHandler((void (*)(uint16_t error)) callback); 00205 } 00206 00207 00208 /** 00209 * @brief Attaches a user callback to the flag Interrupt 00210 * The call back will be then called each time the status 00211 * flag pin will be pulled down due to the occurrence of 00212 * a programmed alarms ( OCD, thermal alert) 00213 * @param[in] callback Name of the callback to attach 00214 * to the Flag Interrupt 00215 * @retval None 00216 */ 00217 virtual void AttachFlagInterrupt(void (*callback)(void)) 00218 { 00219 L6206_AttachFlagInterrupt((void (*)(void)) callback); 00220 } 00221 00222 /** 00223 * @brief Returns the current speed of the specified motor 00224 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00225 * @retval current speed in % from 0 to 100 00226 */ 00227 virtual unsigned int GetSpeed(unsigned int motorId) 00228 { 00229 return (unsigned int) L6206_GetCurrentSpeed((uint8_t) motorId); 00230 } 00231 00232 /** 00233 * @brief Returns the device state 00234 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00235 * @retval State (STEADY or INACTIVE) 00236 */ 00237 virtual motorState_t GetDeviceState(unsigned int motorId) 00238 { 00239 return (motorState_t) L6206_GetDeviceState((uint8_t) motorId); 00240 } 00241 00242 /** 00243 * @brief Returns the FW version of the library 00244 * @retval L6206_FW_VERSION 00245 */ 00246 virtual uint8_t GetFwVersion(void) 00247 { 00248 return (uint8_t) L6206_GetFwVersion(); 00249 } 00250 00251 /** 00252 * @brief Returns the max speed of the specified motor 00253 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00254 * @retval maxSpeed in % from 0 to 100 00255 */ 00256 virtual uint16_t GetMaxSpeed(unsigned int motorId) 00257 { 00258 return (uint16_t) L6206_GetMaxSpeed((uint8_t) motorId); 00259 } 00260 00261 /** 00262 * @brief Stops the motor without disabling the bridge 00263 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00264 * @retval none 00265 */ 00266 virtual void HardStop(unsigned int motorId) 00267 { 00268 L6206_HardStop((uint8_t) motorId); 00269 } 00270 00271 /** 00272 * @brief Runs the motor 00273 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00274 * @param[in] direction FORWARD or BACKWARD 00275 * @retval None 00276 * @note For unidirectionnal motor, direction parameter has no effect 00277 */ 00278 virtual void Run(unsigned int motorId, direction_t direction) 00279 { 00280 L6206_Run((uint8_t) motorId, (motorDir_t) direction); 00281 } 00282 00283 /** 00284 * @brief Changes the max speed of the specified device 00285 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00286 * @param[in] newMaxSpeed in % from 0 to 100 00287 * @retval true if the command is successfully executed, else false 00288 */ 00289 virtual bool SetSpeed(unsigned int motorId, unsigned int newMaxSpeed) 00290 { 00291 return (bool) L6206_SetMaxSpeed((uint8_t) motorId, (uint16_t) newMaxSpeed); 00292 } 00293 00294 /** 00295 * @brief Disable the specified bridge 00296 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00297 * @retval None 00298 * @note When input of different brigdes are parallelized 00299 * together, the disabling of one bridge leads to the disabling 00300 * of the second one 00301 */ 00302 virtual void DisableBridge(unsigned int bridgeId) 00303 { 00304 L6206_DisableBridge((uint8_t) bridgeId); 00305 } 00306 00307 /** 00308 * @brief Enable the specified bridge 00309 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00310 * @retval None 00311 * @note When input of different brigdes are parallelized 00312 * together, the enabling of one bridge leads to the enabling 00313 * of the second one 00314 */ 00315 virtual void EnableBridge(unsigned int bridgeId) 00316 { 00317 L6206_EnableBridge((uint8_t) bridgeId); 00318 } 00319 00320 /** 00321 * @brief Get the status of the bridge enabling of the corresponding bridge 00322 * @param[in] bridgeId from 0 for bridge A to 1 for bridge B 00323 * @retval State of the Enable&Flag pin of the corresponding bridge (1 set, 0 for reset) 00324 */ 00325 virtual unsigned int GetBridgeStatus(unsigned int bridgeId) 00326 { 00327 return (unsigned int) L6206_GetBridgeStatus((uint8_t) bridgeId); 00328 } 00329 00330 /** 00331 * @brief Immediatly stops the motor and disable the power bridge 00332 * @param[in] motorId from 0 to MAX_NUMBER_OF_BRUSH_DC_MOTORS 00333 * @retval None 00334 * @note if two motors uses the same power bridge, the 00335 * power bridge will be disable only if the two motors are stopped 00336 */ 00337 virtual void HardHiZ(unsigned int motorId) 00338 { 00339 L6206_HardHiz((uint8_t) motorId); 00340 } 00341 00342 /** 00343 * @brief Error handler which calls the user callback (if defined) 00344 * @param[in] error Number of the error 00345 * @retval None 00346 */ 00347 virtual void ErrorHandler(uint16_t error) 00348 { 00349 L6206_ErrorHandler((uint16_t) error); 00350 } 00351 00352 /** 00353 * @brief Set dual full bridge parallelling configuration 00354 * @param[in] newConfig bridge configuration to apply from 00355 * dualFullBridgeConfig_t enum 00356 * @retval None 00357 */ 00358 virtual void SetDualFullBridgeConfig(unsigned int newConfig) 00359 { 00360 L6206_SetDualFullBridgeConfig((uint8_t) newConfig); 00361 } 00362 00363 /** 00364 * @brief Get the PWM frequency of the specified bridge 00365 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00366 * @retval Freq in Hz 00367 */ 00368 virtual unsigned int GetBridgeInputPwmFreq(unsigned int bridgeId) 00369 { 00370 return (unsigned int) L6206_GetBridgeInputPwmFreq((uint8_t) bridgeId); 00371 } 00372 00373 /** 00374 * @brief Changes the PWM frequency of the bridge input 00375 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00376 * @param[in] newFreq in Hz 00377 * @retval None 00378 */ 00379 virtual void SetBridgeInputPwmFreq(unsigned int bridgeId, unsigned int newFreq) 00380 { 00381 L6206_SetBridgeInputPwmFreq((uint8_t) bridgeId, (uint32_t) newFreq); 00382 } 00383 00384 /** 00385 * @brief Sets the number of devices to be used 00386 * @param[in] nbDevices (from 1 to MAX_NUMBER_OF_DEVICES) 00387 * @retval TRUE if successfull, FALSE if failure, attempt to set a number of 00388 * devices greater than MAX_NUMBER_OF_DEVICES 00389 */ 00390 virtual bool SetNbDevices(uint8_t nbDevices) 00391 { 00392 return (bool) L6206_SetNbDevices((uint8_t) nbDevices); 00393 } 00394 00395 00396 /*** Public Interrupt Related Methods ***/ 00397 00398 /* ACTION 6 --------------------------------------------------------------* 00399 * Implement here interrupt related methods, if any. * 00400 * Note that interrupt handling is platform dependent, e.g.: * 00401 * + mbed: * 00402 * InterruptIn feature_irq(pin); //Interrupt object. * 00403 * feature_irq.fall(callback); //Attach a callback. * 00404 * feature_irq.mode(PullNone); //Set interrupt mode. * 00405 * feature_irq.enable_irq(); //Enable interrupt. * 00406 * feature_irq.disable_irq(); //Disable interrupt. * 00407 * + Arduino: * 00408 * attachInterrupt(pin, callback, RISING); //Attach a callback. * 00409 * detachInterrupt(pin); //Detach a callback. * 00410 * * 00411 * Example (mbed): * 00412 * void AttachFeatureIRQ(void (*fptr) (void)) * 00413 * { * 00414 * feature_irq.fall(fptr); * 00415 * } * 00416 * * 00417 * void EnableFeatureIRQ(void) * 00418 * { * 00419 * feature_irq.enable_irq(); * 00420 * } * 00421 * * 00422 * void DisableFeatureIRQ(void) * 00423 * { * 00424 * feature_irq.disable_irq(); * 00425 * } * 00426 *------------------------------------------------------------------------*/ 00427 00428 00429 /** 00430 * @brief Enabling the FLAG interrupt handling. 00431 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00432 * @retval None. 00433 */ 00434 virtual void EnableFlagIRQ(uint8_t bridgeId) 00435 { 00436 if (bridgeId == BRIDGE_A) 00437 { 00438 flag_A_irq.mode(PullUp); 00439 flag_A_irq.fall(this, &L6206::L6206_FlagInterruptHandler); 00440 } 00441 else 00442 { 00443 flag_B_irq.mode(PullUp); 00444 flag_B_irq.fall(this, &L6206::L6206_FlagInterruptHandler); 00445 } 00446 } 00447 00448 /** 00449 * @brief Disabling the FLAG interrupt handling. 00450 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00451 * @retval None. 00452 */ 00453 virtual void DisableFlagIRQ(uint8_t bridgeId) 00454 { 00455 if (bridgeId == BRIDGE_A) 00456 flag_A_irq.fall(NULL); 00457 else 00458 flag_B_irq.fall(NULL); 00459 } 00460 00461 00462 /*** Public In/Out Related Methods ***/ 00463 00464 00465 00466 protected: 00467 00468 /*** Protected Component Related Methods ***/ 00469 00470 /* ACTION 7 --------------------------------------------------------------* 00471 * Declare here the component's specific methods. * 00472 * They should be: * 00473 * + Methods with the same name of the C component's virtual table's * 00474 * functions (1); * 00475 * + Methods with the same name of the C component's extended virtual * 00476 * table's functions, if any (2); * 00477 * + Helper methods, if any, like functions declared in the component's * 00478 * source files but not pointed by the component's virtual table (3). * 00479 * * 00480 * Example: * 00481 * Status_t COMPONENT_GetValue(float *f); //(1) * 00482 * Status_t COMPONENT_EnableFeature(void); //(2) * 00483 * Status_t COMPONENT_ComputeAverage(void); //(3) * 00484 *------------------------------------------------------------------------*/ 00485 Status_t L6206_Init(void *init); 00486 Status_t L6206_ReadId(uint8_t *id); 00487 void L6206_TickHandler(uint8_t deviceId); //Handle the device state machine at each tick timer pulse end 00488 void L6206_AttachErrorHandler(void (*callback)(uint16_t error)); //Attach a user callback to the error handler 00489 void L6206_AttachFlagInterrupt(void (*callback)(void)); //Attach a user callback to the flag Interrupt 00490 void L6206_DisableBridge(uint8_t bridgeId); //Disable the specified bridge 00491 void L6206_EnableBridge(uint8_t bridgeId); //Enable the specified bridge 00492 uint16_t L6206_GetBridgeStatus(uint8_t deviceId); //Get bridge status 00493 uint16_t L6206_GetCurrentSpeed(uint8_t motorId); //Return the current speed in pps 00494 motorState_t L6206_GetDeviceState(uint8_t motorId); //Return the device state 00495 uint8_t L6206_GetFwVersion(void); //Return the FW version 00496 uint16_t L6206_GetMaxSpeed(uint8_t motorId); //Return the max speed in pps 00497 void L6206_HardHiz(uint8_t motorId); //Stop the motor and disable the power bridge 00498 void L6206_HardStop(uint8_t motorId); //Stop the motor without disabling the power bridge 00499 void L6206_Run(uint8_t motorId, motorDir_t direction); //Run the motor 00500 uint32_t L6206_GetBridgeInputPwmFreq(uint8_t bridgeId); // Get the PWM frequency of the bridge input 00501 void L6206_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq); // Set the PWM frequency of the bridge input 00502 void L6206_SetDualFullBridgeConfig(uint8_t newConfig); // Set dual full bridge configuration 00503 bool L6206_SetMaxSpeed(uint8_t motorId,uint16_t newMaxSpeed); //Set the max speed in pps 00504 bool L6206_SetNbDevices(uint8_t nbDevices); //Set the number of driver devices 00505 void L6206_ErrorHandler(uint16_t error); 00506 void L6206_FlagInterruptHandler(void); 00507 uint8_t L6206_GetBridgeIdUsedByMotorId(uint8_t motorId); 00508 uint8_t L6206_GetBridgeInputUsedByMotorId(uint8_t motorId); 00509 uint8_t L6206_GetMotorIdUsingbridgeInput(uint8_t bridgeInput); 00510 uint8_t L6206_GetSecondBridgeInputUsedByMotorId(uint8_t motorId); 00511 bool L6206_IsBidirectionnalMotor(uint8_t motorId); 00512 void L6206_SetDeviceParamsToPredefinedValues(void); 00513 void L6206_SetDeviceParamsToGivenValues(L6206_Init_t* initDevicePrm); 00514 00515 /*** Component's I/O Methods ***/ 00516 00517 /* ACTION 8 --------------------------------------------------------------* 00518 * Implement here other I/O methods beyond those already implemented * 00519 * above, which are declared extern within the component's header file. * 00520 *------------------------------------------------------------------------*/ 00521 00522 /** 00523 * @brief Utility function to set or unset EN pin for Bridge A or Bridge B. 00524 * @param[out] none 00525 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00526 * @retval none 00527 */ 00528 void L6206_OutVal( uint8_t bridgeId, uint8_t val) 00529 { 00530 if( bridgeId == BRIDGE_A) 00531 { 00532 EN_flag_A.output(); 00533 EN_flag_A.mode(PullNone); 00534 EN_flag_A.write(val); 00535 } 00536 else 00537 { 00538 EN_flag_B.output(); 00539 EN_flag_B.mode(PullNone); 00540 EN_flag_B.write(val); 00541 } 00542 } 00543 00544 /** 00545 * @brief Making the CPU wait. 00546 * @param None. 00547 * @retval None. 00548 */ 00549 void L6206_Board_Delay(uint32_t delay) 00550 { 00551 wait_ms(delay); 00552 } 00553 00554 /** 00555 * @brief Disable the specified bridge 00556 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00557 * @retval None 00558 * @note When input of different brigdes are parallelized 00559 * together, the disabling of one bridge leads to the disabling 00560 * of the second one 00561 */ 00562 void L6206_Board_DisableBridge(uint8_t bridgeId) 00563 { 00564 DisableFlagIRQ(BRIDGE_A); 00565 DisableFlagIRQ(BRIDGE_B); 00566 00567 __disable_irq(); 00568 L6206_OutVal( bridgeId, 0); 00569 __enable_irq(); 00570 } 00571 00572 /** 00573 * @brief Enable the specified bridge 00574 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00575 * @retval None 00576 * @note When input of different brigdes are parallelized 00577 * together, the enabling of one bridge leads to the enabling 00578 * of the second one 00579 */ 00580 void L6206_Board_EnableBridge(uint8_t bridgeId, uint8_t addDelay) 00581 { 00582 L6206_OutVal( bridgeId, 1); 00583 00584 if (addDelay != 0) 00585 { 00586 wait_ms(BSP_MOTOR_CONTROL_BOARD_BRIDGE_TURN_ON_DELAY); 00587 } 00588 00589 EnableFlagIRQ( bridgeId); 00590 } 00591 00592 /** 00593 * @brief Returns the FLAG pin state. 00594 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00595 * @retval The FLAG pin value. 00596 */ 00597 uint32_t L6206_Board_GetFlagPinState(uint8_t bridgeId) 00598 { 00599 if (bridgeId == 0) 00600 { 00601 EN_flag_A.input(); 00602 return EN_flag_A.read(); 00603 } 00604 else 00605 { 00606 EN_flag_B.input(); 00607 return EN_flag_B.read(); 00608 } 00609 } 00610 00611 /** 00612 * @brief Initiliases the GPIOs used by the L6206s 00613 * @retval None 00614 */ 00615 void L6206_Board_GpioInit(void) 00616 { 00617 /* Init bridge Enable */ 00618 EN_flag_A.output(); 00619 EN_flag_A.write(0); 00620 EN_flag_A.input(); 00621 00622 EN_flag_B.output(); 00623 EN_flag_B.write(0); 00624 EN_flag_B.input(); 00625 00626 00627 /* Init flag Irq */ 00628 DisableFlagIRQ(BRIDGE_A); 00629 DisableFlagIRQ(BRIDGE_B); 00630 00631 } 00632 00633 /** 00634 * @brief Sets the frequency of PWM used for bridges inputs 00635 * @param[in] bridgeInput 0 for input 1A, 1 for input 2A, 00636 * 2 for input 1B, 3 for input 2B 00637 * @param[in] newFreq in Hz 00638 * @param[in] duty Duty cycle 00639 * @retval None 00640 * @note The frequency is directly the current speed of the device 00641 */ 00642 void L6206_Board_PwmSetFreq(uint8_t bridgeInput, uint32_t newFreq, uint8_t duty) 00643 { 00644 /* Computing the period of PWM. */ 00645 float period = 1.0f / newFreq; 00646 float duty_cycle; 00647 int period_us = (int)(period * 1000000); 00648 00649 if (duty > 100) duty = 100; 00650 duty_cycle = (float)duty / 100.0f; 00651 00652 switch (bridgeInput) 00653 { 00654 case 0: 00655 default: 00656 /* Setting the period and the duty-cycle of PWM. */ 00657 pwm_1A.period_us(period_us); 00658 pwm_1A.write(duty_cycle); 00659 break; 00660 00661 case 1: 00662 /* Setting the period and the duty-cycle of PWM. */ 00663 pwm_2A.period_us(period_us); 00664 pwm_2A.write(duty_cycle); 00665 break; 00666 00667 case 2: 00668 /* Setting the period and the duty-cycle of PWM. */ 00669 pwm_1B.period_us(period_us); 00670 pwm_1B.write(duty_cycle); 00671 break; 00672 00673 case 3: 00674 /* Setting the period and the duty-cycle of PWM. */ 00675 pwm_2B.period_us(period_us); 00676 pwm_2B.write(duty_cycle); 00677 break; 00678 } 00679 } 00680 00681 /** 00682 * @brief Reset the PWM for the specified brigde input 00683 * @param[in] bridgeInput 0 for input 1A, 1 for input 2A, 00684 * 2 for input 1B, 3 for input 2B 00685 * @retval None 00686 */ 00687 void L6206_Board_PwmDeInit(uint8_t bridgeInput) 00688 { 00689 switch (bridgeInput) 00690 { 00691 case 0: 00692 default: 00693 //timer_pwm_1A.detach(); 00694 break; 00695 00696 case 1: 00697 //timer_pwm_2A.detach(); 00698 break; 00699 00700 case 2: 00701 //timer_pwm_1B.detach(); 00702 break; 00703 00704 case 3: 00705 //timer_pwm_2B.detach(); 00706 break; 00707 } 00708 } 00709 00710 /** 00711 * @brief Set the PWM frequency the for the specified bridge input 00712 * @param[in] bridgeInput 0 for input 1A, 1 for input 2A, 00713 * 2 for input 1B, 3 for input 2B 00714 * @retval None 00715 */ 00716 void L6206_Board_PwmInit(uint8_t bridgeInput) 00717 { 00718 } 00719 00720 /** 00721 * @brief Stops the PWM uses for the specified brige input 00722 * @param[in] bridgeInput 0 for input 1A, 1 for input 2A, 00723 * 2 for input 1B, 3 for input 2B 00724 * @retval None 00725 */ 00726 void L6206_Board_PwmStop(uint8_t bridgeInput) 00727 { 00728 switch (bridgeInput) 00729 { 00730 case 0: 00731 default: 00732 pwm_1A.write(0.0); 00733 break; 00734 00735 case 1: 00736 pwm_2A.write(0.0); 00737 break; 00738 00739 case 2: 00740 pwm_1B.write(0.0); 00741 break; 00742 00743 case 3: 00744 pwm_2B.write(0.0); 00745 break; 00746 } 00747 } 00748 00749 00750 /*** Component's Instance Variables ***/ 00751 00752 /* ACTION 9 --------------------------------------------------------------* 00753 * Declare here interrupt related variables, if needed. * 00754 * Note that interrupt handling is platform dependent, see * 00755 * "Interrupt Related Methods" above. * 00756 * * 00757 * Example: * 00758 * + mbed: * 00759 * InterruptIn feature_irq; * 00760 *------------------------------------------------------------------------*/ 00761 00762 /* Flag Interrupt. */ 00763 InterruptIn flag_A_irq; 00764 InterruptIn flag_B_irq; 00765 00766 /* ACTION 10 -------------------------------------------------------------* 00767 * Declare here other pin related variables, if needed. * 00768 * * 00769 * Example: * 00770 * + mbed: * 00771 * DigitalOut standby_reset; * 00772 *------------------------------------------------------------------------*/ 00773 00774 /* Digital In/Out for Flag EN pin */ 00775 DigitalInOut EN_flag_A; 00776 DigitalInOut EN_flag_B; 00777 00778 /* PWM Out pin */ 00779 PwmOut pwm_1A; 00780 PwmOut pwm_2A; 00781 PwmOut pwm_1B; 00782 PwmOut pwm_2B; 00783 00784 /* ACTION 11 -------------------------------------------------------------* 00785 * Declare here communication related variables, if needed. * 00786 * * 00787 * Example: * 00788 * + mbed: * 00789 * DigitalOut address; * 00790 * DevI2C &dev_i2c; * 00791 *------------------------------------------------------------------------*/ 00792 00793 /* ACTION 12 -------------------------------------------------------------* 00794 * Declare here identity related variables, if needed. * 00795 * Note that there should be only a unique identifier for each component, * 00796 * which should be the "who_am_i" parameter. * 00797 *------------------------------------------------------------------------*/ 00798 /* Identity */ 00799 uint8_t who_am_i; 00800 00801 /* ACTION 13 -------------------------------------------------------------* 00802 * Declare here the component's static and non-static data, one variable * 00803 * per line. * 00804 * * 00805 * Example: * 00806 * float measure; * 00807 * int instance_id; * 00808 * static int number_of_instances; * 00809 *------------------------------------------------------------------------*/ 00810 void (*flagInterruptCallback)(void); 00811 00812 void (*errorHandlerCallback)(uint16_t error); 00813 00814 uint8_t numberOfDevices; 00815 00816 uint8_t deviceInstance; 00817 00818 deviceParams_t devicePrm; 00819 00820 00821 /** PWM timer variables */ 00822 00823 bool pwm_1A_activated; 00824 bool pwm_2A_activated; 00825 bool pwm_1B_activated; 00826 bool pwm_2B_activated; 00827 }; 00828 00829 #endif /* __L6206_CLASS_H */ 00830 00831 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00832 00833 00834
Generated on Fri Jul 15 2022 09:11:13 by
1.7.2
