MA730 SPI data jump from 3.14 to 0

Hi guys~ I am testing my new made magnet sensor board, which based on MA730. it works now through SPI port, but the angle data always jump from 3.14 to 0, just one cycle range.
Is there any other set up that i missed in the code? i use the example in lib.
by the way, my controller uses esp32.

#include <SimpleFOC.h>

MagneticSensorSPI sensor1 = MagneticSensorSPI(MA730_SPI, 17);
MagneticSensorSPI sensor2 = MagneticSensorSPI(MA730_SPI, 5);

void setup() {
  // monitoring port

  // initialise magnetic sensor hardware

  Serial.println("Sensor ready");

void loop() {
  // display the angle and the angular velocity to the terminal

Hi @zdldcyy,

A late reply, but did you find a solution yet to your problem?

I have not worked with the MA730. The only thing I can think of is checking your magnet for the right allignment and polarisation.

This seems like a latching issue. Crossing the 0 when the magnet rotates very slowly, a very small rotation error may push it back just enough to skip to 3.14 for a single reading. Does that happen when the magnet rotates faster?

Hi V:
it happens all the time, no matter fast or slow. Now Im checking my hardware design, seems that my spi cable is too long and cannot avoid the disturbence.

are you saying this happens on your setup only when using long cable, but no problem with a short one?

i have to use long cable, so i didnt try short cables. but i’ll try it when free, thank you for reminding~

I have the same problem, it is not the matter of cable, I assembled the MA730 in the board has the same problem, I think it is caused by the resolution of MA730, it only be compensated by firmware. This problem must occurs at the position near 16383 to 0 or 0 to 16383.

There may be some weirdness or bug in this function:

The MA730 is a 14 bit sensor hence cpr = 2^14 = 16384

Line 105 is looking for ‘big jumps’ in the raw count that are associated with going from close to zero to close to 16384 (or vice versus).

if your last raw reading (angle_data_prev) was 16000 and your new raw reading (angle_data) was 320 then the difference (d_angle) will be -15680. This big jump should be detected and the full rotation_offset should be changed by ± 2PI.
In my example the abs(d_angle) is greater than 0.8 * 16384 (=13107) then full_rotation_offset should be incremented by 2PI (as delta is negative).

If you put some debugging/print statements here you’ll probably find out what is going on. I suspect (for some reason) d_angle is never going above 0.8*cpr.

The code should has no problem I think. It was caused in this situation, the motor was stopped, the angle_data_prev is 16380 and angle_data is 16382, then second call to getAngle(), angle_data_prev is 16382, angle_data is 2, then third call to getAngle(), angle_data_prev is 2, angle_data is 6, then forth call to getAngle(), angle_data_prev is 6, angle_data is 16383, the error will occur in this situation. Because I found the last 4 bits for MA730 angle value was always changing when in motionless state.