rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
as5600.h
Go to the documentation of this file.
1
88
89#pragma once
90
91#include <stdbool.h>
92#include <stdint.h>
93
94#include "sense_bus.h"
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
100#define AS5600_ADDR 0x36u
101#define AS5600_REG_STATUS 0x0Bu
102#define AS5600_REG_RAW_ANGLE 0x0Cu
103#define AS5600_REG_ANGLE 0x0Eu
104#define AS5600_REG_AGC 0x1Au
105#define AS5600_REG_MAGNITUDE 0x1Bu
106
107#define AS5600_STATUS_MH 0x08u
108#define AS5600_STATUS_ML 0x10u
109#define AS5600_STATUS_MD 0x20u
111#define AS5600_STATUS_MASK (AS5600_STATUS_MH | AS5600_STATUS_ML | AS5600_STATUS_MD)
112
114#define AS5600_COUNTS 4096u
116#define AS5600_CDEG_TURN 36000
117
127uint16_t as5600_u12(const uint8_t *b);
128
137bool as5600_status_possible(uint8_t status);
138
147bool as5600_md(uint8_t status);
154bool as5600_ml(uint8_t status);
161bool as5600_mh(uint8_t status);
162
173int16_t as5600_delta(uint16_t a, uint16_t b);
174
185int32_t as5600_cdeg(int32_t counts);
186
187/* -------------------------------------------------------------- driver */
188
189typedef struct {
190 sense_part_t part;
191} as5600_t;
192
199void as5600_init(as5600_t *d, sense_bus_t *bus);
200
211bool as5600_step(as5600_t *d, uint32_t now_ms);
212
220
230sense_err_t as5600_read_status(as5600_t *d, uint8_t *status);
231
239sense_err_t as5600_read_raw(as5600_t *d, uint16_t *raw);
240
248sense_err_t as5600_read_agc(as5600_t *d, uint8_t *agc);
249
257sense_err_t as5600_read_mag(as5600_t *d, uint16_t *magnitude);
258
269sense_err_t as5600_read_angle(as5600_t *d, uint8_t *status, uint16_t *raw);
270
280 uint16_t *magnitude);
281
282#ifdef __cplusplus
283}
284#endif
bool as5600_status_possible(uint8_t status)
Whether status is one an AS5600 can give: not ML and MH together.
Definition as5600.c:17
bool as5600_ml(uint8_t status)
Read the ML bit of a STATUS value.
Definition as5600.c:28
sense_err_t as5600_read_agc(as5600_t *d, uint8_t *agc)
AGC: 1 byte from 0x1A; the same rule.
Definition as5600.c:121
uint16_t as5600_u12(const uint8_t *b)
A 12-bit register pair, most significant byte first: RAW ANGLE, ANGLE or MAGNITUDE.
Definition as5600.c:12
bool as5600_md(uint8_t status)
The magnet bits of status.
Definition as5600.c:23
sense_state_t as5600_state(const as5600_t *d)
The part's state as of the last probe.
Definition as5600.c:94
void as5600_init(as5600_t *d, sense_bus_t *bus)
A part on bus at AS5600_ADDR, not yet probed.
Definition as5600.c:62
sense_err_t as5600_read_status(as5600_t *d, uint8_t *status)
STATUS: 1 byte from 0x0B.
Definition as5600.c:99
int16_t as5600_delta(uint16_t a, uint16_t b)
a minus b on the circle, -2048 to 2047 counts: the shortest way from b to a.
Definition as5600.c:38
sense_err_t as5600_read_angle(as5600_t *d, uint8_t *status, uint16_t *raw)
STATUS, then RAW ANGLE: two transactions.
Definition as5600.c:143
bool as5600_mh(uint8_t status)
Read the MH bit of a STATUS value.
Definition as5600.c:33
sense_err_t as5600_read_raw(as5600_t *d, uint16_t *raw)
RAW ANGLE: 2 bytes from 0x0C, 0 to 4095; the same rule.
Definition as5600.c:110
int32_t as5600_cdeg(int32_t counts)
counts in hundredths of a degree, rounded to the nearest, halves away from zero.
Definition as5600.c:46
bool as5600_step(as5600_t *d, uint32_t now_ms)
Every tick: probes the part when it is due – at the first call, and SENSE_RETRY_MS after it was found...
Definition as5600.c:86
sense_err_t as5600_read_mag(as5600_t *d, uint16_t *magnitude)
MAGNITUDE: 2 bytes from 0x1B, 0 to 4095; the same rule.
Definition as5600.c:132
sense_err_t as5600_read_magnitude(as5600_t *d, uint8_t *agc, uint16_t *magnitude)
AGC, then MAGNITUDE: two transactions; the same rule.
Definition as5600.c:158
The sensor bus: one I2C (Inter-Integrated Circuit) bus with current monitors on it,...
sense_err_t
What a transaction came to.
Definition sense_bus.h:62
sense_state_t
A part on the bus, as far as it is known.
Definition sense_bus.h:175
Definition as5600.h:189
Definition sense_bus.h:91
A part on the bus: its address, state and last probe.
Definition sense_bus.h:190