11//
22// FILE: AS56000.cpp
33// AUTHOR: Rob Tillaart
4- // VERSION: 0.6.2
4+ // VERSION: 0.6.3
55// PURPOSE: Arduino library for AS5600 magnetic rotation meter
66// DATE: 2022-05-28
77// URL: https://github.com/RobTillaart/AS5600
@@ -428,6 +428,7 @@ bool AS5600::magnetTooWeak()
428428
429429float AS5600::getAngularSpeed (uint8_t mode)
430430{
431+ // default behaviour
431432 uint32_t now = micros ();
432433 int angle = readAngle ();
433434 uint32_t deltaT = now - _lastMeasurement;
@@ -436,9 +437,9 @@ float AS5600::getAngularSpeed(uint8_t mode)
436437 // assumption is that there is no more than 180° rotation
437438 // between two consecutive measurements.
438439 // => at least two measurements per rotation (preferred 4).
439- if (deltaA > 2048 ) deltaA -= 4096 ;
440- if (deltaA < -2048 ) deltaA += 4096 ;
441- float speed = (deltaA * 1e6 ) / deltaT;
440+ if (deltaA > 2048 ) deltaA -= 4096 ;
441+ else if (deltaA < -2048 ) deltaA += 4096 ;
442+ float speed = (deltaA * 1e6 ) / deltaT;
442443
443444 // remember last time & angle
444445 _lastMeasurement = now;
@@ -465,7 +466,10 @@ float AS5600::getAngularSpeed(uint8_t mode)
465466int32_t AS5600::getCumulativePosition ()
466467{
467468 int16_t value = readAngle ();
468- if (_error != AS5600_OK) return _position;
469+ if (_error != AS5600_OK)
470+ {
471+ return _position;
472+ }
469473
470474 // whole rotation CW?
471475 // less than half a circle
@@ -479,7 +483,10 @@ int32_t AS5600::getCumulativePosition()
479483 {
480484 _position = _position - 4096 - _lastPosition + value;
481485 }
482- else _position = _position - _lastPosition + value;
486+ else
487+ {
488+ _position = _position - _lastPosition + value;
489+ }
483490 _lastPosition = value;
484491
485492 return _position;
@@ -504,7 +511,7 @@ int32_t AS5600::resetPosition(int32_t position)
504511
505512int32_t AS5600::resetCumulativePosition (int32_t position)
506513{
507- _lastPosition = readReg2 (AS5600_RAW_ANGLE) & 0x0FFF ;
514+ _lastPosition = readAngle () ;
508515 int32_t old = _position;
509516 _position = position;
510517 return old;
0 commit comments