Skip to content

Commit

Permalink
update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Oct 10, 2024
1 parent 6b83e16 commit 33d66ef
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 19 deletions.
1 change: 1 addition & 0 deletions AS5600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ uint16_t AS5600::readAngle()
if ((_directionPin == AS5600_SW_DIRECTION_PIN) &&
(_direction == AS5600_COUNTERCLOCK_WISE))
{
// mask needed for value == 0.
value = (4096 - value) & 0x0FFF;
}
_lastReadAngle = value;
Expand Down
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,35 @@ int32_t getRevolutions();
int32_t resetRevolutions(); // replaces resetPosition();
```

### Angular Speed + Cumulative position optimization.

Since 0.6.4 it is possible to optimize the performance of getting both.
- **getCumulativePosition()**
- **getAngularSpeed()**

As both use to read the Angle, one can reuse this by setting the update flag to false.
One must call **readAngle()** right before both of them
In code:

```cpp
...
alpha = as5600.readAngle();
pos = as5600.getCumulativePosition(false);
speed = as5600.getAngularSpeed(AS5600_MODE_DEGREES, false);

// process the values...
```

Please note that the **mode** parameter for getAngularSpeed() becomes mandatory.

The call to **readAngle()** caches the angle read and uses it in both functions.
The savings are substantial, see **AS5600_position_speed.ino**

The advantage is that both speed and pos are based upon the same reading.
A disadvantage is that the latter of the two calls is not max up to date.

Use with care.


### Status registers

Expand Down
55 changes: 36 additions & 19 deletions examples/AS5600_position_speed/AS5600_position_speed.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,42 @@ void setup()
Serial.print("Connect: ");
Serial.println(b);

delay(1000);

start = micros();
as5600.getCumulativePosition();
as5600.getAngularSpeed();
stop = micros();
Serial.print("update true: \t");
Serial.println(stop - start);
delay(100);

start = micros();
as5600.readAngle();
as5600.getCumulativePosition(false);
as5600.getAngularSpeed(AS5600_MODE_DEGREES, false);
stop = micros();
Serial.print("update false: \t");
Serial.println(stop - start);
Serial.println();
delay(100);
for (uint32_t speed = 100000; speed <= 800000; speed += 100000)
{
Wire.setClock(speed);
Serial.println(speed);
delay(100);

start = micros();
as5600.getCumulativePosition();
as5600.getAngularSpeed();
stop = micros();
Serial.print("update true: \t");
Serial.println(stop - start);
delay(100);

start = micros();
as5600.readAngle();
as5600.getCumulativePosition(false);
as5600.getAngularSpeed(AS5600_MODE_DEGREES, false);
stop = micros();
Serial.print("update false: \t");
Serial.println(stop - start);
Serial.println();
delay(100);
}

/*
about ~1% slower on AVR @100K
start = micros();
as5600.getCumulativePosition(true);
as5600.getAngularSpeed(AS5600_MODE_DEGREES, false);
stop = micros();
Serial.print("update false: \t");
Serial.println(stop - start);
Serial.println();
delay(100);
*/

delay(2000);
}
Expand Down
42 changes: 42 additions & 0 deletions examples/AS5600_position_speed/output_0.6.4_UNO.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

BOARD: UNO
IDE: 1.8.19
SKETCH: AS5600_position_speed.ino


AS5600_LIB_VERSION: 0.6.4
64
Connect: 1
100000
update true: 1208
update false: 640

200000
update true: 724
update false: 368

300000
update true: 552
update false: 316

400000
update true: 440
update false: 276

500000
update true: 432
update false: 224

600000
update true: 356
update false: 236

700000
update true: 372
update false: 192

800000
update true: 356
update false: 220

followed by lots of data

0 comments on commit 33d66ef

Please sign in to comment.