Documentation
¶
Index ¶
- Constants
- type AS5600Device
- func (d *AS5600Device) Configure(cfg Config) error
- func (d *AS5600Device) GetMaxAngle(units AngleUnit) (uint16, float32, error)
- func (d *AS5600Device) GetMaxPosition(units AngleUnit) (uint16, float32, error)
- func (d *AS5600Device) SetMaxAngle(mang float32, units AngleUnit) error
- func (d *AS5600Device) SetMaxPosition(mpos float32, units AngleUnit) error
- func (d *AS5600Device) WriteRegister(address uint8, value uint16) error
- type AS5601Device
- type AngleUnit
- type BURN_CMD
- type BaseDevice
- func (d *BaseDevice) Angle(units AngleUnit) (uint16, float32, error)
- func (d *BaseDevice) Burn(burnCmd BURN_CMD) error
- func (d *BaseDevice) Configure(cfg Config)
- func (d *BaseDevice) GetZeroPosition(units AngleUnit) (uint16, float32, error)
- func (d *BaseDevice) MagnetStatus() (detected bool, strength MagnetStrength, err error)
- func (d *BaseDevice) RawAngle(units AngleUnit) (uint16, float32, error)
- func (d *BaseDevice) ReadRegister(address uint8) (uint16, error)
- func (d *BaseDevice) SetZeroPosition(zpos float32, units AngleUnit) error
- func (d *BaseDevice) WriteRegister(address uint8, value uint16) error
- type Config
- type MagnetStrength
Constants ¶
const ( // NATIVE_ANGLE_MAX is the maximum valid value for a native angle for a AS560x device NATIVE_ANGLE_MAX = (1 << 12) - 1 + iota // NATIVE_ANGLE_RANGE is the number of unique values for native angles for a AS560x device NATIVE_ANGLE_RANGE )
const ( // ZMCO contains the number of times a BURN_ANGLE command has been executed (max 3 burns) ZMCO = 0x00 // ZPOS is the zero (start) position in RAW_ANGLE terms. ZPOS = 0x01 // CONF supports custom config. Raw 14-bit register. See datasheet for mapping or use 'virtual registers' below. CONF = 0x07 // STATUS indicates magnet position. Encapsulates MD, ML & MH. See also 'virtual registers' below. STATUS = 0x0b // RAW_ANGLE is the raw unscaled & unadjusted angle (12 bit: 0-4095/0xfff) RAW_ANGLE = 0x0c // ANGLE is RAW_ANGLE scaled & adjusted according to ZPOS (and MPOS/MANG on AS5600). (12 bit: 0-4095/0xfff) ANGLE = 0x0e // AGC is the Automatic Gain Control based on temp, airgap etc. 0-255 @ 5V, 0-128 @ 3.3V. AGC = 0x1a // MAGNITUDE indicates the magnitude value of the internal CORDIC output. See datasheet for more info. MAGNITUDE = 0x1b // BURN performs permanent programming of some registers. See BURN_XYZ cmd constants below for commands. BURN = 0xff )
AS560x common device registers
const ( // MPOS is the maximum position in RAW_ANGLE terms. With ZPOS, defines a 'narrower angle' for higher resolution. MPOS = 0x03 // MANG is the maximum angle. With ZPOS, defines a 'narrower angle' for higher resolution. MANG = 0x05 )
AS5600 specific registers
const ( // ABN. See datasheet for mapping ABN = 0x09 // PUSHTHR. Configures push-button function. See datasheet and AGC PUSHTHR = 0x0a )
AS5601 specific registers
const ( // WD is a Virtual Register for the Watchdog timer. See WATCHDOG_TIMER consts. WD = iota + virtualRegisterStartAddress // FTH is a Virtual Register for the Fast Filter Threshold. See FAST_FILTER_THRESHOLD consts. FTH // SF is a Virtual Register for the Slow Filter. See SLOW_FILTER_RESPONSE consts. SF // PWMF is a Virtual Register for PWM Frequency (AS5600 ONLY). See PWM_FREQUENCY consts. PWMF // OUTS is a Virtual Register for the Output Stage (AS5600 ONLY). See OUTPUT_STAGE consts. OUTS // HYST is a Virtual Register for Hysteresis. See HYSTERESIS consts. HYST // PM is a Virtual Register for the Power Mode. See POWER_MODE consts. PM // MD is a Virtual Register for the 'Magnet was detected' flag. MD // ML is a Virtual Register for the 'AGC maximum gain overflow' a.k.a 'magnet too weak' flag. ML // MH is a Virtual Register for the 'AGC minimum gain overflow' a.k.a 'magnet too strong' flag. MH )
const ( // PM_NOM is the normal 'always on' power mode. No polling, max 6.5mA current PM_NOM = iota // PM_LPM1 is Low Power Mode 1. 5ms polling, max 3.4mA current PM_LPM1 // PM_LPM2 is Low Power Mode 2. 20ms polling, max 1.8mA current PM_LPM2 // PM_LPM3 is Low Power Mode 3. 100ms polling, max 1.5mA current PM_LPM3 )
POWER_MODE values for the PM component of CONF (and the PM VR)
const ( // HYST_OFF disables any hysteresis of the output HYST_OFF = iota // HYST_1LSB enables output hysteresis using 1 LSB HYST_1LSB // HYST_2LSB enables output hysteresis using 2 LSBs HYST_2LSB // HYST_3LSB enables output hysteresis using 3 LSBs HYST_3LSB )
HYSTERESIS values for the HYST component of CONF (and the HYST VR)
const ( // OS_ANALOG_FULL_RANGE enables analog output with full range (0%-100% VDD) OS_ANALOG_FULL_RANGE = iota // OS_ANALOG_REDUCED_RANGE enables analog output with reduced range (10%-90% VDD) OS_ANALOG_REDUCED_RANGE // OS_DIGITAL_PWM enables digital PWM output. Frequency determined by PWMF OS_DIGITAL_PWM )
OUTPUT_STAGE values for the OUTS component of CONF (and the OUTS VR - AS5600 ONLY)
const ( // PWMF_115_HZ enables PWM at 115 Hz PWMF_115_HZ = iota // PWMF_230_HZ enables PWM at 230 Hz PWMF_230_HZ // PWMF_460_HZ enables PWM at 460 Hz PWMF_460_HZ // PWMF_920_HZ enables PWM at 920 Hz PWMF_920_HZ )
PWM_FREQUENCY values for the PWMF component of CONF (and the PWMF VR - ASS5600 ONLY)
const ( // SF_16X enables a 16x Slow Filter step response SF_16X = iota // SF_8X enables a 8x Slow Filter step response SF_8X // SF_4X enables a 4x Slow Filter step response SF_4X // SF_2X enables a 2x Slow Filter step response SF_2X )
SLOW_FILTER_RESPONSE values for the SF (slow filter) component of CONF (and the SF VR)
const ( // FTH_NONE disables the fast filter (slow filter only) FTH_NONE = iota // FTH_6LSB enables a fast filter threshold with 6 LSBs FTH_6LSB // FTH_7LSB enables a fast filter threshold with 7 LSBs FTH_7LSB // FTH_9LSB enables a fast filter threshold with 9 LSBs FTH_9LSB // FTH_18LSB enables a fast filter threshold with 18 LSBs FTH_18LSB // FTH_21LSB enables a fast filter threshold with 21 LSBs FTH_21LSB // FTH_24LSB enables a fast filter threshold with 24 LSBs FTH_24SB // FTH_10LSB enables a fast filter threshold with 10 LSBs FTH_10LSB )
FAST_FILTER_THRESHOLD values for the FTH (fast filter threshold) component of CONF (and the FTH VR)
const ( // WD_OFF disables the Watchdog Timer WD_OFF = iota // WD_ON enables the Watchdog Timer (automatic entry into LPM3 low-power mode enabled) WD_ON )
WATCHDOG_TIMER values for the WD component of CONF (and the WD VR)
const ( // STATUS_MH is set in STATUS when the magnet field is too strong (AGC minimum gain overflow) STATUS_MH = 1 << (iota + 3) // STATUS_ML is set in STATUS when the magnet field is too weak (AGC maximum gain overflow) STATUS_ML // STATUS_MD is set n STATUS when the magnet is detected. Doesn't seem to work with some units. STATUS_MD )
constants for the raw STATUS register bitfield value.
const ( // ABN_8 configures 8 output positions (61 Hz) ABN_8 = iota // ABN_16 configures 16 output positions (122 Hz) ABN_16 // ABN_32 configures 32 output positions (244 Hz) ABN_32 // ABN_64 configures 64 output positions (488 Hz) ABN_64 // ABN_128 configures 128 output positions (976 Hz) ABN_128 // ABN_256 configures 256 output positions (1.95 KHz) ABN_256 // ABN_512 configures 512 output positions (3.9 KHz) ABN_512 // ABN_1024 configures 1024 output positions (7.8 KHz) ABN_1024 // ABN_2048 configures 2048 output positions (15.6 KHz) ABN_2048 )
ABN_MAPPING values for the ABN register (AS5601 ONLY)
const BURN_ANGLE_COUNT_MAX uint16 = 3
BURN_ANGLE_COUNT_MAX is a constant for the maximum number of times a BURN_ANGLE command can be executed. Compare this with ZMCO
const DefaultAddress uint8 = 0x36
DefaultAddress is the default I2C address of the AMS AS560x sensors (0x36).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AS5600Device ¶
type AS5600Device struct { // promote BaseDevice BaseDevice }
AS5600Device represents an ams AS5600 device driver accessed over I2C
func NewAS5600 ¶
func NewAS5600(bus drivers.I2C) AS5600Device
NewAS5600 creates a new AS5600Device given an I2C bus
func (*AS5600Device) Configure ¶
func (d *AS5600Device) Configure(cfg Config) error
Configure sets up the AMS AS5600 sensor device with the given configuration.
func (*AS5600Device) GetMaxAngle ¶
func (d *AS5600Device) GetMaxAngle(units AngleUnit) (uint16, float32, error)
GetMaxAngle returns the 'max position' (MANG) in different units
func (*AS5600Device) GetMaxPosition ¶
func (d *AS5600Device) GetMaxPosition(units AngleUnit) (uint16, float32, error)
GetMaxPosition returns the 'max position' (MPOS) in different units
func (*AS5600Device) SetMaxAngle ¶
func (d *AS5600Device) SetMaxAngle(mang float32, units AngleUnit) error
SetMaxAngle sets the 'max angle' (MANG) in different units
func (*AS5600Device) SetMaxPosition ¶
func (d *AS5600Device) SetMaxPosition(mpos float32, units AngleUnit) error
SetMaxPosition sets the 'max position' (MPOS) in different units
func (*AS5600Device) WriteRegister ¶
func (d *AS5600Device) WriteRegister(address uint8, value uint16) error
WriteRegister writes the given value for the given register to the AS560x device via I2C
type AS5601Device ¶
type AS5601Device struct {
BaseDevice // promote base device
}
AS5601Device represents an ams AS5601 device driver accessed over I2C
func NewAS5601 ¶
func NewAS5601(bus drivers.I2C) AS5601Device
NewAS5601 creates a new AS5601Device given an I2C bus
type AngleUnit ¶
type AngleUnit int
AngleUnit is an enum to allow the use of different units when reading/writing angles from the AS560x sensors.
const ( // ANGLE_NATIVE uses the device's native angle measurement. i.e. 12-bit integer, 0 <= angle <= 0xfff (4095) ANGLE_NATIVE AngleUnit = iota // ANGLE_DEGREES_INT measures angles in degrees using integer arithmetic for speed. i.e. 0 <= angle < 360 ANGLE_DEGREES_INT // ANGLE_DEGREES_FLOAT measures angles in degrees using floating point (slower). i.e. 0.0 <= angle < 360.0 ANGLE_DEGREES_FLOAT // ANGLE_RADIANS measures angles in radians using floating point (slower). i.e. 0.0 <= angle < 2 * PI ANGLE_RADIANS )
type BaseDevice ¶
type BaseDevice struct {
// contains filtered or unexported fields
}
BaseDevice handles the common behaviour between AS5600 & AS5601 devices
func (*BaseDevice) Angle ¶
func (d *BaseDevice) Angle(units AngleUnit) (uint16, float32, error)
Angle reads the (scaled & adjusted) ANGLE register in various units
func (*BaseDevice) Burn ¶
func (d *BaseDevice) Burn(burnCmd BURN_CMD) error
Burn is a convenience method to program the device permanently by writing to the BURN register (limited number of times use!)
func (*BaseDevice) Configure ¶
func (d *BaseDevice) Configure(cfg Config)
Configure sets up the AMS AS560x sensor device with the given configuration.
func (*BaseDevice) GetZeroPosition ¶
func (d *BaseDevice) GetZeroPosition(units AngleUnit) (uint16, float32, error)
GetZeroPosition returns the 'zero position' (ZPOS) in various units
func (*BaseDevice) MagnetStatus ¶
func (d *BaseDevice) MagnetStatus() (detected bool, strength MagnetStrength, err error)
MagnetStatus reads the STATUS register and reports magnet position characteristics
func (*BaseDevice) RawAngle ¶
func (d *BaseDevice) RawAngle(units AngleUnit) (uint16, float32, error)
RawAngle reads the (unscaled & unadjusted) RAW_ANGLE register in various units
func (*BaseDevice) ReadRegister ¶
func (d *BaseDevice) ReadRegister(address uint8) (uint16, error)
ReadRegister reads the value for the given register from the AS560x device via I2C
func (*BaseDevice) SetZeroPosition ¶
func (d *BaseDevice) SetZeroPosition(zpos float32, units AngleUnit) error
SetZeroPosition sets the 'zero position' (ZPOS) in various units
func (*BaseDevice) WriteRegister ¶
func (d *BaseDevice) WriteRegister(address uint8, value uint16) error
WriteRegister writes the given value for the given register to the AS560x device via I2C
type Config ¶
type Config struct { // Address is the I2C address of the AS560x device. If left zero this will default to 0x36 Address uint8 }
Config holds the configuration for the AMS AS560x sensor devices.
type MagnetStrength ¶
type MagnetStrength int
MagnetStrength is an enum to indicate the magnetic field strength detected by the AS560x sensors.
const ( // MagnetTooWeak indicates that the magnet strength is too weak (AGC maximum gain overflow) - move it closer MagnetTooWeak MagnetStrength = iota - 1 // MagnetOk indicates that the magnet strength is about right. MagnetOk // MagnetTooStrong indicates that the magnet strength is too strong (AGC minimum gain overflow) - move it further away MagnetTooStrong )