simplefoc / Arduino-FOC-drivers

Drivers and support code for SimpleFOC
https://docs.simplefoc.com/drivers_library
MIT License
146 stars 63 forks source link

Support Infineon's TLE5012B SPI encoder #10

Closed zhuangfengzi closed 1 year ago

zhuangfengzi commented 3 years ago

The accuracy of the tle5012b encoder is 16 bit or 15 bit, and the performance is very good! His SPI was originally 3 wires, and the official added 4-wire library, which is convenient to connect! Can add this encoder may give me some advice on code transformation! esteem it a favor!

https://github.com/Infineon/TLE5012-Magnetic-Angle-Sensor

zhuangfengzi commented 3 years ago

Reading angle test code works well! As follows:

include "Tle5012b_4wire.h"

Tle5012b_4wire Tle5012MagneticAngleSensor; errorTypes checkError = NO_ERROR;

void setup() { delay(2000); Serial.begin(115200); checkError = Tle5012MagneticAngleSensor.begin(); Serial.print("checkError: "); Serial.println(checkError,HEX); delay(1000); Serial.println("Init done"); }

void loop() { double d = 0.0; double r = 0.0; double s = 0.0; double t = 0; int16_t b = 0;

Tle5012MagneticAngleSensor.getAngleValue(d); Tle5012MagneticAngleSensor.getNumRevolutions(b); Tle5012MagneticAngleSensor.getAngleSpeed(s); Tle5012MagneticAngleSensor.getAngleRange(r); Tle5012MagneticAngleSensor.getTemperature(t);

Serial.print("Temperature:"); Serial.print(t); Serial.print("°C\tangle:"); Serial.print(d); Serial.print("°\trange:"); Serial.print(r); Serial.print("\tspeed:"); Serial.print(s); Serial.print("\t Revolution:");Serial.println(b);

delay(10); }

owennewo commented 3 years ago

This sensor is somewhat different to the magnetic spi sensors we currently support. E.g returns 4 bytes not 2.

If you want to try to add support for this sensor then I'd suggest starting with the magneticsensorspi.cpp and changing it to meet your sensor. If you have specific questions, feel free to ask.

zhuangfengzi commented 3 years ago

@Owennew o, thank you!

Tle5012b was originally a three line SPI, but it was changed to a 4-line SPI, but the SPI can work. It is only an official library, but I don't know how to transplant the official library into simple FOC, or after integration,

This can happen:

MagneticSensorSPIConfig s AS5147 SPI = {

.spi mode = SPI MODE1,

.clock_ speed = 1000000,

.bit_ resolution = 14,

.angle_ register = 0xCFFF,

.data start bit = 13,

.command Rw bit = 14,

.command parity bit = 15

}

/* Typical configuration for the 14bit MonolithicPower MA730 magnetic sensor over SPI interface /

MagneticSensorSPIConfig s MA730 SPI = {

.spi mode = SPI MODE0,

.clock_ speed = 1000000,

.bit_ resolution = 14,

.angle_ register = 0x0000,

.data start bit = 15,

.command Rw bit = 0, // not required

.command parity bit = 0 // parity not implemented

}

MagneticSensorSPIConfig s Tle5012b SPI = {

.spi mode = SPI MODE0,

.clock_ speed = 1000000,

.bit_ resolution = 15,

.angle_ register = 0x7FFF,///???????????

.data start bit = 15,

.command Rw bit = 0, // not required

.command parity bit = 0 // parity not implemented

}

.........

You can also use the code magneticsensorspi sensor = magneticsensorspi (16, 14, 0x3fff); I'm a novice, so it's hard!

zhuangfengzi commented 3 years ago

@owennewo There is this column in the official document. I am looking at it. I will help you to see it under the guidance! https://docs.simplefoc.com/sensor_support

owennewo commented 3 years ago

Is there any reason why you want to use this particular sensor? It is expensive (£35) and currently not supported. You'll need to rewrite most of the class, I can't write this for you as I don't have the sensor. Can you code c/c++? How determined are you to complete this?

zhuangfengzi commented 3 years ago

It's half cheaper than as5047p as5147p, so use this test! If there is no way, only change the encoder! My C + + is very bad, just a fan! @Owennew o, thank you very much!

runger1101001 commented 3 years ago

Dear @zhuangfengzi ,

I have some TLE5012 on my desk and will try to get them supported in SimpleFOC soon. Some other users have recently done some work on this as well (https://github.com/xerootg/btt-s42b-simplefoc/blob/master/src/TLE5012b.cpp), but it is hardware specific code.

You are right that the chip is less expensive most of the others, just the evaluation boards are more expensive :-) For this reason alone I think it is interesting to support it.

runger1101001 commented 2 years ago

There is support for the TLE5012B for STM32 now: https://github.com/simplefoc/Arduino-FOC-drivers/tree/master/src/encoders/tle5012b

And there is a new GenericSensor class: https://docs.simplefoc.com/generic_sensor with which you should be able to integrate the official library and just use Tle5012MagneticAngleSensor.getAngleValue(d); on the hardware platforms it supports.

runger1101001 commented 1 year ago

Since we now support the TLE5012B, at least on STM32 MCUs, I am going to close this ticket. Please feel free to re-open it or create a new one if the solution we have isn't meeting your needs.