Skip to content

Misreads #5

@arpruss

Description

@arpruss

This is a great library, but I'm having trouble with some misreads. I rotate the magnet (it's set in a skate bearing, so I can do it smoothly) clockwise and read getAngle(), and normally the data is increasing, but every so often I get one piece of data that seems to be behind.

My current workaround is to read three angles in sequence, and then return one of the pair that are closest together, but that's really kludgy (plus a slowdown).

I am using 4.7K pull-up resistors on SDA and SCL, and using a 3.3v board (stm32f103c8t6 blue pill clone).

Would you have any suggestions?

Here's my filtering code, which pretty much solves the problem, but introduces some latency.

        unsigned int distance(unsigned a, unsigned b) {
          int delta = a-b;
          if (delta & 0x800) {
            delta |= ~0xFFF;
          }
          if (delta < 0)
            return -delta;
          else
            return delta;
        }

        unsigned int getAngleFiltered()
        {            
            unsigned int angle1 = this->readRaw16( AS5601::WordRegister::ANGLE );
            unsigned int angle2 = this->readRaw16( AS5601::WordRegister::ANGLE );
            unsigned int angle3 = this->readRaw16( AS5601::WordRegister::ANGLE );
            unsigned d12 = distance(angle1,angle2);
            unsigned d23 = distance(angle2,angle3);
            unsigned d13 = distance(angle1,angle3);
            if (d13 < d12)
              return angle3;
            if (d12 < d23)
              return angle2;
            return angle3;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions