Angle sensor SPI support / SC60228DC

Thanks.

There were indeed some bit issues. Now I have velocity control working as well. However it seems that the sensor is slower than the AS5147. (Unless something else that I don’t get is going on).

Roughly speaking I was able to achieve 25 rad/s with standard settings using the AS5147.
50 pole stepper. With the SC60228DC only 12 rad/s.

A quick fix is however to advance the electric angle artificially. I think I have seen it mentioned before somewhere, but couldn’t find it? Like so:

image

I wonder it would make sense to make that a setting? Perhaps even a “time-delay” constant could be added to the sensor.

With the increased advance I’m able to reach the 25 rad/s without too much tweaking yet.

I think @Antun has to comment on that, but personally I don’t like this solution, since it seems a bit heuristic, and much prefer your suggestion of handling it in the sensor, since it is the sensor latency that we are assuming causes this.

It’s interesting that it is slower than the AS5047 - which requires reading 32 bits for a current angle value as opposed to 16 bits of the SC60228… that really indicates that the lag is in the sensor IC itself.

For getting even more speed, have you tried using the ABI mode of the AS5047? this should eliminate the latency of the SPI requests completely, leaving only the sensor’s own latency… There’s a driver for the STM32 hardware encoder in the drivers repo, which uses the encoder peripheral of the STM32s and doesn’t need interrupts.

25rad/sec is only 238rpm. I know that AS5047 is rated at 28000 rpm, so there is something going on with your setup to max it out at more than 100 times lower RPM. Chinese lie a lot but not that much.

Didn’t work in my case. Not sure what’s the problem, don’t have time to debug, later. It’s definitely the sensor because it works flawlessly with the AS5047P, then when I swap the sensor, it bumps and grinds and makes funny noises, then doesn’t move. This is how I call it if it helps. I’m posting only the relevant portions. Perhaps I’m making a mistake somewhere.

#include <SimpleFOCDrivers.h>
#include "encoders/sc60228/MagneticSensorSC60228.h"

// SENSOR SPI SC60228
// SPI2 PINS
#define CSN2 PB12
#define CLK2 PB13
#define MISO2 PB14
#define MOSI2 PB15

MagneticSensorSC60228 sensorSC60228(CSN2);

SPIClass SPISensor(MOSI2, MISO2, CLK2);

// Inside setup {
sensorSC60228.init(&SPISensor);
// }

I tried velocity and angle.

This exact same code works fine with the generic sensor code and AS5047P (except the constructor of course).

As I said, perhaps I’m making a stupid mistake somewhere, but don’t have time to debug now. If you see something strange with my code, like last time with the wrong PWM pin, please let me know.

Cheers,
Valentine

Edit: Also, I can read the angle if I run the debug branch code standalone, so the sensor alone works, but when I integrate with the closed loop, that’s where it breaks.

Looks great, I would like to see an encoder with a hollow shaft with the possibility of cable passage, slip ring etc. Do you have any tips or has anyone created something similar? I am interested in buying for my project.

I made a bit of progress with my setup. The comparatively poor performance I was seeing with the SC60228DC was most likely related to a poor electric angle offset calibration that had moved since I installed the stepper motors in their housing. I made second sample of my board and are now at 4/4 working perfectly fine. I will do a small secondary post/thread about the system performance.

1 Like

hmmm… in my case the PID tunings were significantly different for this sensor than an AS5048A. I tested with a SAMD21 based board, it has about 3.3kHz loop iteration speed with motion downsample of 4 in velocity mode - all these things affect the tuning - I had to lower the output_ramp to 200.0 and increase the velocity Tf to 0.05. After a bit of playing around the motor was rotating quite smoothly.

Entirely possible, because I kept everything else and only swapped the sensor. The angle is clearly being read correctly, I don’t believe the sensor code is having a problem, but the setup is too expensive to use it to fine tune the PID for a $2 sensor. When I get the time I’ll test on a cheap motor. Thank you for the advise.

I’ve got an SC60228 that seems to be set to 2048 PPR, not 4096. I’m guessing I got the wrong model (although the markings are clearly 60228), or if there’s some register I need to set to get the full resolution.

To my knowledge this sensor doesn’t allow register access.

In that case, what gives? Maybe there’s a bug in the decoding, or something’s slightly off about the SPI config. I could solder leads on for my logic probes and do some pulseview digging, but I really have other things I’d rather do :confused:

I’ve submitted a PR that adds a cpr parameter to the sc60228 driver so my apparently 11 bit secret variant will work. Added CPR configuration option to SC60228 Encoder by josephduchesne · Pull Request #15 · simplefoc/Arduino-FOC-drivers · GitHub

I am from MagnTek. You can consult me directly for samples and technical questions. may email address is: weijun.mao@magntek.com.cn.
6835 is the latest magnet encoder we released, which can meet the needs for serve motor and step motor. We have some application notes to help yout to get a decent accuracy.

Hi @Roger_Mao , we are honored to have you here on SimpleFOC!

Several of our users (including myself) have been working with your sensors, and we have written some drivers for Arduino for them too:
https://github.com/simplefoc/Arduino-FOC-drivers/tree/master/src/encoders/mt6701
https://github.com/simplefoc/Arduino-FOC-drivers/tree/master/src/encoders/mt6816

I look forward to trying your MT6835 sensor, although the calibration procedure looks a bit scary :slight_smile:

One question that has been raised for the MT6801, and is not clear from the Datasheet: does the ABZ interface need pull-up resistors?

Thank you and best regards!

Mr. Mao Weijun:

Thank you very much for reaching out to us. We are interested in your sensors. It will be very educational and productive if we know more about them. We will contact you directly about details.

Respectfully,
Valentine

Mr. Mao Weijun:

Thank you very much. We are looking for sample schematics and recommended PCB layout for the sensors. The current documentation does not have any hardware recommendations. Please help us out.

Respectfully,
Valentine

No. The ABZ output of MT6801 is push and pull, no pull-up resistor is needed. But altually I will not encourage you to use MT6801 as it is the ifrst generation and we have decided to phase out. Mt6701 will be a good replacement for it.

1 Like

Is anyone using the Sc60228 sensor?
Mcu Stm32G431 - Arduino 1.8.9 -Dev Branch (downloaded today)
Magnet checked working with tle5012.

Sensor angle is 6.28 for 180°. changing CPR did not work, because the angle value always jumps to zero after 3.14.

to test I have uncommented this in sc60228.cpp

Serial.print(result.angle, DEC); // was HEX

resulting in 4096 for every 180°

can anyone confirm this?

Btw the link to the english datasheet doesnt work anymore. maybe someone saved it?

hm, it was fine when I tried it, and Runger reported it appeared to work ok. So if you graph it with serial monitor, what does it look like?

Hi @2hry! Yes, it is working fine for me.

Please try changing the SPI mode. Please try with SPI Mode 0, and see if this helps. You can also try lowering the SPI speed.

SPISettings mySC60228SPISettings(1000000, SC60228_BITORDER, SPI_MODE0); 

MagneticSensorSC60228 sensor = MagneticSensorSC60228(PIN_SPI_SS, mySC60228SPISettings);

@runger
thanks.
I Ieft the speed at 8000000, and changing to SPI_MODE0 results in angle 6.28 for 360°.
Its working now

@Anthony_Douglas on the serial monitor it looked normal, just the angle was counting double as it should be (12.56 for 360°, but should be 6.28)

2 Likes