This is on custom hardware board with ESP32-S3-WROOM, DRV8323 gate driver (3 pin PWM mode) with integrated shunt amplifiers (set to gain=20 and midpoint 3.3V/2) for three 3mOhm low side shunts. Testing with a 1-PP industrial geared BLDC with hall sensors and a hoverboard motor (hall sensors as well). Open-loop works fine, as does closed loop voltage-torque control. Reading the DC current (current_sense.getDCCurrent()) in this mode seems to work well. Sensor and current sense alignemnt is hardcoded with correct parameters to keep everything consistent during testing. Also tried on two different drive boards to elliminate some random HW issue / defect.
The problem is, DC current torque control works well, but only sometimes. When it does, the motor behaves as expected and the DC current reading hovers around the expected set value (0.5A for my testing). This works correctly for both rotation directions.
When it does not work, SimpleFOC applies max voltage almost imedietely, the motor spins very quickly and the DC current readings are very high (5A-10A). When direction change is commanded (same torque but with - sign), motor does not change direction and aplied voltge (reported by SimpleFOC) stays the same.
I have not determined exactly what causes it to work or not work, sometimes it’s different just after a reboot. It does apear that the frequency at which loopFOC() is called has an effect on it. Calling it alone in the main loop makes it work most of the time (execution frequency is around 35kHz in this case) but adding monitoring (>8kHz) or a 1ms delay (1Khz exactly) makes it not work most of the time.
I have tried changing the PID_current_q PIDs without success. The best I can achieve is a slower ramp to the maximum voltage.
Some issues I discovered while debugging that might or might not be related:
- Without executing an analogRead() on current sense pins before current_sense.init() the ESP crashes (WDT reset that backtraces to waiting for conversion in adc driver). This seems to be a bug in ADC initialization code?
- If I print the current sense offset_ia/b/c values in LowsideCurrentSense::calibrateOffsets(), they are consistently around 4.95. Is this expected? The shunt amp output at this time (with no current) is around 1.65V (confirmed with measuring).
Any ideas?
Cheers!