Seeed_Arduino_AS5600 icon indicating copy to clipboard operation
Seeed_Arduino_AS5600 copied to clipboard

Wrong angle returned / conversation factor wrong

Open Neumi opened this issue 3 years ago • 2 comments

A wrong angle is returned in the examples: examples/fullFunction/fullFunction.ino examples/readAngle/readAngle.ino

The conversion factor is unprecise and should be 0.087890625 instead of 0.087 / 0.0878. This becomes a problem when precise angle measurements are important.

Neumi avatar Sep 16 '22 16:09 Neumi

I wonder if it useful to write this as (angle * 360) / 4096 instead of a fixed numeric constant? That way a reader can see how it is calculated, as well as always using the best floating point precision available on that particular CPU?

I've added this as a standard function in my version of the library:

/*******************************************************
  Method: getDegrees
  In:  none
  Out: value of raw angle register 0..359 degrees
  Description: gets raw value of magnet position, then
  converts to degrees.
  start, end/max angle settings do not apply.
*******************************************************/
float AMS_5600::getDegrees()
{
  return (getRawAngle() * 360.0) / 4096.0;
}

sheffieldnikki avatar Sep 17 '22 15:09 sheffieldnikki

I agree with sheffieldnick. The calculation method does make it more obvious how the conversion is made and provides the maximum precision available.

steve-arnold avatar Sep 18 '22 08:09 steve-arnold