API Reference
as5600
CircuitPython helper library for the AMS AS5600 12-bit on-axis magnetic rotary position sensor
Author(s): Noel Anderson
Implementation Notes
Hardware:
AS5600 <https://ams.com/as5600>
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class as5600.AS5600(i2c, address=_AS5600_DEFAULT_I2C_ADDR)
Initialize the AS5600 chip at
addressoni2c_bus.- Parameters:
i2c (I2C) – The I2C bus object.
address (int) – The I2C address of the device. Default is 0x36.
- FAST_FILTER_THRESHOLD_10LSB = 7
Fast Filter Threshold (FTH) 10 LSB
- FAST_FILTER_THRESHOLD_18LSB = 4
Fast Filter Threshold (FTH) 18 LSB
- FAST_FILTER_THRESHOLD_21LSB = 5
Fast Filter Threshold (FTH) 21 LSB
- FAST_FILTER_THRESHOLD_24LSB = 6
Fast Filter Threshold (FTH) 24 LSB
- FAST_FILTER_THRESHOLD_6LSB = 1
Fast Filter Threshold (FTH) 6 LSB
- FAST_FILTER_THRESHOLD_7LSB = 2
Fast Filter Threshold (FTH) 7 LSB
- FAST_FILTER_THRESHOLD_9LSB = 3
Fast Filter Threshold (FTH) 9 LSB
- FAST_FILTER_THRESHOLD_SLOW = 0
Fast Filter off. Slow Filter only
- HYSTERESIS_1LSB = 1
Hysteresis (HYST) 1 LSB
- HYSTERESIS_2LSB = 2
Hysteresis (HYST) 2 LSB
- HYSTERESIS_3LSB = 3
Hysteresis (HYST) 3 LSB
- HYSTERESIS_OFF = 0
Hysteresis (HYST) off
- OUTPUT_STAGE_ANALOG_FULL = 0
Output Stage (OUTS) full range analog output 0-100% GND to VDD
- OUTPUT_STAGE_ANALOG_REDUCED = 1
Output Stage (OUTS) reduced range analog output 10-90% GND to VDD
- OUTPUT_STAGE_DIGITAL_PWM = 2
Output Stage (OUTS) digital PWM output
- POWER_MODE_LPM1 = 1
Low Power (LPM1) mode - 3.4mA, Polling Time = 5mS
- POWER_MODE_LPM2 = 2
Low Power (LPM2) mode - 1.8mA, Polling Time = 20mS
- POWER_MODE_LPM3 = 3
Low Power (LPM3) mode - 1.5mA, Polling Time = 100mS
- POWER_MODE_NOM = 0
Always on (PM) mode - 6.5mA
- PWM_FREQUENCY_115HZ = 0
PWM Frequency (PWMF) 115Hz
- PWM_FREQUENCY_230HZ = 1
PWM Frequency (PWMF) 230Hz
- PWM_FREQUENCY_460HZ = 2
PWM Frequency (PWMF) 460Hz
- PWM_FREQUENCY_920HZ = 3
PWM Frequency (PWMF) 920Hz
- SLOW_FILTER_16X = 0
Slow Filter (SF) 16x
- SLOW_FILTER_2X = 3
Slow Filter (SF) 2x
- SLOW_FILTER_4X = 2
Slow Filter (SF) 4x
- SLOW_FILTER_8X = 1
Slow Filter (SF) 8x
- property angle
Get the current 12-bit angle value (ANGLE).
If zero_position() and max_position(), or max_angle() has been set then this value is scaled to those limits. Else it is scaled to 0-360 degrees, with 4095 representing 360 degrees.
- Returns:
The current angle value as an integer.
- Return type:
- burn_in_angle()
Perform a permanent writing of ZPOS and MPOS values to non-volatile memory. These are set by zero_position() and max_position().
burn_in_angle() can only be executed sucessfully up to 3 times due to device restrictions. burn_in_angle() can only be executed if is_magnet_detected = True.
zmco shows how many times ZPOS and MPOS have been permanently written.
- burn_in_settings()
Perform a permanent writing of MANG and CONFIG to non-volatile memory.
MANG is set by max_angle().
MANG can be written only if ZPOS and MPOS have never been permanently written (zmco = 0).
CONFIG contains the combination of all values set by the configuration methods.
These are watch_dog, power_mode, hysteresis, output_stage, pwm_frequency, fast_filter & slow_filter.
burn_in_settings() can be performed only one time due to device restrictions, and should be performed before burn_in_angle().
- property fast_filter: int
Get and set the Fast Filter Threshold (FTH) configuration.
Valid values: FAST_FILTER_THRESHOLD_SLOW, FAST_FILTER_THRESHOLD_6LSB, FAST_FILTER_THRESHOLD_7LSB,
- Returns:
The fast filter threshold value as an integer.
- Return type:
- property gain: int
Get the 8-bit Automatic Gain Control value (AGC).
- Returns:
The AGC value as an integer.
- Return type:
- property hysteresis: int
Get and set the Hysteresis (HYST) configuration. Set this to avoid toggling of the output when the magnet is not moving.
Valid values: HYSTERESIS_OFF, HYSTERESIS_1LSB, HYSTERESIS_2LSB & HYSTERESIS_3LSB
- Returns:
The hysteresis value as an integer.
- Return type:
- property is_magnet_detected: bool
Test MD Status Bit.
- Returns:
True if a magnet is detected, False otherwise.
- Return type:
- property is_magnet_too_strong: bool
Test MH Status Bit. True if AGC minimum gain overflow, magnet too strong
- Returns:
True if the magnet is too strong, False otherwise.
- Return type:
- property is_magnet_too_weak: bool
Test ML Status Bit. True if AGC maximum gain overflow, magnet too weak
- Returns:
True if the magnet is too weak, False otherwise.
- Return type:
- property magnitude: int
Get the 12-bit CORDIC (Coordinate Rotation Digital Computer) magnitude (MAGNITUDE).
- Returns:
The magnitude value as an integer.
- Return type:
- property max_angle: int
Get and set the maximum anglular range (MANG) in degrees.
For applications which do not use the full 0 to 360 degree angular range, the output resolution can be enhanced by programming the range which is actually used. In this case, the full resolution of the output is automatically scaled to the programmed angular range. The angular range must be greater than 18 degrees.
It can also be set by a combination of zero_position & max_position (ZPOS and MPOS).
- Returns:
The maximum angle in degrees as an integer.
- Return type:
- property max_position: int
Get and set the 12-bit maximum position (MPOS).
For applications which do not use the full 0 to 360 degree angular range, the output resolution can be enhanced by programming the range which is actually used. In this case, the full resolution of the output is automatically scaled to the programmed angular range. The angular range must be greater than 18 degrees.
Set by a combination of zero_position & max_position (ZPOS and MPOS).
It can also be set by max_angle.
- Returns:
The maximum position as an integer.
- Return type:
- property output_stage: int
Get and set the Output Stage configuration. This controls the output of pin 3 (OUT) as either an analog or PWM signal.
Valid values: OUTPUT_STAGE_ANALOG_FULL, OUTPUT_STAGE_ANALOG_REDUCED, OUTPUT_STAGE_DIGITAL_PWM
- Returns:
The output stage value as an integer.
- Return type:
- property power_mode: int
Get and set the Power Mode (PM) configuration.
Valid values: POWER_MODE_NOM, POWER_MODE_LPM1, POWER_MODE_LPM2 & POWER_MODE_LPM3
- Returns:
The power mode as an integer.
- Return type:
- property pwm_frequency: int
Get and set the PWM Frequency (PWMF) configuration. Sets the frequency of the PWM output.
Ignored if output_stage is set as Analog. Valid values: PWM_FREQUENCY_115HZ, PWM_FREQUENCY_230HZ, PWM_FREQUENCY_460HZ & PWM_FREQUENCY_920HZ
- Returns:
The PWM frequency value as an integer.
- Return type:
- property raw_angle
Get the current unscaled and unmodified 12-bit angle (RAWANGLE).
- Returns:
The current raw angle as an integer.
- Return type:
- property slow_filter: int
Get and set the Slow Filter (SF) configuration.
Valid values: SLOW_FILTER_16X, SLOW_FILTER_8X, SLOW_FILTER_4X & SLOW_FILTER_2X
- Returns:
The slow filter value as an integer.
- Return type:
- property watch_dog: bool
Get and set the Watchdog (WD) configuration. True enables the watchdog.
The watchdog configuration saves power by switching into low power mode LMP3 if the angle stays within the watchdog threshold of 4 LSB for at least one minute.
- Returns:
The watchdog value as an integer.
- Return type:
- property zero_position: int
Get and set the 12-bit zero position (ZPOS).
For applications which do not use the full 0 to 360 degree angular range, the output resolution can be enhanced by programming the range which is actually used. In this case, the full resolution of the output is automatically scaled to the programmed angular range. The angular range must be greater than 18 degrees.
Set by a combination of zero_position & max_position (ZPOS and MPOS).
It can also be set by max_angle.
- Returns:
The zero position as an integer.
- Return type: