Current sensing with the DRV8316

Hi everyone,

I’m working on a custom FOC motor controller using the DRV8316CRQRGFRQ1, and I have some questions regarding how to properly implement current sensing with the SimpleFOC library.

The DRV8316 uses low-side current sensing with integrated current sense amplifiers, and outputs an analog voltage of the form:

SOx = Vref/2 ± Gain × Iout

So from what I understand, I need to:

  • Read the SOx signals using ADC

  • Subtract the offset (Vref/2)

  • Divide by gain (and shunt resistor?) to get current in amps

However, I’m a bit unsure about how this maps into SimpleFOC:

  1. Should I use LowsideCurrentSense or GenericCurrentSense?
    Since the DRV8316 already includes current sense amplifiers, I’m wondering if GenericCurrentSense is more appropriate, where I manually convert ADC readings to current.

  2. What should I use as the shunt resistance in LowsideCurrentSense?
    The driver doesn’t include internal shunt resistors (as far as I understand), so this depends on my external hardware. But since the output is already amplified, I’m unsure how to correctly set the parameters (gain vs shunt value).

  3. Timing / synchronization:
    For low-side sensing, I assume ADC sampling needs to be synchronized with PWM (when low-side MOSFETs are on).
    Does SimpleFOC handle this internally when using LowsideCurrentSense, or do I need to manage ADC triggering manually?

If anyone has experience using DRV83xx drivers (especially DRV8316) with SimpleFOC, I’d really appreciate some guidance or example setups.

Thanks!

  1. DRV8316 uses lowside current sensing
  2. You should set the gain (in mv/A) that is configured for your DRV8316. For example: LowsideCurrentSense current_sense = LowsideCurrentSense(1200.0f, PA0, PA1, PA2);
  3. What microcontroller ae you using? SimpleFOC does it automatically for my STM32G4

Forget about the gain and shunt in the constructor, just input any values and your ADC pins. Then after instancing, directly assign the gain_a, gain_b, and gain_c with your Scaler value. These scaler values are the ultimate computational goal of those constructor’s parameters. You don’t have to deal with them if you can just give SimpleFOC its goal directly. The scaler value is calculated with the formula:

Scaler = Vref / (Gain * ADC_max_value * shunt_res)

For example, your ESP32-S3 has 12-bit ADC, so ADC_max_value = 4095, The Vdd for the ADC might be 3.3V (I’m not sure, check your datasheet), and your shunt is of your choice, I’ll assume 0.001R, and let’s say you configure your DRV8316 to have a gain of 10:

Scaler = 3.3 / (10 * 4095 * 0.001) = 0.080586

Just set gain_a, gain_b, and gain_c to this value and forget about the other formulas and parameters. That’s it.