Closed Loop Control - TMAG5273 to simpleFOC hallsensor.h & INA240 & MPC6021 to simpleFOC...

Closed Loop Control - TMAG5273 to simpleFOC hallsensor.h & INA240 & MPC6021 to simpleFOC InlineCurrentSense.h

FOR SparkFun_IoT_Brushless_Motor_Driver all in one board

cross post from:

https://github.com/sparkfun/SparkFun_Io … r/issues/3

Greetings, happy new year, and hope all is well! I am really learning a lot from this board and my deep dive with it, it’s been a wonderful introduction into the world of motors and FOC control.

I have a beginner question, and basically was wondering are there any examples or hints you could give for closed loop controls for this board? It works very well as a wheel for IoT control, but I was hoping to implement it as a motor as opposed to a potentiometer. Hoping to implement very smooth rotation (as opposed to direct voltage open control), haptics, gimbal style motion and anything else. I am new to motor control and a bit new to coding. I could use some pointing in the right direction or som bread crumbs, as it seems. I tried to create a script that calculated RPM and velocity from the angle data from

Specifically can you help find the output of SparkFun_TMAG5273_Arduino_Library_Defs.h, that might “fit” in the HallSensor.h of simpleFOC, and can you help find the INA240/MPC6021 outputs that would match the InlineCurrentSense.h of simpleFOC, either of these would close the loop and get smooth motor operation:

(1) the output of the TMAG5273 chip is not the same as the simpleFOC hallsensor.h input.

simpleFOC required input for HallSensor:

class HallSensor: public Sensor{

public:

/**

HallSensor class constructor

@param encA HallSensor A pin

@param encB HallSensor B pin

@param encC HallSensor C pin

@param pp pole pairs (e.g hoverboard motor has 15pp and small gimbals often have 7pp)

@param index index pin number (optional input)

*/

HallSensor(int encA, int encB, int encC, int pp);

TMAG5273 Output:

All enumerators from class: SparkFun_TMAG5273_Arduino_Library_Defs.h

(2) And the output of the INA240 & MPC6021 are not the same as the simpleFOC InlineCurrentSense.h input:

simpleFOC required input for InlineCurrentSense.h:

class InlineCurrentSense: public CurrentSense{

public:

/**

InlineCurrentSense class constructor

@param shunt_resistor shunt resistor value

@param gain current-sense op-amp gain

@param phA A phase adc pin

@param phB B phase adc pin

@param phC C phase adc pin (optional)

*/

INA240 Current-Sense Amplifier and MPC6221 OpAmp outputs per the manual:

INA240 (U) on GPIO 35, INA240 (V) on GPIO 36, INA240 (W) on GPIO 39, MCP6021 on GPIO 32

Subject of the issue

Using either of the two closed loop FOC control:

TMAG5273 to simpleFOC hallsensor.h & INA240 & MPC6021 to simpleFOC InlineCurrentSense.h

Your workbench

What development board or microcontroller are you using?

Only using the included board:

[SparkFun_IoT_Brushless_Motor_Driver]

What version of hardware or breakout board are you using?

Revision number listed on bottom left of back red board, v10 (cannot see a . could be v1.0 but reads as v10)

How is the breakout board wired to your microcontroller?

NA

How is everything being powered?

USB over Battery, or USB over computer (both utilized)

Are there any additional details that may help us help you?

No, stock all in one board configuration.

Steps to reproduce

Issue here is in generating the code to begin with, see above description

Expected behavior

simpleFOC hallsensor.h should be populated with data from TMAG5273 hall sensor

simpleFOC InlineCurrentSense.h should be populated with data from INA240 & MPC6021

Actual behavior

Currently TMAG5273 hall sensor provides angular data, and I dont see within the manual a description of all the the functions contained within SparkFun_TMAG5273_Arduino_Library_Defs.h, SparkFun_TMAG5273_Arduino_Library_Defs.h is not commented enough that a begginer like myself can convert the TMAG data to simpleFOC hallsensor.h logic.

Currently INA240 & MPC6021 data is only described (as far as my abilities and travels have thus led me, I may have missed a doc) in the online hardware overview MKdoc with INA240 (U) on GPIO 35, INA240 (V) on GPIO 36, INA240 (W) on GPIO 39, MCP6021 on GPIO 32. I am wondering how to rectify these pin inputs with the simpleFOC InlineCurrentSense.h logic.

Thank you for any help you may have,

Waffle City, aiaaaa