Issue with AS5048A magnetic sensor

I’m using the AS5048A magnetic sensor in SPI mode with a SimpleFOCShield on Nucleo-64.

The angle value I get with magnetic_sensor_spi_example (I removed the velocity measurement) is continuously oscillating, but not random.

If I set the motor at a certain angle (let’s call it “pointing right”) and start the program, I always get this:
image

If I turn 90° CW, nothing changes:
image

But if I continue turning, as I approach the “pointing left” position, the amplitude increases:
image

And then, at the exact “pointing left” position, the value stabilizes at about 6 rad (not 38, see below):
image

The stabilized value is difficult to get, it needs precise tuning of the angle. But each time you miss the required precise angle, the value is offsetted by about PI rad (hence the above screenshot, at 38 rad, after a few trials).

If you continue turning the motor, between “point left” and “point top left”, there are several of those “stabilized” angles. Each time you cross them, the value is offsetted by about PI rad.

If you continue turning after “point top left”, you come back to the original behavior, but with the accumulated offset:
image

Any clue?

I did some more tests and discovered that the issue only occurs when going through my SimpleFOCShield! If I remove the shield and plug the sensor directly on the Nucleo-L476RG, it works like a charm. I’m a bit puzzled. How can the shield interfere?

I solved my problem by replacing:

MagneticSensorSPI sensor(10, 14, 0x3FFF);

by:

MagneticSensorAS5048A sensor(10);

(after installing the Ardunio-FOC-drivers library, thanks @runger)

However, the fact that the SimpleFOCShield somehow pollutes the SPI signal is above me. Any idea @Antun_Skuric?

Hey @quentin,

I have no idea how would shield interfere :smiley:
It might somehow introduce some ground plane noise or something like that, but I have never had any such issues sofar.

However, what might be an issue is the pinout you have chosen for your shield. Make sure that you do not use and of the SPI pins for the PWM.
So avoid using pins 13 and 11. And maybe dont use the chip select pin at pin 10, but if you can put it somewhere esle so you can use pin 10 with your shield for pwm.

Now I have not really understood your problem with the sensor, were you able to have any values out of it or just the noise?

I’m happy that you’ve found a solution that works for you, but the library should be able to work without any problems with the AS5048A. It was one of the first sensors that has been supported by the simplefoc library. So and as far as I know, many people has used it with the library out of the box. But every mcu is a bit different and every sensor as well, so if there is one thing we have learned with simplefoc is that you never know with hardware :smiley:

My current results are:

  • Both MagneticSensorSPI(10, 14, 0x3FFF) and MagneticSensorAS5048A(10) work correctly without the shield.
  • MagneticSensorAS5048A(10) also works correctly with the shield.
  • MagneticSensorSPI(10, 14, 0x3FFF) doesn’t work with the shield: I get a strange and noisy angle signal (see my first post).

I will now check my pinout and try to change my CS pin.

That’s very interesting. I have no idea what that could be, but I’d be really interested to get to the bottom of this.

We did have some issues with clock signals of the spi for the stm32, this should be resolved in the dev branch. @runger has rewritten the spi sensor implementation.

In your photos from before, you say that you move the motor 90 degrees but you always have the agle of 3 rad, just more or less noise?
Is this the behavior you’ve got?
Or your angle is read well, just you have a lot of noise and that is the issue?

From 0 to PI/2, no change in signal (“short” noise). From PI/2 to 3PI/2, the angle doesn’t seem to change but the noise gets taller. From 3PI/2 to 2PI, very strange behavior with stabilization at specific angles (with no noise) and sudden and permanent offset of PI rad.

I have some more disturbing news, see below.

I did some more tests and entered voodoo territory.

The issue probably involves a faulty connector. Here is my connector, done manually with a cheap Chinese toolset:

This works like a charm (direct connection between the sensor and the Nucleo board):

With the SimpleFOCShield, it works correctly with MagneticSensorAS5048A but not with MagneticSensorSPI:

Now for the strangest part. If using a breadboard instead of directly plugin the connector to the shield, it works with both MagneticSensorAS5048A and MagneticSensorSPI:

Hey @quentin,

I was having similar issues with my velocity readings! Did this fix you found end up smoothing our the results?

@ DGAQ, I indeed experienced an issue with velocity, but I don’t think it’s related to the sensor, so here is a new thread to discuss it if needed.

I’ve just done some more tests and haven’t witnessed the strange behavior from last month.

All I see now is that my AS5048A:

  • works correctly with MagneticSensorAS5048A(10)
  • doesn’t work at all with MagneticSensorSPI(10, 14, 0x3FFF) (hangs in SPI communication)

Hi, just like to join the club with this issue. I’ve tried a lot of different things. With/without logic level shifter / with SPI1/SPI2/SPI3 and still getting issues. I will give the above flavors a go, it seems to be totally random though :expressionless:

If I hook it up to my arduino it seems to work flawlessly. Strange thing is, I’ve had this sensor working before without issue.

My F446RE Code (and same datasheet figures):
afbeelding



Hi @marethyu,
Did you try the magnetic_sensor_spi_example?
What data do you get from the sensor?

That works, my own script too. But once I start using it in combination with Loopfoc/move commands, I start getting spikes in my sensor reading.

Edit: initially I had almost exactly the same output as yours, but that was with a logic level shifter in between, corrupting the spi signal. Now I’m attempting a direct connection to 5V tolerant pins.

Hey @marethyu,

I was not able to get good readings with my AS5047 spi sensor using the 5v logic with the stm32 boards. I had to use 3.3V logic.
The breakout that I have has a small soldering connection to switch in between logic levels, you don’t have one?
I am not sure what is the best way to solve this issue except for using the same logic level as the board.

Hi Antun,

I have the AS5048A btw; I see the type is ‘wrong’ in my screenshot.

I’m not sure what breakout you mean? I did use two variants of logic level shifters that were not OK in terms of speed. I’m picking up two different types tomorrow (I hope they work).

I’ll update this post if I found a solution.

The thing that I cannot comprehend is that I only seem to get it if my motor is actually moving. If I move the encoder by hand and read the sensor I never see a spike.

Edit: reading another post about this issue you refer to the breakout of the sensor. Unfortunately the one I have does not have an easy accessible soldering bridge.