MSPM0L1306BrushedMotorControlLibrary  1.0
drv8706-q1.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  * @file drv8706-q1.h
34  * @brief Brushed Motor Driver Library DRV8706-Q1 Motor Driver Module
35  * @defgroup BSM__MSPM0L_DRV8706Q1 DRV8706-Q1 - Motor Driver Module
36  *
37  * @anchor bsm_motor_driver_drv8706q1_Overview
38  * # Overview
39  *
40  * The DRV8706-Q1 motor driver module utilizes the HAL's apis to control the
41  * drv8706-q1 brushed motor driver.
42  *
43  * <hr>
44  ******************************************************************************/
48 #ifndef bsm_motor_driver_drv8706q1_h
49 #define bsm_motor_driver_drv8706q1_h
50 
51 #include "hal.h"
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
61 typedef enum
62 {
72 
77 typedef enum {
87 
92 typedef enum {
100 
105 typedef enum {
111 
116 typedef enum {
122 
127 typedef enum {
133 
137 typedef enum {
167 
171 typedef enum {
181 
186 typedef enum {
192 
193 #ifndef DOXYGEN_SHOULD_SKIP_THIS
194 
195 typedef enum {
197  DRV8706Q1_SPI_W0_WRITE = 0,
199  DRV8706Q1_SPI_W0_READ = 1,
200 } DRV8706Q1_SPI_W0_BIT;
201 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
202 
206 typedef struct {
215  _iq20 csaSF;
261 
265  _iq20 aRef_V;
266 
271 
276 
280  _iq20 shuntRes;
281 
285  DRV8706Q1_MODES driveMode;
287 
288 
297 
310  DRV8706Q1_H_BRIDGE_DRIVES drive);
311 
322  DRV8706Q1_H_BRIDGE_DRIVES drive);
323 
335  DRV8706Q1_PHASE_DRIVES drive);
336 
347  DRV8706Q1_PHASE_DRIVES drive);
348 
359  DRV8706Q1_SOLENOID_DRIVES drive);
360 
372  DRV8706Q1_PWM_CHANNELS drvChan,
373  DRV8706Q1_HALF_BRIDGE_DRIVES drive);
374 
387  DRV8706Q1_HALF_BRIDGE_DRIVES driveChan0,
388  DRV8706Q1_HALF_BRIDGE_DRIVES driveChan1);
389 
401  DRV8706Q1_SOLENOID_DRIVES drive);
402 
403 #ifndef DOXYGEN_SHOULD_SKIP_THIS
404 uint16_t DRV8706Q1_spiCmd(SPI_CHANNELS spiChan,
405  SPI_CS spiCS,
406  DRV8706Q1_SPI_W0_BIT wo_bit,
407  DRV8706Q1_SPI_ADDR addr,
408  uint8_t data);
409 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
410 
432  DRV8706Q1_SPI_ADDR addr,
433  uint8_t mask,
434  uint8_t value);
435 
436 
453 __STATIC_INLINE uint16_t DRV8706Q1_spiWriteCmd(DRV8706Q1_INSTANCE drv,
454  DRV8706Q1_SPI_ADDR addr,
455  uint8_t data) {
456  return DRV8706Q1_spiCmd(drv.spiChan,drv.spiCS, DRV8706Q1_SPI_W0_WRITE,addr,data);
457 }
458 
471 __STATIC_INLINE uint16_t DRV8706Q1_spiReadCmd(DRV8706Q1_INSTANCE drv,
472  DRV8706Q1_SPI_ADDR addr) {
473  return DRV8706Q1_spiCmd(drv.spiChan,drv.spiCS, DRV8706Q1_SPI_W0_READ,addr,0x0);
474 }
475 
476 
484 
485 #ifndef DOXYGEN_SHOULD_SKIP_THIS
486 
487 void DRV8706Q1_setPWMFreq(DRV8706Q1_INSTANCE drv,
488  DRV8706Q1_PWM_CHANNELS drvChan,
489  uint32_t value);
490 
491 void DRV8706Q1_setDutyCycle(DRV8706Q1_INSTANCE drv,
492  DRV8706Q1_PWM_CHANNELS drvChan,
493  uint8_t value);
494 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
495 
509  DRV8706Q1_PWM_CHANNELS drvPwmChan,
510  uint32_t value);
511 
512 
525  DRV8706Q1_PWM_CHANNELS drvPwmChan,
526  uint8_t value);
527 
537 
545 
557 __STATIC_INLINE void DRV8706Q1_setNSleep(DRV8706Q1_INSTANCE drv,bool value) {
558  HAL_setGPIOOutput(drv.nSleep,value);
559  /* tWake - Turnon time = 1ms
560  * tSleep - Turnoff time = 1ms
561  * So not matter what you set sleep pin to just wait 1 ms
562  */
564 }
565 
573 __STATIC_INLINE void DRV8706Q1_setDrvOff(DRV8706Q1_INSTANCE drv,bool value) {
574  HAL_setGPIOOutput(drv.drvOff,value);
575 }
576 
584 __STATIC_INLINE void DRV8706Q1_setNHiZ1(DRV8706Q1_INSTANCE drv,bool value) {
585  HAL_setGPIOOutput(drv.nHiz1,value);
586 }
587 
595 __STATIC_INLINE void DRV8706Q1_setNHiZ2(DRV8706Q1_INSTANCE drv,bool value) {
596  HAL_setGPIOOutput(drv.nHiz2,value);
597 }
598 
609 void DRV8706Q1_setAnalogReference(DRV8706Q1_INSTANCE *drv, _iq20 aRef_V);
610 
622  DRV8706Q1_CSA_DIV csaDiv);
623 
635  DRV8706Q1_CSA_GAINS gcsa);
636 
649  _iq20 rShunt);
650 
651 #ifdef __cplusplus
652 }
653 #endif
654 
655 #endif
656 
DRV8706Q1_CSA_DIV csaDiv
Definition: drv8706-q1.h:275
__STATIC_INLINE void DRV8706Q1_setDrvOff(DRV8706Q1_INSTANCE drv, bool value)
Help function that controls the MCU pin connected to DrvOff pin on the motor driver.
Definition: drv8706-q1.h:573
_iq20 csaSF
Definition: drv8706-q1.h:215
SPI_CHANNELS spiChan
Definition: drv8706-q1.h:255
Definition: drv8706-q1.h:163
Definition: drv8706-q1.h:159
uint16_t DRV8706Q1_switchToPhaseDrive(DRV8706Q1_INSTANCE *drv, DRV8706Q1_PHASE_DRIVES drive)
Function will program the motor driver to switch to Phase control mode and reconfigure the pin to the...
Definition: drv8706-q1.c:270
Definition: drv8706-q1.h:94
void HAL_setGPIOOutput(GPIO_OUTPUT_PINS pin, PIN_MODE mode)
Set output pin&#39;s value.
Definition: hal.c:210
Definition: drv8706-q1.h:64
DRV8706Q1_CSA_GAINS csaGain
Definition: drv8706-q1.h:270
DRV8706Q1_PWM_CHANNELS
Represents the motor driver&#39;s input pins that expects a PWM signal.
Definition: drv8706-q1.h:127
__STATIC_INLINE void DRV8706Q1_setNHiZ1(DRV8706Q1_INSTANCE drv, bool value)
Help function that controls the MCU pin connected to nHiZ1 pin on the motor driver.
Definition: drv8706-q1.h:584
__STATIC_INLINE uint16_t DRV8706Q1_spiWriteCmd(DRV8706Q1_INSTANCE drv, DRV8706Q1_SPI_ADDR addr, uint8_t data)
Perform a SPI write operation. This function already converts the address and data to the data format...
Definition: drv8706-q1.h:453
Definition: drv8706-q1.h:151
Brushed Motor Driver Library HAL Module.
Definition: drv8706-q1.h:107
__STATIC_INLINE void DRV8706Q1_setNHiZ2(DRV8706Q1_INSTANCE drv, bool value)
Help function that controls the MCU pin connected to nHiZ2 pin on the motor driver.
Definition: drv8706-q1.h:595
Definition: drv8706-q1.h:131
void DRV8706Q1_changeHBridgeDrive(DRV8706Q1_INSTANCE drv, DRV8706Q1_H_BRIDGE_DRIVES drive)
Function will reconfigure the pins for the specific H-bridge mode configuration. Unlike DRV8706Q1_swi...
Definition: drv8706-q1.c:193
Definition: drv8706-q1.h:173
Definition: drv8706-q1.h:145
ADC_CHANS
Definition: hal.h:161
DRV8706Q1_PHASE_DRIVES
Represents all the different configurations the Phase Enable control mode supports.
Definition: drv8706-q1.h:92
void DRV8706Q1_changeSolenoidDrive(DRV8706Q1_INSTANCE drv, DRV8706Q1_SOLENOID_DRIVES drive)
Function will reconfigure the pins for the specific Solenoid mode configuration. Unlike DRV8706Q1_swi...
Definition: drv8706-q1.c:144
Definition: drv8706-q1.h:129
DRV8706Q1_SOLENOID_DRIVES
Represents all the different configurations the Solenoid control mode supports.
Definition: drv8706-q1.h:105
Definition: drv8706-q1.h:79
void DRV8706Q1_reset(DRV8706Q1_INSTANCE *drv)
This functions resets the SPI registers of the motor driver by putting it to sleep, delaying and waking it up. Note that when this function is called the motor driver sleep pin will be high. This functional internally calls DRV8706Q1_powerOnResetVal.
Definition: drv8706-q1.c:232
Definition: drv8706-q1.h:147
PWM_CHANNELS in2Ph
Definition: drv8706-q1.h:250
GPIO_INPUT_PINS nFault
Definition: drv8706-q1.h:230
_iq20 aRef_V
Definition: drv8706-q1.h:265
DRV8706Q1_CSA_DIV
Represents all the current sense amplifier reference voltage divider settings.
Definition: drv8706-q1.h:186
Definition: drv8706-q1.h:141
uint16_t DRV8706Q1_switchToHBridgeDrive(DRV8706Q1_INSTANCE *drv, DRV8706Q1_H_BRIDGE_DRIVES drive)
Function will program the motor driver to switch to H-bridge control mode and reconfigure the pin to ...
Definition: drv8706-q1.c:251
DRV8706Q1_MODES driveMode
Definition: drv8706-q1.h:285
Internal structure that represents a specific DRV8706-Q1.
Definition: drv8706-q1.h:206
Definition: drv8706-q1.h:81
void HAL_delayMilliSeconds(uint32_t num_ms)
Delay function in milliseconds.
Definition: hal.c:327
Definition: drv8706-q1.h:96
Definition: drv8706-q1.h:157
Definition: drv8706-q1.h:188
Definition: drv8706-q1.h:85
uint16_t DRV8706Q1_setCurrentSenseGain(DRV8706Q1_INSTANCE *drv, DRV8706Q1_CSA_GAINS gcsa)
Configure the CSA to the gain setting specified. This function will update the CSA_CTRL.CSA_GAIN register bitfield with the gain you specified.
Definition: drv8706-q1.c:358
GPIO_INPUT_PINS
Definition: hal.h:153
Definition: drv8706-q1.h:175
DRV8706Q1_HALF_BRIDGE_DRIVES
Represents all the different configurations the Half Bridge control mode supports.
Definition: drv8706-q1.h:116
uint16_t DRV8706Q1_spiUpdateRegister(DRV8706Q1_INSTANCE drv, DRV8706Q1_SPI_ADDR addr, uint8_t mask, uint8_t value)
Function to allow a user to modify a specific bitfield in one of the motor driver&#39;s registers...
Definition: drv8706-q1.c:240
DRV8706Q1_H_BRIDGE_DRIVES
Represents all the different configurations the H-Bridge control mode supports.
Definition: drv8706-q1.h:77
GPIO_OUTPUT_PINS nHiz2
Definition: drv8706-q1.h:240
PWM_CHANNELS
Channels described here simply references individual PWM output pins. This means a micro-controller c...
Definition: hal.h:97
void DRV8706Q1_changePhaseDrive(DRV8706Q1_INSTANCE drv, DRV8706Q1_PHASE_DRIVES drive)
Function will reconfigure the pins for the specific Phase enable mode configuration. Unlike DRV8706Q1_switchToPhaseDrive this function does not update the control mode via SPI. So the device must be configured to Phase enable mode already.
Definition: drv8706-q1.c:215
void DRV8706Q1_powerOnResetVal(DRV8706Q1_INSTANCE *drv)
Reset internal DRV structure variables to sync with the motor driver registers power on reset value...
Definition: drv8706-q1.c:60
void DRV8706Q1_changeHalfBridgeDrive(DRV8706Q1_INSTANCE drv, DRV8706Q1_PWM_CHANNELS drvChan, DRV8706Q1_HALF_BRIDGE_DRIVES drive)
Function will reconfigure the pins for the specific Half Bridge mode configuration. Unlike DRV8706Q1_switchToHalfBridgeDrive this function does not update the control mode via SPI. So the device must be configured to Phase enable mode already.
Definition: drv8706-q1.c:163
DRV8706Q1_SPI_ADDR
Represents the addresses for all the SPI registers.
Definition: drv8706-q1.h:137
Definition: drv8706-q1.h:66
__STATIC_INLINE uint16_t DRV8706Q1_spiReadCmd(DRV8706Q1_INSTANCE drv, DRV8706Q1_SPI_ADDR addr)
Perform a SPI read operation. This function converts the address to the data format required by the m...
Definition: drv8706-q1.h:471
Definition: drv8706-q1.h:109
GPIO_OUTPUT_PINS nSleep
Definition: drv8706-q1.h:220
void DRV8706Q1_setAnalogReference(DRV8706Q1_INSTANCE *drv, _iq20 aRef_V)
Set voltage connected to the motor driver&#39;s AREF pin. This value is needed to properly calculate the ...
Definition: drv8706-q1.c:354
DRV8706Q1_CSA_GAINS
Represents all the current sense amplifier gain settings.
Definition: drv8706-q1.h:171
uint16_t DRV8706Q1_switchToSolenoidDrive(DRV8706Q1_INSTANCE *drv, DRV8706Q1_SOLENOID_DRIVES drive)
Function will program the motor driver to switch to Solenoid control mode and reconfigure the pin to ...
Definition: drv8706-q1.c:303
__STATIC_INLINE void DRV8706Q1_setNSleep(DRV8706Q1_INSTANCE drv, bool value)
Help function that controls the MCU pin connected to nSleep pin on the motor driver. Note if you manually set nSLEEP low for more than 1 ms then all the register values will be reset to their default values. Therefore, it would be important to immediately call DRV8706Q1_powerOnResetVal whenver you set nSLEEP to high to make sure internal structures are sync.
Definition: drv8706-q1.h:557
Definition: drv8706-q1.h:177
Definition: drv8706-q1.h:190
Definition: drv8706-q1.h:68
Definition: drv8706-q1.h:70
void DRV8706Q1_init(DRV8706Q1_INSTANCE *drv)
Initialized critical structure representing specific instance of the motor driver. Important Not calling this function will result in unexpected results.
Definition: drv8706-q1.c:68
Definition: drv8706-q1.h:165
uint16_t DRV8706Q1_setAnalogReferenceDivider(DRV8706Q1_INSTANCE *drv, DRV8706Q1_CSA_DIV csaDiv)
Set current shunt amplifier reference voltage divider. This function will update the CSA_CTRL...
Definition: drv8706-q1.c:382
SPI_CS spiCS
Definition: drv8706-q1.h:260
void DRV8706Q1_setCurrentShuntResistor(DRV8706Q1_INSTANCE *drv, _iq20 rShunt)
Set the current shunt resistor value used by the current sense amplifier. This value needs to be set ...
Definition: drv8706-q1.c:399
GPIO_OUTPUT_PINS nHiz1
Definition: drv8706-q1.h:235
Definition: drv8706-q1.h:153
_iq20 shuntRes
Definition: drv8706-q1.h:280
DRV8706Q1_MODES
Represents the four different input control modes the DRV8706-Q1 supports.
Definition: drv8706-q1.h:61
void DRV8706Q1_setDriveDutyCycle(DRV8706Q1_INSTANCE drv, DRV8706Q1_PWM_CHANNELS drvPwmChan, uint8_t value)
Sets the duty cycle for the correct channel based on the drive specified.
Definition: drv8706-q1.c:126
uint16_t DRV8706Q1_switchToHalfBridgeDrive(DRV8706Q1_INSTANCE *drv, DRV8706Q1_HALF_BRIDGE_DRIVES driveChan0, DRV8706Q1_HALF_BRIDGE_DRIVES driveChan1)
Function will reconfigure the pins for the specific Half Bridge mode configuration. Also the control mode will be updated via SPI.
Definition: drv8706-q1.c:285
_iq20 DRV8706Q1_getCurrent(DRV8706Q1_INSTANCE drv)
Return the current read from the DRV8706-Q1 motor driver.
Definition: drv8706-q1.c:404
void DRV8706Q1_setDrivePWMFreq(DRV8706Q1_INSTANCE drv, DRV8706Q1_PWM_CHANNELS drvPwmChan, uint32_t value)
Sets the PWM frequency for the correct channel based on the drive specified.
Definition: drv8706-q1.c:107
Definition: drv8706-q1.h:149
PWM_CHANNELS in1En
Definition: drv8706-q1.h:245
Definition: drv8706-q1.h:83
Definition: drv8706-q1.h:161
GPIO_OUTPUT_PINS
Definition: hal.h:137
Definition: drv8706-q1.h:143
Definition: drv8706-q1.h:139
SPI_CS
The chip select number here has no relationship with the physical chip select that the SPI peripheral...
Definition: hal.h:123
GPIO_OUTPUT_PINS drvOff
Definition: drv8706-q1.h:225
Definition: drv8706-q1.h:120
SPI_CHANNELS
Channels described usually references individual SPI peripheral instances ie ( SCLK, PICO and POCI).
Definition: hal.h:110
Definition: drv8706-q1.h:155
Definition: drv8706-q1.h:118
Definition: drv8706-q1.h:98
Definition: drv8706-q1.h:179
ADC_CHANS adcChan
Definition: drv8706-q1.h:210
© Copyright 1995-2025, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale