SimpleFOCShield: does my current sensing really work?

My motor works fine with my SimpleFOCShield, both in “DC Current” and “FOC Current” modes. Additionally, I successfully tuned the Current PIDs in order to improve the angle control. All this seem to indicate that my current sensing works as expected.

However, when I try to read actual current values, I get puzzling results:

In my application (which looks a lot like single_full_control_example), adding motor.monitor_variables = _MON_CURR_Q|_MON_CURR_D gets me only zeros in SimpleFOCStudio:

image

Same thing if I use current_sense.getPhaseCurrents() and current_sense.getDCCurrent(): they return only zeros.

However, if I run the inline_current_sense_test example (which calls current_sense.getPhaseCurrents() and current_sense.getDCCurrent()), I seem to get noise:

image

Does it make sense?

Never mind, it was a silly mistake. I now get correct values from current_sense.getPhaseCurrents() and current_sense.getDCCurrent() in all cases.

2 Likes

Hi quentin. I have been having a somewhat similar problem. If you don’t mind, what was the mistake that was made?

I develop under STM32CubeIDE, using a port of SimpleFOC and STM32Duino I did for STM32CubeIDE. The bug was in my STM32Duino port: the analogRead() function always returned zero.

I should have known right away. When a function returns exactly zero all the time, then it is most probably due to a code issue (a function returning a default value). All I needed to do was to trace the code up to the faulty function.