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.
Dependencies: ST_INTERFACES
Dependents: motori prova_motore SchedamotoriIHM12A1 prova_motore_duck ... more
Fork of X-NUCLEO-IHM12A1 by
STSpin240_250.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file STSpin240_250.cpp 00004 * @author IPC Rennes 00005 * @version V1.0.0 00006 * @date April 25th, 2016 00007 * @brief STSpin240 motor driver (Dual brush DC motors) 00008 * @note (C) COPYRIGHT 2016 STMicroelectronics 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2016 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 /* Includes ------------------------------------------------------------------*/ 00040 #include "STSpin240_250.h" 00041 00042 /* Definitions ---------------------------------------------------------------*/ 00043 00044 /* Error: Access a motor index greater than the one of the current brigde configuration */ 00045 #define STSPIN240_250_ERROR_1 (0xC001) 00046 /* Error: Use of a bridgeId greater than BRIDGE_B */ 00047 #define STSPIN240_250_ERROR_2 (0xC002) 00048 00049 /* Maximum frequency of the PWMs in Hz */ 00050 #define STSPIN240_250_MAX_PWM_FREQ (100000) 00051 00052 /* Minimum frequency of the PWMs in Hz */ 00053 #define STSPIN240_250_MIN_PWM_FREQ (2) 00054 00055 /* Bridge A */ 00056 #define BRIDGE_A (0) 00057 00058 /* Bridge B */ 00059 #define BRIDGE_B (1) 00060 00061 /* PWM id for PWM_A */ 00062 #define PWM_A (0) 00063 00064 /* PWM id for PWM_B */ 00065 #define PWM_B (1) 00066 00067 /* PWM id for PWM_REF */ 00068 #define PWM_REF (2) 00069 00070 /* Variables ----------------------------------------------------------------*/ 00071 00072 /* Number of devices. */ 00073 uint8_t STSpin240_250::numberOfDevices = 0; 00074 uint8_t STSpin240_250::arrayNbMaxMotorsByConfig[2] = {1,2}; 00075 /* Methods -------------------------------------------------------------------*/ 00076 00077 /********************************************************** 00078 * @brief Starts the STSpin240_250 library 00079 * @param[in] pInit pointer to the initialization data 00080 * @retval COMPONENT_OK in case of success. 00081 **********************************************************/ 00082 status_t STSpin240_250::STSpin240_250_Init(void* pInit) 00083 { 00084 /* Standby-reset deactivation */ 00085 STSpin240_250_Board_ReleaseReset(); 00086 00087 /* Let a delay after reset */ 00088 STSpin240_250_Board_Delay(1); 00089 00090 if (pInit == 0) 00091 { 00092 // Set all registers to their predefined values 00093 // from powerstep01_target_config.h 00094 STSpin240_250_SetDeviceParamsToPredefinedValues(); 00095 } 00096 else 00097 { 00098 STSpin240_250_SetDeviceParamsToGivenValues((STSpin240_250_init_t *)pInit); 00099 } 00100 00101 /* Initialise input PWM of bridges*/ 00102 STSpin240_250_SetDualFullBridgeconfig(device_prm.dualBridgeEnabled); 00103 00104 return COMPONENT_OK; 00105 } 00106 00107 /********************************************************** 00108 * @brief Read id 00109 * @param[in] id pointer to the identifier to be read. 00110 * @retval COMPONENT_OK in case of success. 00111 **********************************************************/ 00112 status_t STSpin240_250::STSpin240_250_ReadId(uint8_t *id) 00113 { 00114 *id = deviceInstance; 00115 00116 return COMPONENT_OK; 00117 } 00118 00119 /********************************************************** 00120 * @brief Attaches a user callback to the error Handler. 00121 * The call back will be then called each time the library 00122 * detects an error 00123 * @param[in] callback Name of the callback to attach 00124 * to the error Hanlder 00125 * @retval None 00126 **********************************************************/ 00127 void STSpin240_250::STSpin240_250_AttachErrorHandler(void (*callback)(uint16_t error)) 00128 { 00129 errorHandlerCallback = (void (*)(uint16_t error)) callback; 00130 } 00131 00132 00133 /******************************************************//** 00134 * @brief Disable the specified bridge 00135 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00136 * @retval None 00137 * @note Bridge A and bridge B share the same enable pin. 00138 * When bridge A is disabled, bridge B is disabled and 00139 * reversely 00140 **********************************************************/ 00141 void STSpin240_250::STSpin240_250_DisableBridge(uint8_t bridgeId) 00142 { 00143 STSpin240_250_Board_DisableBridge(); 00144 device_prm.bridgeEnabled[BRIDGE_A] = FALSE; 00145 device_prm.bridgeEnabled[BRIDGE_B] = FALSE; 00146 } 00147 00148 /******************************************************//** 00149 * @brief Enable the specified bridge 00150 * @param[in] bridgeId (from 0 for bridge A to 1 for bridge B) 00151 * @retval None 00152 * @note Bridge A and bridge B share the same enable pin. 00153 * When bridge A is enabled, bridge B is enabled and 00154 * reversely 00155 **********************************************************/ 00156 void STSpin240_250::STSpin240_250_EnableBridge(uint8_t bridgeId) 00157 { 00158 device_prm.bridgeEnabled[BRIDGE_A] = TRUE; 00159 device_prm.bridgeEnabled[BRIDGE_B] = TRUE; 00160 STSpin240_250_Board_EnableBridge(1); 00161 } 00162 00163 /********************************************************** 00164 * @brief Error handler which calls the user callback (if defined) 00165 * @param[in] error Number of the error 00166 * @retval None 00167 **********************************************************/ 00168 void STSpin240_250::STSpin240_250_ErrorHandler(uint16_t error) 00169 { 00170 if (errorHandlerCallback != 0) 00171 { 00172 (void) errorHandlerCallback(error); 00173 } 00174 else 00175 { 00176 /* Aborting the program. */ 00177 exit(EXIT_FAILURE); 00178 } 00179 } 00180 00181 /******************************************************//** 00182 * @brief Get the PWM frequency of the specified bridge 00183 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00184 * @retval Freq in Hz 00185 **********************************************************/ 00186 uint32_t STSpin240_250::STSpin240_250_GetBridgeInputPwmFreq(uint8_t bridgeId) 00187 { 00188 if (bridgeId > BRIDGE_B) 00189 { 00190 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_2); 00191 } 00192 00193 return (device_prm.bridgePwmFreq[(bridgeId << 1)]); 00194 } 00195 00196 /******************************************************//** 00197 * @brief Get the status of the bridge enabling of the corresponding bridge 00198 * @param[in] bridgeId from 0 for bridge A to 1 for bridge B 00199 * @retval State of the Enable&Fault pin (shared for bridge A and B) 00200 **********************************************************/ 00201 uint16_t STSpin240_250::STSpin240_250_GetBridgeStatus(void) 00202 { 00203 uint16_t status = STSpin240_250_Board_GetFaultPinState(); 00204 00205 return (status); 00206 } 00207 00208 /******************************************************//** 00209 * @brief Returns the current speed of the specified motor 00210 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00211 * @retval current speed in % from 0 to 100 00212 **********************************************************/ 00213 uint16_t STSpin240_250::STSpin240_250_GetCurrentSpeed(uint8_t motorId) 00214 { 00215 uint16_t speed = 0; 00216 00217 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00218 { 00219 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00220 } 00221 else 00222 { 00223 if (device_prm.motionState[motorId] != INACTIVE) 00224 { 00225 speed = device_prm.speed[motorId]; 00226 } 00227 } 00228 return (speed); 00229 } 00230 00231 /******************************************************//** 00232 * @brief Returns the device state 00233 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00234 * @retval State (STEADY or INACTIVE) 00235 **********************************************************/ 00236 motorState_t STSpin240_250::STSpin240_250_GetDeviceState(uint8_t motorId) 00237 { 00238 motorState_t state = INACTIVE; 00239 00240 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00241 { 00242 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00243 } 00244 else 00245 { 00246 state = device_prm.motionState[motorId]; 00247 } 00248 return (state); 00249 } 00250 00251 /******************************************************//** 00252 * @brief Get the motor current direction 00253 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00254 * @retval direction 00255 **********************************************************/ 00256 motorDir_t STSpin240_250::STSpin240_250_GetDirection(uint8_t motorId) 00257 { 00258 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00259 { 00260 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00261 } 00262 00263 return device_prm.direction[motorId]; 00264 } 00265 00266 /******************************************************//** 00267 * @brief Returns the FW version of the library 00268 * @retval STSPIN240_250_FW_VERSION 00269 **********************************************************/ 00270 uint32_t STSpin240_250::STSpin240_250_GetFwVersion(void) 00271 { 00272 return (STSPIN240_250_FW_VERSION); 00273 } 00274 00275 00276 /******************************************************//** 00277 * @brief Return the duty cycle of PWM used for REF 00278 * @param[in] refId 0 is the only supported id for STSpin240 or 00279 * STSpin250 00280 * @retval duty cycle in % (from 0 to 100) 00281 **********************************************************/ 00282 uint8_t STSpin240_250::STSpin240_250_GetRefPwmDc(uint8_t refId) 00283 { 00284 uint32_t duty = 0; 00285 00286 if (duty == 0) 00287 { 00288 duty = device_prm.refPwmDc; 00289 } 00290 return (duty); 00291 } 00292 00293 /******************************************************//** 00294 * @brief Return the frequency of PWM used for REF 00295 * @param[in] refId 0 is the only supported id for STSpin240 or 00296 * STSpin250 00297 * @retval Frequency in Hz 00298 **********************************************************/ 00299 uint32_t STSpin240_250::STSpin240_250_GetRefPwmFreq(uint8_t refId) 00300 { 00301 uint32_t freq = 0; 00302 00303 if (refId == 0) 00304 { 00305 freq = device_prm.refPwmFreq; 00306 } 00307 return (freq); 00308 } 00309 00310 /******************************************************//** 00311 * @brief Immediatly stops the motor and disable the power bridge 00312 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00313 * @retval None 00314 * @note As all motors uses the same power bridge, the 00315 * power bridge will be disable only if all motors are 00316 * stopped 00317 **********************************************************/ 00318 void STSpin240_250::STSpin240_250_HardHiz(uint8_t motorId) 00319 { 00320 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00321 { 00322 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00323 } 00324 else 00325 { 00326 if (device_prm.bridgeEnabled[motorId] != FALSE) 00327 { 00328 /* Only disable bridges if dual bridge mode is disabled or */ 00329 /* if all motors are inactive as there are sharing the same power stage */ 00330 if ((device_prm.dualBridgeEnabled == 0)|| 00331 ((motorId == 0)&&(device_prm.motionState[1] == INACTIVE))|| 00332 ((motorId == 1)&&(device_prm.motionState[0] == INACTIVE))) 00333 { 00334 /* Disable the bridge */ 00335 STSpin240_250_DisableBridge(motorId); 00336 } 00337 } 00338 /* Disable the PWM */ 00339 STSpin240_250_HardStop(motorId); 00340 } 00341 } 00342 00343 /******************************************************//** 00344 * @brief Stops the motor without disabling the bridge 00345 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00346 * @retval none 00347 **********************************************************/ 00348 void STSpin240_250::STSpin240_250_HardStop(uint8_t motorId) 00349 { 00350 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00351 { 00352 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00353 } 00354 else 00355 { 00356 if (device_prm.motionState[motorId] != INACTIVE) 00357 { 00358 /* Disable corresponding PWM */ 00359 STSpin240_250_Board_PwmStop(motorId); 00360 00361 /* Set inactive state */ 00362 device_prm.motionState[motorId] = INACTIVE; 00363 } 00364 } 00365 } 00366 00367 /******************************************************//** 00368 * @brief Release reset (exit standby mode) 00369 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1) 00370 * @retval None 00371 **********************************************************/ 00372 void STSpin240_250::STSpin240_250_ReleaseReset(void) 00373 { 00374 STSpin240_250_Board_ReleaseReset(); 00375 00376 /* Start PWM used for REF pin */ 00377 STSpin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc); 00378 } 00379 00380 /******************************************************//** 00381 * @brief Reset (enter standby mode) 00382 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1) 00383 * @retval None 00384 **********************************************************/ 00385 void STSpin240_250::STSpin240_250_Reset(void) 00386 { 00387 uint8_t loop; 00388 for (loop = 0; loop < STSPIN240_250_NB_MAX_MOTORS; loop++) 00389 { 00390 /* Stop motor if needed*/ 00391 if (device_prm.motionState[loop] != INACTIVE) 00392 { 00393 STSpin240_250_HardStop(loop); 00394 } 00395 /* Disable bridge if needed */ 00396 if (device_prm.bridgeEnabled[loop] != FALSE) 00397 { 00398 STSpin240_250_DisableBridge(loop); 00399 } 00400 } 00401 00402 /* Stop PWM used for REF pin */ 00403 STSpin240_250_Board_PwmStop(PWM_REF); 00404 00405 /* Reset the STBY/RESET pin */ 00406 STSpin240_250_Board_Reset(); 00407 } 00408 00409 /******************************************************//** 00410 * @brief Runs the motor 00411 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00412 * @param[in] direction FORWARD or BACKWARD 00413 * @retval None 00414 * @note For unidirectionnal motor, direction parameter has 00415 * no effect 00416 **********************************************************/ 00417 void STSpin240_250::STSpin240_250_Run(uint8_t motorId, motorDir_t direction) 00418 { 00419 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00420 { 00421 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00422 } 00423 else 00424 { 00425 if ((device_prm.motionState[motorId] == INACTIVE) || 00426 (device_prm.direction[motorId] != direction)) 00427 { 00428 00429 /* Release reset if required */ 00430 if (STSpin240_250_GetResetState() == 0) 00431 { 00432 STSpin240_250_ReleaseReset(); 00433 } 00434 00435 /* Eventually deactivate motor */ 00436 if (device_prm.motionState[motorId] != INACTIVE) 00437 { 00438 STSpin240_250_HardStop(motorId); 00439 } 00440 00441 /* Set direction */ 00442 STSpin240_250_SetDirection(motorId, direction); 00443 00444 /* Switch to steady state */ 00445 device_prm.motionState[motorId] = STEADY; 00446 00447 /* Enable bridge */ 00448 if (device_prm.bridgeEnabled[motorId] == FALSE) 00449 { 00450 STSpin240_250_EnableBridge(motorId); 00451 } 00452 /* Set PWM */ 00453 STSpin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]); 00454 } 00455 } 00456 } 00457 00458 /******************************************************//** 00459 * @brief Changes the PWM frequency of the bridge input 00460 * @param[in] bridgeId 0 for bridge A, 1 for bridge B 00461 * @param[in] newFreq in Hz 00462 * @retval None 00463 * @note 1)The PWM is only enabled when the motor is requested 00464 * to run. 00465 * 2) If the two bridges share the same timer, their frequency 00466 * has to be the same 00467 * 3) If the two bridges share the same timer, the frequency 00468 * is updated on the fly is there is only one motor running 00469 * on the targeted bridge. 00470 **********************************************************/ 00471 void STSpin240_250::STSpin240_250_SetBridgeInputPwmFreq(uint8_t bridgeId, uint32_t newFreq) 00472 { 00473 if (bridgeId > BRIDGE_B) 00474 { 00475 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_2); 00476 } 00477 00478 if (newFreq > STSPIN240_250_MAX_PWM_FREQ) 00479 { 00480 newFreq = STSPIN240_250_MAX_PWM_FREQ; 00481 } 00482 00483 device_prm.bridgePwmFreq[bridgeId] = newFreq; 00484 00485 if (device_prm.motionState[bridgeId] != INACTIVE) 00486 { 00487 STSpin240_250_Board_PwmSetFreq(bridgeId, device_prm.bridgePwmFreq[bridgeId],device_prm.speed[bridgeId]); 00488 } 00489 } 00490 00491 /******************************************************//** 00492 * @brief Specifies the direction 00493 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00494 * @param[in] dir FORWARD or BACKWARD 00495 * @note The direction change is only applied if the device 00496 * is in INACTIVE state. To change direction while motor is 00497 * running, use the run function 00498 * @retval None 00499 **********************************************************/ 00500 void STSpin240_250::STSpin240_250_SetDirection(uint8_t motorId, motorDir_t dir) 00501 { 00502 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00503 { 00504 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00505 } 00506 else 00507 { 00508 if (device_prm.motionState[motorId] == INACTIVE) 00509 { 00510 STSpin240_250_Board_SetDirectionGpio(motorId, dir); 00511 device_prm.direction[motorId] = dir; 00512 } 00513 } 00514 } 00515 00516 /******************************************************//** 00517 * @brief Set the dual bridge configuration mode 00518 * @param[in] enable 0 to disable, 00519 * 1 to enable (not supported by STSPIN250) 00520 * @retval None 00521 **********************************************************/ 00522 void STSpin240_250::STSpin240_250_SetDualFullBridgeconfig(uint8_t enable) 00523 { 00524 device_prm.dualBridgeEnabled = enable; 00525 00526 /* Check reset pin state*/ 00527 if (STSpin240_250_GetResetState() != 0) 00528 { 00529 STSpin240_250_Reset(); 00530 STSpin240_250_ReleaseReset(); 00531 } 00532 } 00533 00534 /******************************************************//** 00535 * @brief Changes the max speed of the specified device 00536 * @param[in] motorId from 0 to (MAX_NUMBER_OF_BRUSH_DC_MOTORS - 1) 00537 * @param[in] newMaxSpeed in % from 0 to 100 00538 * @retval true if the command is successfully executed, else false 00539 **********************************************************/ 00540 bool STSpin240_250::STSpin240_250_SetMaxSpeed(uint8_t motorId, uint16_t newMaxSpeed) 00541 { 00542 bool cmdExecuted = FALSE; 00543 00544 if (motorId >= arrayNbMaxMotorsByConfig[device_prm.dualBridgeEnabled]) 00545 { 00546 STSpin240_250_ErrorHandler(STSPIN240_250_ERROR_1); 00547 } 00548 else 00549 { 00550 device_prm.speed[motorId] = newMaxSpeed; 00551 if (device_prm.motionState[motorId] != INACTIVE) 00552 { 00553 /* Set PWM frequency*/ 00554 STSpin240_250_Board_PwmSetFreq(motorId, device_prm.bridgePwmFreq[motorId],device_prm.speed[motorId]); 00555 } 00556 cmdExecuted = TRUE; 00557 } 00558 return cmdExecuted; 00559 } 00560 00561 /******************************************************//** 00562 * @brief Changes the duty cycle of the PWM used for REF 00563 * @param[in] refId 0 is the only supported id for STSpin240 or 00564 * STSpin250 00565 * @param[in] newDc new duty cycle from 0 to 100 00566 * @retval None 00567 **********************************************************/ 00568 void STSpin240_250::STSpin240_250_SetRefPwmDc(uint8_t refId, uint8_t newDc) 00569 { 00570 if (newDc > 100) 00571 { 00572 newDc = 100; 00573 } 00574 00575 device_prm.refPwmDc = newDc; 00576 00577 if (STSpin240_250_GetResetState() != 0) 00578 { 00579 /* Immediatly set the PWM frequency for ref if chip is not in reset */ 00580 STSpin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc); 00581 } 00582 } 00583 00584 /******************************************************//** 00585 * @brief Changes the frequency of PWM used for REF 00586 * @param[in] refId 0 is the only supported id for STSpin240 or 00587 * STSpin250 00588 * @param[in] newFreq in Hz 00589 * @retval None 00590 **********************************************************/ 00591 void STSpin240_250::STSpin240_250_SetRefPwmFreq(uint8_t refId, uint32_t newFreq) 00592 { 00593 if (newFreq > STSPIN240_250_MAX_PWM_FREQ) 00594 { 00595 newFreq = STSPIN240_250_MAX_PWM_FREQ; 00596 } 00597 00598 device_prm.refPwmFreq = newFreq; 00599 00600 if (STSpin240_250_GetResetState() != 0) 00601 { 00602 /* Immediatly set the PWM frequency for ref if chip is not in reset */ 00603 STSpin240_250_Board_PwmSetFreq(PWM_REF, device_prm.refPwmFreq,device_prm.refPwmDc); 00604 } 00605 } 00606 00607 00608 /******************************************************//** 00609 * @brief Get the status of the bridge enabling of the corresponding bridge 00610 * @retval State of the Enable&Fault pin (shared for bridge A and B) 00611 **********************************************************/ 00612 uint8_t STSpin240_250::STSpin240_250_GetResetState(void) 00613 { 00614 uint8_t status = STSpin240_250_Board_GetResetPinState(); 00615 00616 return (status); 00617 } 00618 00619 /******************************************************//** 00620 * @brief Set the parameters of the device to values of pInitPrm structure 00621 * @param[in] deviceId (from 0 to MAX_NUMBER_OF_DEVICES -1) 00622 * @param pInitPrm pointer to a structure containing the initial device parameters 00623 * @retval None 00624 **********************************************************/ 00625 void STSpin240_250::STSpin240_250_SetDeviceParamsToGivenValues(STSpin240_250_init_t *pInitPrm) 00626 { 00627 uint32_t i; 00628 00629 device_prm.dualBridgeEnabled = pInitPrm->dualBridgeEnabled; 00630 00631 device_prm.bridgePwmFreq[BRIDGE_A] = pInitPrm->bridgePwmFreq[BRIDGE_A]; 00632 device_prm.bridgePwmFreq[BRIDGE_B] = pInitPrm->bridgePwmFreq[BRIDGE_B];; 00633 00634 device_prm.refPwmFreq = pInitPrm->refPwmFreq; 00635 device_prm.refPwmDc = pInitPrm->refPwmDc; 00636 00637 for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++) 00638 { 00639 device_prm.speed[i] = 100; 00640 device_prm.direction[i] = FORWARD; 00641 device_prm.motionState[i] = INACTIVE; 00642 } 00643 for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++) 00644 { 00645 device_prm.bridgeEnabled[i] = FALSE; 00646 } 00647 } 00648 /******************************************************//** 00649 * @brief Sets the parameters of the device to predefined values 00650 * from STSpin240_250_target_config.h 00651 * @retval None 00652 **********************************************************/ 00653 void STSpin240_250::STSpin240_250_SetDeviceParamsToPredefinedValues(void) 00654 { 00655 uint32_t i; 00656 00657 device_prm.dualBridgeEnabled = STSPIN240_250_CONF_PARAM_DUAL_BRIDGE_ENABLING; 00658 00659 device_prm.bridgePwmFreq[BRIDGE_A] = STSPIN240_250_CONF_PARAM_FREQ_PWM_A; 00660 device_prm.bridgePwmFreq[BRIDGE_B] = STSPIN240_250_CONF_PARAM_FREQ_PWM_B; 00661 00662 device_prm.refPwmFreq = STSPIN240_250_CONF_PARAM_FREQ_PWM_REF; 00663 device_prm.refPwmDc = STSPIN240_250_CONF_PARAM_DC_PWM_REF; 00664 00665 for (i = 0; i < MAX_NUMBER_OF_BRUSH_DC_MOTORS; i++) 00666 { 00667 device_prm.speed[i] = 100; 00668 device_prm.direction[i] = FORWARD; 00669 device_prm.motionState[i] = INACTIVE; 00670 } 00671 for (i = 0; i < STSPIN240_250_NB_BRIDGES; i++) 00672 { 00673 device_prm.bridgeEnabled[i] = FALSE; 00674 } 00675 } 00676 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 07:47:17 by
1.7.2

X-NUCLEO-IHM12A1 Low Voltage Dual Brush DC Motor Driver