MSPM0C1106HallSensoredTrapMotorControlLibrary  1.0
drv8311.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 drv8311.h
35  * @brief drv8311_MODULE Module
36  *
37  * @anchor drv8311_h
38  * # Overview
39  *
40  * API's releated to drv8311
41  *
42  * <hr>
43  ******************************************************************************/
48 #ifndef _drv8311_H_
49 #define _drv8311_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 drv8311_MAXIMUM_RESET_TIME (40)
65 
67 #define drv8311_MAXIMUM_WAKEUP_TIME (2000)
68 
70 #define drv8311_VOLTAGE_CONV_CONST _IQ20(8.143)
71 
73 #define drv8311_CSA_REF_VOLTAGE (3000)
74 
76 #define drv8311_CSAGAIN_0P25VA_IQ _IQ20(0.25)
77 
79 #define drv8311_CSAGAIN_0P5VA_IQ _IQ20(0.5)
80 
82 #define drv8311_CSAGAIN_1P0VA_IQ _IQ20(1.0)
83 
85 #define drv8311_CSAGAIN_2P0VA_IQ _IQ20(2.0)
86 
87 //*****************************************************************************
88 // typedefs
89 //*****************************************************************************
90 
91 
93 typedef enum
94 {
98  drv8311_CSAGAIN_0P5VA = 0x01 << 0,
104 
106 typedef enum
107 {
113 
115 typedef enum
116 {
122 
124 typedef struct
125 {
149  _iq20 csa_sf;
153  _iq20 csaVRef;
186 
188 
189 //*****************************************************************************
190 // the function prototypes
191 //*****************************************************************************
197 __STATIC_INLINE void drv8311_setDrvoff(
198  drv8311_Instance *drvHandle, drv8311_DRVOFF_PIN_STAT value)
199 {
200  if(value == drv8311_DRVOFF_PIN_HIGH)
201  {
203  }
204  else if(value == drv8311_DRVOFF_PIN_LOW)
205  {
207  }
208  else
209  {
210  /* This is expected to be empty */
211  }
212 }
213 
219 __STATIC_INLINE void drv8311_setnSleep(
220  drv8311_Instance *drvHandle, drv8311_DRV_NSLEEP_STAT value)
221 {
222  if(value == drv8311_DRV_NSLEEP_AWAKE)
223  {
225  }
226  else if(value == drv8311_DRV_NSLEEP_SLEEP)
227  {
229  }
230  else
231  {
232  /* This is expected to be empty */
233  }
234  /* tWake - Turnon time = 1ms
235  * tSleep - Turnoff time = 1ms
236  * So not matter what you set sleep pin to just wait 1 ms
237  */
239 }
240 
245 void drv8311_init(drv8311_Instance *drvHandle);
246 
251 void drv8311_enable(drv8311_Instance *drvHandle);
252 
259  drv8311_Instance *drvHandle, drv8311_CSAGAIN csa);
260 
266 _iq20 drv8311_getVoltage(HAL_ADC_CHAN chan);
267 
276  drv8311_Instance *drvHandle, _iq20 vRef);
277 
286  HAL_ADC_INT_VREF internalVRef, uint16_t externalVRef);
287 
293 __STATIC_INLINE _iq20 drv8311_getcsaVref(uint16_t vRef)
294 {
295  _iq13 temp = _IQ13div(_IQ13(vRef),_IQ13(1000));
296  return _IQ13toIQ20(temp);
297 }
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 #endif /* _drv8311_H_ */
303 
HAL_ADC_CHAN VsenA
Definition: drv8311.h:161
Define drv8311 CSA GAIN 0.5 Setting.
Definition: drv8311.h:98
void drv8311_ADCVRefSel(HAL_ADC_VREF adcRef, HAL_ADC_CHAN chan, HAL_ADC_INT_VREF internalVRef, uint16_t externalVRef)
updates the adc voltage reference
Definition: drv8311.c:133
HAL_FAULT_INPUT
Definition: hal.h:159
__STATIC_INLINE void drv8311_setDrvoff(drv8311_Instance *drvHandle, drv8311_DRVOFF_PIN_STAT value)
set drvoff
Definition: drv8311.h:197
HAL_SPI_CS spiCs
Definition: drv8311.h:145
_iq20 drv8311_getVoltage(HAL_ADC_CHAN chan)
Get voltage from adc channel.
Definition: drv8311.c:105
HAL_ADC_CHAN IsenA
Definition: drv8311.h:173
Hall Sensored Trap Motor Control Library HAL Module.
HAL_ADC_VREF
Definition: hal.h:190
Define drv8311 CSA GAIN 2.0 Setting.
Definition: drv8311.h:102
drv8311_DRVOFF_PIN_STAT
Definition: drv8311.h:106
GPIO set to high.
Definition: hal.h:84
Define DRVOFF PIN HIGH.
Definition: drv8311.h:111
HAL_ADC_CHAN
Definition: hal.h:88
HAL_GPIO_IN
Definition: hal.h:109
HAL_SPI_CS
Definition: hal.h:176
HAL_ADC_CHAN VsenB
Definition: drv8311.h:165
#define drv8311_MAXIMUM_WAKEUP_TIME
Defines the time to wakeup the drv after reset.
Definition: drv8311.h:67
HAL_GPIO_OUT nsleep
Definition: drv8311.h:129
Define drv8311 CSA GAIN 1.0 Setting.
Definition: drv8311.h:100
HAL_ADC_INT_VREF
Definition: hal.h:201
void drv8311_enable(drv8311_Instance *drvHandle)
Enable DRV.
Definition: drv8311.c:60
Define drv8311 CSA GAIN 0.25 Setting.
Definition: drv8311.h:96
_iq20 csaVRef
Definition: drv8311.h:153
_iq20 drv8311_getCurrent(HAL_ADC_CHAN chan, drv8311_Instance *drvHandle, _iq20 vRef)
Get current from adc channel.
Definition: drv8311.c:118
Defines drv8311 instance.
Definition: drv8311.h:124
HAL_ADC_CHAN Vsen
Definition: drv8311.h:157
HAL_SPI_CHAN
Definition: hal.h:168
drv8311_DRV_NSLEEP_STAT
Definition: drv8311.h:115
__STATIC_INLINE void drv8311_setnSleep(drv8311_Instance *drvHandle, drv8311_DRV_NSLEEP_STAT value)
set nSleep
Definition: drv8311.h:219
GPIO set to low.
Definition: hal.h:82
Define NSLEEP PIN LOW.
Definition: drv8311.h:118
HAL_ADC_CHAN IsenB
Definition: drv8311.h:177
HAL_ADC_CHAN VsenC
Definition: drv8311.h:169
Define DRVOFF PIN LOW.
Definition: drv8311.h:109
HAL_GPIO_OUT drvoff
Definition: drv8311.h:133
void drv8311_updateCSAScaleFactor(drv8311_Instance *drvHandle, drv8311_CSAGAIN csa)
updates the current gain scale factor
Definition: drv8311.c:75
__STATIC_INLINE _iq20 drv8311_getcsaVref(uint16_t vRef)
get Current reference in IQ20
Definition: drv8311.h:293
HAL_SPI_CHAN spiChan
Definition: drv8311.h:141
HAL_ADC_CHAN IsenC
Definition: drv8311.h:181
Define NSLEEP PIN HIGH.
Definition: drv8311.h:120
_iq20 csa_sf
Definition: drv8311.h:149
drv8311_CSAGAIN
Definition: drv8311.h:93
HAL_GPIO_OUT
Definition: hal.h:124
HAL_GPIO_IN nfault
Definition: drv8311.h:137
void HAL_writeGPIOPin(HAL_GPIO_OUT pin, HAL_GPIO_STATE value)
Write to GPIOpin.
Definition: hal.c:193
__STATIC_INLINE void HAL_delayMicroSeconds(uint32_t microSeconds)
Delays for specific time in microseconds.
Definition: hal.h:487
HAL_FAULT_INPUT faultIn
Definition: drv8311.h:185
void drv8311_init(drv8311_Instance *drvHandle)
initialize the drv8311 module
Definition: drv8311.c:45
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale