Inlinecurrent and Lowsidecurrent parameters

Hi everyone,
I have a question for use Inlinecurrent and lowsidecurrent.
My platform : stm32G431RB
My motorDrive : SimpleFOCShieldV2.0.4

If I use Inlinecurrent, my intial parameters as below
InlineCurrentSense current_sense = InlineCurrentSense(0.01, 50.0, PA0, PA1);
then I use lowsidecurrent, Do I need to change the resistance and gain
LowsideCurrentSense current_sense = LowsideCurrentSense(0.01, 50.0, PA0, PA1) ?

thank you.

Hi @Kevin, welcome to SimpleFOC!

The SimpleFOCShield has inline shunt resistors, so you can’t use low side current sensing with this driver. With this driver you just use the inline sensing.

1 Like

Hey @Kevin,

As @runger said simplefocshield has inline current sense on board so it is preferable to use the inline current sense code for it.

However you can also use the low side current sense code, the gains and shunt are hardware components and they stay the same in the code.

If you decide to use low side code make sure to lower the pwm frequency of your driver to around 20kHz.

One benefit of the low side current sensing code over the inline current sensing is the speed. As the low side current sense code does not call analogRead, it takes much less time to read the currents and you’ll have much shorter loop times.

So briefly

  • shunt and gain values don’t change
  • preferred way is to use inline current sense code with inline current sensing hardware
  • you can use low-side current sense code with the inline current sense hardware ( not inverse though). It has some benefits like faster loop times, but also some inconveniences like lower pwm frequency
1 Like

Thank you for the explanation. :slightly_smiling_face:
I will choose the best for my system.


For STM32, we could achieve extremely fast analog reads either by DMA or use dual-channel interleaved mode. Using interleaved mode, the regular SMT32 CPU is fast enough to pull data at maximum speed without DMA, at 584 nanoseconds per sample (for STM32F103).

In STM32 analogRead() and the STM Arduino STM32duino core, the bluepill ADC conversion time is about 7 us so we could dramatically improve the read times.

I need to read the code to see if this has been done, I may be saying something obvious here of course.


//Measure on A0
uint16_t analogDataPoints[100];
void analogsample() { 
  int channel = PIN_MAP[PA0].adc_channel;
  adc_set_sample_rate(ADC1, ADC_SMPR_1_5); // ADC_SMPR_13_5, ADC_SMPR_1_5
  adc_set_sample_rate(ADC2, ADC_SMPR_1_5); // ADC_SMPR_13_5, ADC_SMPR_1_5
  adc_set_reg_seqlen(ADC1, 1);
  adc_set_reg_seqlen(ADC2, 1);
  ADC1->regs->SQR3 = channel;
  ADC2->regs->SQR3 = channel;

  ADC1->regs->CR1 |= 0x70000; // ADC_CR1_FASTINT;
  ADC1->regs->CR2 |= ADC_CR2_CONT | ADC_CR2_SWSTART;
  ADC2->regs->CR2 |= ADC_CR2_CONT | ADC_CR2_SWSTART;
  ADC2->regs->CR1 |= 0x70000; // ADC_CR1_FASTINT;
  for (int j = 0; j < 100 ; j+=2 )
    while (!(ADC1->regs->SR & ADC_SR_EOC))
    analogDataPoints[j] = ADC1->regs->DR & ADC_DR_DATA;
    while (!(ADC2->regs->SR & ADC_SR_EOC))
    analogDataPoints[j+1] = ADC2->regs->DR & ADC_DR_DATA;