Magnetic sensor value jumps

hello everyone
i’m using AS5045 magnetic sensor which has only got pwm to communicate(No SPI). i used the example in the library “find_raw_min_max” in utils->sensor tes-> magnetic->pwm and started finding min and max

as i usually get 16-4008, i also get all these combinations: (12 & 16) for min & (4004 or 4008 or 40012 or 4016 or 4020) for max
and with any of these numbers in combination, i still have jumps in y raw readings. jumps are about (0-8) which leads to a change in 0.01 place of angle!
the foc library for controlling motor is working fine(there may be some inefficiencies due to these jumps) and i don’t have problems in running motor itself
but rather i’m using motor speed in my control loop and it causes major problem there!
because of those jumps in my raw readings, i get a large velocities like 6 rad/s!
is there anything i can do?
here are some pics of the datas:

here the motor is stationary.

the source code suggests that you play with the values 4 and 904. That could move the sampling points to areas with less jitter.

An example to find out the raw max and min count to be provided to the constructor
SPin your motor/sensor/magnet to see what is the maximum output of the sensor and what is the minimum value
And replace values 4 and 904 with new values. Once when you replace them make sure there is no jump in the angle reading sensor.getAngle().
If there is a jump that means you can still find better values.

MagneticSensorPWM sensor = MagneticSensorPWM(2, 4, 904);

“and with any of these numbers in combination, i still have jumps in y raw readings.”

What microcontroller are you using?

The PWM communication is the worst one supported by the library. We only support around 1000 impulses per revolution. And that is realy not much.
Please consider using some other type of communication, the PWM is there only in extrema cases, when you really have no other choice :smiley:

Regarding the jumps in your serial output, they are caused by the resolution, not by min and max values. You will not be able to do too much there. You can increase the velocity low pas filtering time constant to get the smoother values but, I would not expect very precise control with the PWM.
You really cannot use the SPI?

arduino nano
i don’t have any other choice right now.
can you provide a link regarding to velocity low pass filtering time constant?
as i said the motor control is fine by me. my problem is the values that have jumps which i’m using them in control loop.

i’m afraid the AS5045 doesn’t come with that! :frowning:

Hey ,

I’ve just committed a driver for the AS5145 in SSI mode. You can find it here:

The same code should work for the AS5045 as well.
To use it, you could just copy the 2 files (.cpp and .h) to your own project for now.

It isn’t tested much, I was using a STM32G491 when testing it.
You could try it out if you want. If it works reliably (and I must stress I haven’t tested it much, just verified that it outputs 0-2PI as you turn the motor a full turn) it should have better performance than using the PWM output.


will check it out