|
UUtzinger_DRV8704
0.1.1
Arduino library for the DRV8704 dual H-bridge gate driver
|
Arduino library for the Texas Instruments DRV8704 dual H-bridge gate driver.
Generated API docs are available at: https://uutzinger.github.io/Arduino_DRV8704/
This library exposes the DRV8704 through one consistent control model:
CoastBrakeCurrentDrivePwmDriveWithCurrentLimitIt also provides:
The DRV8704 is not a pure SPI motor controller.
It has two separate control surfaces:
AIN1/AIN2/BIN1/BIN2:Important hardware constraint:
ISGAIN and TORQUE are chip-globalMinimum useful connections:
SCS to a GPIO used as chip selectSCLK, SDATI, SDATO to the MCU SPI busAIN1, AIN2, BIN1, BIN2 to GPIO or PWM-capable pinsRecommended optional connections:
SLEEPnRESETFAULTn with pull-upBoard-level requirements still come from the DRV8704 datasheet:
FAULTn and SDATODirection is separate from magnitude control:
setDirection(BridgeId bridge, Direction direction)This direction is then used by both:
setCurrent(...)setSpeed(...)Use explicit static bridge commands when you want an immediate override:
coast(BridgeId bridge)brake(BridgeId bridge)These states override active current-drive or PWM-drive behavior on that bridge immediately.
Use current drive when you want the DRV8704 internal current chopper to regulate a bridge in the currently selected direction.
Current drive is intended for inductive loads. Do not present it as a primary control method for resistive heaters.
Primary API:
setShuntResistance(float ohms) depends on your hardware designsetShuntResistance(BridgeId bridge, float ohms)setCurrentModePreset(CurrentModePreset preset) timing baseline for heater, TEC, or motor loadssetCurrentLimit(float amps)setCurrent(BridgeId bridge, float amps)disableCurrentLimit()currentLimitResult()Control flow:
setCurrent(...)Current-limit equation used by the driver:
The implementation chooses the highest usable gain first because that gives the finest current resolution for a given shunt.
Important limitation:
currentLimitResult() reports the programmed current-trip settings, not measured load currentUse PWM mode when you want open-loop duty control while keeping the DRV8704 current limit active during PWM on-time. This is the recommended control path for resistive heaters.
Primary API:
beginPwmMode(const DRV8704PwmConfig& config)setPwmFrequency(uint32_t hz)setCurrentLimit(float amps)setDirection(BridgeId bridge, Direction direction)setSpeed(BridgeId bridge, float percent)pwmCapability()Behavior:
setSpeed(..., 0): behaves like coast(...)setSpeed(..., 100): constant-on directional input, no PWM toggling0 < speed < 100: one bridge input is PWM, the complementary input is held lowHigh-level PWM control is intentionally framed as PWM with current limit. If you want effectively unbounded drive, deliberately program a very high current limit instead of using a separate unsafe mode.
Default library PWM settings now start from:
5 kHz10-bit preferred resolutionThe interactive examples follow that model by default:
pwm ... commands apply PWM with the stored current limit activefull ... is the explicit no-current-limit comparison modeDRV8704_Test is the main engineering console for bring-up and bench tuningThe presets are starting points for current-limit timing, not guaranteed final answers.
HeaterTOFF=0x40, TBLANK=0x00, AutoMixed decay on the reference heater-pad setupThermoelectricCoolerMotorSmallInductanceMotorMediumInductanceMotorLargeInductanceThe implementation also adjusts preset timing when PWM mode is active at higher frequency. Validate the preset on real hardware and retune as needed.
The bridge follows the most recent command on that bridge.
Examples:
coast(bridge)brake(bridge)beginPwmMode(...)setCurrentLimit(...)setDirection(...)setSpeed(...)setDirection(...)setCurrent(...)The current-limit configuration remains programmed until you change it or call disableCurrentLimit().
The example set is organized by workflow:
BasicBringupRegisterHealthCheckDRV8704_TestBridgeControlDemoCurrentModeDemoCurrentPresetDemoCurrent_TestPwmModeDemoPWM_TestUse examples/DRV8704_Test when you need one serial console for:
BasicBringup and RegisterHealthCheckfull drive on hardwareSupported PWM backends:
analogWrite()The generic Arduino backend does not control PWM frequency directly. Hardware-specific backends report achieved frequency and duty resolution through pwmCapability().
Fault handling is available through:
STATUS registerFAULTn pinhealthCheck() for startup plausibility and fault reportingUseful low-level helpers:
readRegister()writeRegister()updateRegister()applyConfig()readStatus()hasFault()clearFaults()README.md provides the top-level usage modeldocs/ contains generated Doxygen output when documentation has been built