18#define I2C_FREQ 100000
21#define RAW_ANG_HIGH 0x0C
22#define RAW_ANG_LOW 0x0D
23#define STATUS_REG 0x0B
25#define MAGNITUDE_HIGH 0x1B
26#define MAGNITUDE_LOW 0x1C
64 float delta_raw_pos = 0;
71 if ((status_val & 0x20) && !(status_val & 0x10)
72 && !(status_val & 0x08)) {
74 raw_pos = (float) raw_angle * 0.0879;
77 if (delta_raw_pos > 180)
79 else if (delta_raw_pos < -180)
85 *new_pos = (double)real_pos;
132 uint8_t status_val =
get_pos(¤t_pos);
164 Wire.beginTransmission(i2c_address);
165 Wire.write(i2c_register);
166 Wire.endTransmission();
167 Wire.requestFrom(i2c_address, (uint8_t) 1);
168 while (Wire.available() == 0)
176 return ((word_high << 8) | word_low);
Class that functions for interacting with AS5601 magnetic rotary position sensor.
uint16_t i2c_word_transaction(uint8_t i2c_address, uint8_t i2c_register)
void Begin()
Initialize the I2C bus.
uint16_t get_magnitude()
Get the magnitude value of the internal CORDIC output.
void init_zero()
Reset zero position set the offset to zero.
uint8_t get_pos(double *new_pos)
Calculate an unwrap the position.
uint16_t get_conf()
Get the configuration register.
uint8_t get_agc()
Calculate the automatic gain control (AGC)
void set_gear_ratio(uint8_t enc_ratio)
Set the gear ratio between encoder and measure axis.
uint8_t set_zero()
Set zero by setting offset angle.
uint8_t i2c_byte_transaction(uint8_t i2c_address, uint8_t i2c_register)