On this page
DRV8316 driver
The DRV8316 from Texas Instruments is a 3-phase motor driver with integrated MOSFETs, 3 current sense amplifiers, a buck regulator and full protection, all configured over SPI. It runs from 4.5V to 35V and delivers up to 8A peak, which makes it a great fit for compact BLDC and stepper controllers. It is used on the SimpleFOCMini v2 and the SimpleFOC-microspora.
The DRV8316 also works without SPI, as a plain 3-PWM or 6-PWM driver using the standard BLDCDriver3PWM / BLDCDriver6PWM classes. The SimpleFOCDrivers classes add everything the SPI interface offers: PWM mode, current sense gain, slew rate, protection settings, and reading the fault status.
Driver source and README Examples
Hardware setup
| DRV8316 pin | Connect to |
|---|---|
| SDI, SDO, SCLK, nSCS | SPI MOSI, MISO, SCK, and a chip select pin |
| INHA, INHB, INHC | PWM pins (high side) |
| INLA, INLB, INLC | 6-PWM: PWM pins (low side). 3-PWM: digital outputs, or pull up to enable the phases |
| nFAULT (optional) | Digital input, active low |
| DRVOFF (optional) | Digital output, to switch the driver off |
| SOA, SOB, SOC (current sense) | Analog inputs |
| VREF / ILIM | Reference voltage for the current sense amplifiers and the current limit |
Usage
Use DRV8316Driver6PWM or DRV8316Driver3PWM instead of the standard driver class. Everything else in your code stays the same.
#include <SimpleFOC.h>
#include <SimpleFOCDrivers.h>
#include "drivers/drv8316/drv8316.h"
BLDCMotor motor = BLDCMotor(11);
// 6-PWM: high/low pin pairs for phases A, B, C, then the SPI chip select
DRV8316Driver6PWM driver = DRV8316Driver6PWM(A_H, A_L, B_H, B_L, C_H, C_L, CS);
// or 3-PWM: three PWM pins, then the SPI chip select
// DRV8316Driver3PWM driver = DRV8316Driver3PWM(A, B, C, CS);
void setup() {
driver.voltage_power_supply = 12;
driver.init(); // also sets the DRV8316 to the matching PWM mode over SPI
motor.linkDriver(&driver);
// ... the rest of your usual SimpleFOC setup
}
The full constructor parameters are:
DRV8316Driver6PWM(phA_h, phA_l, phB_h, phB_l, phC_h, phC_l, cs, currentLimit = false, en = NOT_SET, nFault = NOT_SET);
DRV8316Driver3PWM(phA, phB, phC, cs, currentLimit = false, en = NOT_SET, nFault = NOT_SET);
en: the pin connected to DRVOFF. It is active low: the class drives it low to enable the driver.nFault: the pin connected to nFAULT, configured as an input.
Using a different SPI bus
init() uses the default SPI object. If the DRV8316 is on another SPI bus, or on non-default pins, pass your own SPIClass:
SPIClass SPI_3(MOSI_PIN, MISO_PIN, SCK_PIN);
driver.init(&SPI_3);
Configuration
All the DRV8316 registers are available as getter and setter methods, with the options as enums. Configure the driver after driver.init() and before motor.init():
driver.init();
driver.setSlew(Slew_200Vus); // slew rate: 25, 50, 150 or 200 V/us
driver.setBuckVoltage(VB_5V); // buck output: 3.3V, 4V, 5V or 5.7V
driver.setBuckCurrentLimit(Limit_600mA);
driver.setOCPMode(Latched_Fault); // what to do on overcurrent, see below
driver.setCurrentSenseGain(Gain_0V3); // see current sensing below
The setters already wait the 400ns the DRV8316 needs between SPI operations, so you don’t need to add delays yourself.
| Setting | Methods | Options |
|---|---|---|
| PWM mode | setPWMMode() | PWM6_Mode, PWM6_CurrentLimit_Mode, PWM3_Mode, PWM3_CurrentLimit_Mode (set automatically by init()) |
| Slew rate | setSlew() | Slew_25Vus, Slew_50Vus, Slew_150Vus, Slew_200Vus |
| Current sense gain | setCurrentSenseGain() | Gain_0V15, Gain_0V3, Gain_0V6, Gain_1V2 |
| Overcurrent protection | setOCPMode(), setOCPLevel(), setOCPRetryTime(), setOCPDeglitchTime() | Latched_Fault, AutoRetry_Fault, ReportOnly, NoAction; 16A or 24A |
| Overvoltage protection | setOvervoltageProtection(), setOvervoltageLevel() | on/off; 20V or 32V |
| Buck regulator | setBuckEnabled(), setBuckVoltage(), setBuckCurrentLimit() | 3.3V, 4V, 5V, 5.7V; 150mA or 600mA |
| Recirculation | setRecirculationMode() | BrakeMode, CoastMode |
| Register lock | setRegistersLocked() | locks the configuration against accidental writes |
Current sensing
The DRV8316 measures the current in the low-side MOSFET of each phase, so use LowsideCurrentSense. The amplifier gain is set over SPI, and the value you give to LowsideCurrentSense (in mV/A) must match it:
setCurrentSenseGain() | LowsideCurrentSense gain |
|---|---|
Gain_0V15 | 150.0f |
Gain_0V3 | 300.0f |
Gain_0V6 | 600.0f |
Gain_1V2 | 1200.0f |
LowsideCurrentSense current_sense = LowsideCurrentSense(300.0f, SOA_PIN, SOB_PIN, SOC_PIN);
void setup() {
// ... driver.init()
driver.setCurrentSenseGain(Gain_0V3); // matches 300 mV/A
current_sense.linkDriver(&driver);
current_sense.init();
motor.linkCurrentSense(¤t_sense);
// ... motor.init(), motor.initFOC()
}
A higher gain gives better resolution for small currents but a smaller measurable range. Pick the highest gain that still covers the peak current of your motor. With a 3.3V ADC and the amplifier output centred at half of it, the range is roughly ±1.65V divided by the gain, e.g. about ±5.5A at 0.3 V/A.
Low-side current sensing is not supported on all microcontrollers, check the current sensing support before choosing your MCU.
Current limiting
In the PWM6_CurrentLimit_Mode and PWM3_CurrentLimit_Mode PWM modes, the DRV8316 limits the phase current cycle by cycle, with the threshold set by the voltage on the VREF/ILIM pin. This is a hardware safety limit, independent of the SimpleFOClibrary current control. Set the mode after driver.init(), since init() sets the plain PWM mode:
driver.init();
driver.setPWMMode(PWM6_CurrentLimit_Mode);
See the DRV8316 datasheet for how the ILIM voltage maps to the current limit.
Faults and diagnostics
The DRV8316 detects overcurrent, overtemperature, overvoltage, undervoltage, buck regulator faults and SPI errors. When something doesn’t work, read the status first:
DRV8316Status status = driver.getStatus();
if (status.isFault()) {
Serial.print("Overcurrent: "); Serial.println(status.isOverCurrent());
Serial.print("Overtemperature: "); Serial.println(status.isOverTemperature());
Serial.print("Overvoltage: "); Serial.println(status.isOverVoltage());
Serial.print("Buck error: "); Serial.println(status.isBuckError());
Serial.print("Charge pump UV: "); Serial.println(status.isChargePumpUnderVoltage());
Serial.print("SPI error: "); Serial.println(status.isSPIError());
driver.clearFault();
}
For overcurrent, you can also find out which MOSFET tripped with isOverCurrent_Ah(), isOverCurrent_Al(), … isOverCurrent_Cl(). The README has a complete status printing example.
Overcurrent protection modes
Latched_Fault(safest): the driver switches off on overcurrent and stays off untilclearFault()is called.AutoRetry_Fault: the driver switches off and retries after the retry time.ReportOnlyandNoAction: the driver keeps running. Only use these if you understand the risk, for example while debugging false trips with very low resistance motors.
Common causes of faults:
- Overcurrent right at startup: motor phase resistance too low for the supply voltage, a short in the motor wiring, or a too high
voltage_limit. - SPI error: wrong SPI mode or wiring. The driver uses SPI mode 1 at 1MHz, which the class sets automatically.
- Power-on reset flag (
isPowerOnReset()): the driver was reset by a supply dip, often caused by a weak power supply. The configuration has to be written again.