Skip to content

Commit

Permalink
Fix #65, getCumulativePosition() + some more
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Oct 4, 2024
1 parent 20b40c1 commit 5e1c243
Show file tree
Hide file tree
Showing 10 changed files with 598 additions and 61 deletions.
21 changes: 11 additions & 10 deletions AS5600.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: AS56000.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.6.1
// VERSION: 0.6.2
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand Down Expand Up @@ -303,8 +303,9 @@ uint8_t AS5600::getWatchDog()
//
uint16_t AS5600::rawAngle()
{
int16_t value = readReg2(AS5600_RAW_ANGLE) & 0x0FFF;
if (_offset > 0) value = (value + _offset) & 0x0FFF;
int16_t value = readReg2(AS5600_RAW_ANGLE);
if (_offset > 0) value += _offset;
value &= 0x0FFF;

if ((_directionPin == AS5600_SW_DIRECTION_PIN) &&
(_direction == AS5600_COUNTERCLOCK_WISE))
Expand All @@ -317,8 +318,9 @@ uint16_t AS5600::rawAngle()

uint16_t AS5600::readAngle()
{
uint16_t value = readReg2(AS5600_ANGLE) & 0x0FFF;
if (_offset > 0) value = (value + _offset) & 0x0FFF;
uint16_t value = readReg2(AS5600_ANGLE);
if (_offset > 0) value += _offset;
value &= 0x0FFF;

if ((_directionPin == AS5600_SW_DIRECTION_PIN) &&
(_direction == AS5600_COUNTERCLOCK_WISE))
Expand All @@ -337,8 +339,8 @@ bool AS5600::setOffset(float degrees)
if (neg) degrees = -degrees;

uint16_t offset = round(degrees * AS5600_DEGREES_TO_RAW);
offset &= 4095;
if (neg) offset = 4096 - offset;
offset &= 0x0FFF;
if (neg) offset = (4096 - offset) & 0x0FFF;
_offset = offset;
return true;
}
Expand Down Expand Up @@ -462,7 +464,7 @@ float AS5600::getAngularSpeed(uint8_t mode)
//
int32_t AS5600::getCumulativePosition()
{
int16_t value = readReg2(AS5600_ANGLE) & 0x0FFF;
int16_t value = readAngle();
if (_error != AS5600_OK) return _position;

// whole rotation CW?
Expand All @@ -487,9 +489,8 @@ int32_t AS5600::getCumulativePosition()
int32_t AS5600::getRevolutions()
{
int32_t p = _position >> 12; // divide by 4096
if (p < 0) p++; // correct negative values, See #65
return p;
// if (p < 0) p++;
// return p;
}


Expand Down
4 changes: 2 additions & 2 deletions AS5600.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AS5600.h
// AUTHOR: Rob Tillaart
// VERSION: 0.6.1
// VERSION: 0.6.2
// PURPOSE: Arduino library for AS5600 magnetic rotation meter
// DATE: 2022-05-28
// URL: https://github.com/RobTillaart/AS5600
Expand All @@ -12,7 +12,7 @@
#include "Wire.h"


#define AS5600_LIB_VERSION (F("0.6.1"))
#define AS5600_LIB_VERSION (F("0.6.2"))


// default addresses
Expand Down
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.6.2] - 2024-10-04
- Fix #65, make **getCumulativePosition()** direction aware.
- optimize **readAngle()** and **rawAngle()**
- fix negative values in **getRevolutions()**
- fix **setOffset()** to not set offset to 360.
- add unit test for offset -0.01 and 360.0 (both should become 0.0).
- add **AS5600_output_speedtest.ino**, thanks to Pollyscracker
- update readme.md


## [0.6.1] - 2024-03-31
- improve **getCumulativePosition()**, catch I2C error, see #62
- update readme.md (incl reorder future work).
- update GitHub actions
- minor edits


## [0.6.0] - 2024-01-25
- add experimental error handling
- add **int lastError()** so user can check the status of last I2C actions.
Expand Down
Loading

0 comments on commit 5e1c243

Please sign in to comment.