Deng FOC Board - Easy to use!

Hi Folks,

For those of you who want to quickly get familiar with SimpleFOC using low power motors (gimbal), I recommend trying this board from Aliexpress:

It includes 2 sets of AS5600 I2C mag sensors, which are adequate for simple projects or getting familiar with position sensors.

I was able to successfully use all control modes with it, including FOC current current (true torque control!). In the past, I had some trouble getting current mode to work, mostly due to not knowing what values to set for the q and d PI gains.

The example Arduino files located here work great for small gimbal motors: Deng-s-foc-controller/Dengs FOC V3.0/Dengs FOC V3.0 测试例程(支持库SimpleFOC 2.2.1) at master · ToanTech/Deng-s-foc-controller · GitHub

Cheers!
Ben

2 Likes

Hi Ben,

I just received my Deng FOC board. Shame I did not see your post before, it took me some time to find the sample code, the only way of knowing the pins to allocate etc.

I agree the board seems to do everything that simpleFOC offers.

As I go through the examples I reached the dengFOC Current test example. This one crashes on me. Does it work for you?

Regards,

Carl

For other readers this is the Feng FOC 3.0 driven by an ESP32 development board lolin32 lite on the bottom.

Here is the code.

//Current detection test routine Test hardware:FOC V3.0
#include <SimpleFOC.h>

// Current Detection
// Sampling resistor value Gain ADC pin
// check if your board has R010 (0.01 ohm resistor) or R006 (0.006 mOhm resistor
InlineCurrentSense current_sense0 = InlineCurrentSense(0.006, 50, 39, 36, _NC);

void setup() {

Serial.begin(115200);
delay(1000);
Serial.println(“Current sense ready.”);
delay(1000);
// Current Detection

current_sense0.init();
//current_sense0.gain_b *= -1;
}

void loop() {
Serial.println(“Current sense ready.”);

PhaseCurrent_s currents0 = current_sense0.getPhaseCurrents();
float current_magnitude0 = current_sense0.getDCCurrent();
Serial.print(currents0.a1000); // milli Amps
Serial.print("\t");
Serial.print(currents0.b
1000); // milli Amps
Serial.print("\t");
Serial.print(currents0.c1000); // milli Amps
Serial.print("\t");
Serial.println(current_magnitude0
1000); // milli Amps
Serial.println();
}

And here is the crash

Rebooting…
Current sense ready.
Guru Meditation Error: Core 1 panic’ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x400d1d1b PS : 0x00060830 A0 : 0x800d11e6 A1 : 0x3ffb27d0
A2 : 0x3ffc1180 A3 : 0x00000014 A4 : 0x0800001c A5 : 0x00000003
A6 : 0x00000001 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x3ffb27b0
A10 : 0x000003e8 A11 : 0x3ffbef48 A12 : 0x00000000 A13 : 0xffffcfc7
A14 : 0x3ffb7e50 A15 : 0x00000000 SAR : 0x00000003 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000020 LBEG : 0x4008646d LEND : 0x4008647d LCOUNT : 0xfffffffa

Backtrace:0x400d1d18:0x3ffb27d00x400d11e3:0x3ffb27f0 0x400d323a:0x3ffb2820

ELF file SHA256: 0000000000000000

By the way, it crashes on current_sense0.init();

Hey Carl,
This is a bug of the simplefoc I think. It is fixed in the dev branch if you are interested in changing.
If not, you’ll need to create a dummy BLDCDriver instance do not even need to init it. Just link it to the current sense, before you call the current sense init. current_sense.linkDriver(&driver);

Awesome fast reply, thanks that fixed it. For other viewers below is the working code.
Now to go and find these currents in simpleFOCStudio!!

Regards,

Carl

//Current detection test routine Test hardware:FOC V3.0

#include <SimpleFOC.h>

//Dummy BLDC
// BLDC motor & driver instance
BLDCMotor motor = BLDCMotor(8);
BLDCDriver3PWM driver = BLDCDriver3PWM(32,33,25,22);

// Current Detection
// Sampling resistor value Gain ADC pin
// check if your board has R010 (0.01 ohm resistor) or R006 (0.006 mOhm resistor
InlineCurrentSense current_sense0 = InlineCurrentSense(0.006, 50, 39, 36, _NC);

void setup() {

Serial.begin(115200);
delay(1000);
// Current Detection
current_sense0.linkDriver(&driver);
current_sense0.init();
current_sense0.gain_b *= -1;
Serial.println(“Current sense setup complete.”);
delay(1000);
}

void loop() {

PhaseCurrent_s currents0 = current_sense0.getPhaseCurrents();
float current_magnitude0 = current_sense0.getDCCurrent();

Serial.print(currents0.a1000); // milli Amps
Serial.print("\t");
Serial.print(currents0.b
1000); // milli Amps
Serial.print("\t");
Serial.println(current_magnitude0*1000); // milli Amps
}

@Antun_Skuric Do the fixes in the dev branch address the issue where using current sensing prevented the use of analogRead()?

Hey @wrcman555,

No, this we did not address yet and might not so soon.

If your analogRead does not work with current sensing you can use adcRead which is a more efficient version of the analog read.

You might have to include in addition to simplefoc.h:

#include "current_sensing/hardware_specific/esp32/esp32_driver.h"

@Antun_Skuric Thanks! I remember you telling me that. It works well!

Inline current sensing worked fine for me out of the box on the dev release and I could go to FOC current control on torque.

@Carl Same here! I am using the 2 exposed esp pins (I0 and I1) to read values from an external dc current sensor as well as a potentiometer. I had to use adcRead() instead of analogRead().