Stm32 custom encoder platformio

Hi friends,

I’m about do integrate my custom encoder driven by SPI.

What are main changes in code I have to do while adding my specific encoder, apart from parametrizating a device? Have you encountered any difficulties??

Hi @drajwer , welcome to SimpleFOC!

May I ask wich sensor it is you are integrating?

I’m using some magnetic sensor with more complex features.

Thanks, so I make all the necessary functions between my stm and sensor to communicate and read data constantly and then I just get data from those previous functions inside “readMySensorCallback”??

Or I rather should simply read specific variable through SPI inside the "readMySensorCallback?

float readMySensorCallback(){
 // read my sensor
 // return the angle value in radians in between 0 and 2PI
 return ...;

void initMySensorCallback(){
  // do the init

If it’s just using standard SPI, you can also use the generic MagneticSensorSPI class, I think.
If you need to implement a lot of special functions, then I would implement your SPI reads inside of readMySensorCallback

1 Like

Hey runger, have you closed the loop with bldc?

If yes, did it go smooth in terms of implementation of algorithms or maybe you faced some issues?

That is a bit vague. Can you link to a datasheet?

The genericSensor class is super easy to use. You have to implement an initSensor() and readSensor() method.

Then the GenericSensor can be linked to a the motor using same mechanism as other sensors types i.e. motor.linkSensor(&sensor):

Once you’ve got GenericSensor working you could tidy things up and push the code into a dedicated class that extends the common Sensor class.

1 Like

Thank you, appreciate your help

Yes, absolutely, many times and with many different motors and sensors…

Sometimes it’s very easy, and not sensitive tot he parameters very much, and on other setups tuning can be very tricky.

It depends on many factors.