HallSensoredTrapMotorControlLibrary  1.0
hall_trap.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /*!****************************************************************************
34  * @file hall_trap.h
35  * @brief HALL_TRAP_MODULE Module
36  *
37  * @anchor hall_trap_h
38  * # Overview
39  *
40  * API's releated to hall_trap
41  *
42  * <hr>
43  ******************************************************************************/
48 #ifndef hall_trap_h
49 #define hall_trap_h
50 
51 //*****************************************************************************
52 // the includes
53 //*****************************************************************************
54 #include "hal.h"
55 
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 
60 //*****************************************************************************
61 //defines
62 //*****************************************************************************
64 #define HALLTRAP_HALT_TIME_US (1e6)
65 
66 //*****************************************************************************
67 // typedefs
68 //*****************************************************************************
70 typedef enum
71 {
73  HALL_A = 0,
80 }HALL;
81 
83 typedef enum
84 {
89 }MOTOR_DIR;
90 
92 typedef enum
93 {
99 
101 typedef enum
102 {
107 }MOTOR_STATE;
108 
110 typedef enum
111 {
143 
145 typedef struct
146 {
162 
163 //*****************************************************************************
164 // the function prototypes
165 //*****************************************************************************
170 void Halltrap_Init(Halltrap_Instance *hallTrap);
171 
178 void Halltrap_PWMUpdate(
179  Halltrap_Instance *hallTrap, MOTOR_DIR dir, uint16_t pwmDuty);
180 
188  Halltrap_Instance *hallTrap, uint32_t poles);
189 
195 __STATIC_INLINE void Halltrap_setDeadband(
196  Halltrap_Instance *hallTrap, uint16_t deadtime_ns)
197 {
198  HAL_setDeadband(hallTrap->phaseA, deadtime_ns);
199  HAL_setDeadband(hallTrap->phaseB, deadtime_ns);
200  HAL_setDeadband(hallTrap->phaseC, deadtime_ns);
201 }
202 
208 __STATIC_INLINE void Halltrap_setPWMFreq(
209  Halltrap_Instance *hallTrap, uint32_t pwmFreq)
210 {
211  HAL_setPWMFreq(hallTrap->phaseA, pwmFreq);
212  HAL_setPWMFreq(hallTrap->phaseB, pwmFreq);
213  HAL_setPWMFreq(hallTrap->phaseC, pwmFreq);
214 }
215 
221 __STATIC_INLINE void Halltrap_stopMotor(
222  Halltrap_Instance *hallTrap, MOTOR_BRAKE_TYPE brakeType)
223 {
224  if(brakeType == MOTOR_BRAKE_TYPE_COAST)
225  {
226  HAL_PWMOutputLow(hallTrap->phaseA, hallTrap->phaseB, hallTrap->phaseC);
227  }
228  else
229  {
230  HAL_PWMOutputHigh(hallTrap->phaseA, hallTrap->phaseB, hallTrap->phaseC);
231  }
232 }
233 
238 __STATIC_INLINE void Halltrap_disablePWM(Halltrap_Instance *hallTrap)
239 {
240  HAL_PWMOutputLow(hallTrap->phaseA, hallTrap->phaseB, hallTrap->phaseC);
241 }
242 
248 __STATIC_INLINE void Halltrap_changeMotorDirection(
249  Halltrap_Instance *hallTrap, MOTOR_DIR dir)
250 {
251  HAL_PWMOutputLow(hallTrap->phaseA, hallTrap->phaseB, hallTrap->phaseC);
252  /* motor is halted for 1 second to allow the freewheeling
253  * currents to circulate
254  */
256  uint16_t pulseWidth = 0;
257  Halltrap_PWMUpdate(hallTrap, dir, pulseWidth);
258 }
259 
260 #ifdef __cplusplus
261 }
262 #endif
263 #endif /* hall_trap_h */
264 
MOTOR_STATE
Definition: hall_trap.h:101
__STATIC_INLINE void Halltrap_changeMotorDirection(Halltrap_Instance *hallTrap, MOTOR_DIR dir)
Changes the motor direction.
Definition: hall_trap.h:248
__STATIC_INLINE void Halltrap_disablePWM(Halltrap_Instance *hallTrap)
Disable the PWM output.
Definition: hall_trap.h:238
current from A to B in forward control and B to A in reverse control, phase C is open ...
Definition: hall_trap.h:121
HAL_GPIO_IN
Definition: hal.h:109
HAL_PWM phaseA
Phase A timer.
Definition: hall_trap.h:154
HAL_GPIO_IN hallC
HALL C GPIO.
Definition: hall_trap.h:152
Defines Motor Stop.
Definition: hall_trap.h:106
Defines hall A.
Definition: hall_trap.h:73
Hall Sensored Trap Motor Control Library HAL Module.
Defines Motor Brake Type Coast.
Definition: hall_trap.h:95
Defines Motor Directions Forward.
Definition: hall_trap.h:86
MOTOR_BRAKE_TYPE
Definition: hall_trap.h:92
__STATIC_INLINE void Halltrap_setPWMFreq(Halltrap_Instance *hallTrap, uint32_t pwmFreq)
Sets the pwm frequency in all phases.
Definition: hall_trap.h:208
uint32_t Halltrap_calculateMotorSpeed(Halltrap_Instance *hallTrap, uint32_t poles)
Calculates motor speed.
Definition: hall_trap.c:239
current from B to C in forward control and C to B in reverse control, phase A is open ...
Definition: hall_trap.h:131
HAL_PWM
Definition: hal.h:137
void HAL_setDeadband(HAL_PWM pwm, uint16_t deadband)
Sets deadband for timer.
Definition: hal.c:225
__STATIC_INLINE void HAL_delayMicroSeconds(uint32_t microSeconds)
Delays for specific time in microseconds.
Definition: hal.h:455
Defines hall B.
Definition: hall_trap.h:75
void Halltrap_PWMUpdate(Halltrap_Instance *hallTrap, MOTOR_DIR dir, uint16_t pwmDuty)
Updates the PWM.
Definition: hall_trap.c:211
__STATIC_INLINE void HAL_PWMOutputLow(const HAL_PWM gndPhase_1, const HAL_PWM gndPhase_2, const HAL_PWM gndPhase_3)
Set all PWM outputs low.
Definition: hal.h:504
HAL_PWM phaseC
Phase C timer.
Definition: hall_trap.h:158
Defines Motor Run.
Definition: hall_trap.h:104
HALLTRAP_COMM_STATE
Definition: hall_trap.h:110
current from C to A in forward control and A to C in reverse control, phase B is open ...
Definition: hall_trap.h:116
HAL_CAPTURE_TIMER captureInput
input capture
Definition: hall_trap.h:160
current from B to A in forward control and A to B in reverse control, phase C is open ...
Definition: hall_trap.h:136
current from A to C in forward control and C to A in reverse control, phase B is open ...
Definition: hall_trap.h:141
HAL_GPIO_IN hallB
HALL B GPIO.
Definition: hall_trap.h:150
Defines Motor Brake Type Brake.
Definition: hall_trap.h:97
#define HALLTRAP_HALT_TIME_US
Defines the halt time before changing the motor direction.
Definition: hall_trap.h:64
Defines a halltrap instance.
Definition: hall_trap.h:145
__STATIC_INLINE void Halltrap_stopMotor(Halltrap_Instance *hallTrap, MOTOR_BRAKE_TYPE brakeType)
Stops the motor.
Definition: hall_trap.h:221
void Halltrap_Init(Halltrap_Instance *hallTrap)
Initialize the halltrap module.
Definition: hall_trap.c:53
HAL_CAPTURE_TIMER
Definition: hal.h:150
MOTOR_DIR
Definition: hall_trap.h:83
current from C to B in forward control and B to C in reverse control, phase A is open ...
Definition: hall_trap.h:126
__STATIC_INLINE void Halltrap_setDeadband(Halltrap_Instance *hallTrap, uint16_t deadtime_ns)
Sets the deadband in all phases.
Definition: hall_trap.h:195
Maximum hall signals.
Definition: hall_trap.h:79
Defines Motor Directions Reverse.
Definition: hall_trap.h:88
HAL_PWM phaseB
Phase B timer.
Definition: hall_trap.h:156
__STATIC_INLINE void HAL_PWMOutputHigh(const HAL_PWM gndPhase_1, const HAL_PWM gndPhase_2, const HAL_PWM gndPhase_3)
Set complementary PWM outputs high.
Definition: hal.h:528
Defines hall C.
Definition: hall_trap.h:77
HAL_GPIO_IN hallA
HALL A GPIO.
Definition: hall_trap.h:148
HALL
Definition: hall_trap.h:70
void HAL_setPWMFreq(HAL_PWM pwm, uint32_t PWMFreq)
Sets PWMfreq for all timers.
Definition: hal.c:238
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale