Documentation ¶
Overview ¶
Package tlv493d implements interfacing code to the Infineon TLV493D haff effect sensor.
Features of the device:
3-dimensional hall effect sensor, measures up to +/-130 mT magnetic flux. temperature sensor i2c interface 12-bit resolution low power consumption
Features of the driver:
Implemented all options of the device Power modes described in the documentation are defined as constants 2 precisions: high precision (12 bits), where all registers are read or low precision, which saves 50% of I2C bandwidth, but without temperature and only 8-bit resolution Continuous reading mode
Datasheet and application notes: https://www.infineon.com/cms/en/product/sensor/magnetic-sensors/magnetic-position-sensors/3d-magnetics/tlv493d-a1b6/
Example ¶
package main import ( "fmt" "log" "periph.io/x/periph/conn/i2c/i2creg" "periph.io/x/periph/conn/physic" "periph.io/x/periph/experimental/devices/tlv493d" "periph.io/x/periph/host" ) func main() { // Make sure periph is initialized. if _, err := host.Init(); err != nil { log.Fatal(err) } // Open default I²C bus. bus, err := i2creg.Open("") if err != nil { log.Fatalf("failed to open I²C: %v", err) } defer bus.Close() // Create a new TLV493D hall effect sensor. tlv, err := tlv493d.New(bus, &tlv493d.DefaultOpts) if err != nil { log.Fatalln(err) } defer tlv.Halt() // Read a single value. tlv.SetMode(tlv493d.LowPowerMode) fmt.Println("Single reading") reading, err := tlv.Read(tlv493d.HighPrecisionWithTemperature) if err != nil { log.Fatalln(err) } fmt.Println(reading) // Read values continuously from the sensor. fmt.Println("Continuous reading") c, err := tlv.ReadContinuous(100*physic.Hertz, tlv493d.LowPrecision) if err != nil { log.Fatalln(err) } for reading := range c { fmt.Println(reading) } }
Output:
Index ¶
- Constants
- Variables
- type Dev
- func (d *Dev) EnableInterruptions(enable bool) error
- func (d *Dev) EnableParityTest(enable bool) error
- func (d *Dev) EnableTemperatureMeasurement(enable bool) error
- func (d *Dev) Halt() error
- func (d *Dev) Read(precision Precision) (Sample, error)
- func (d *Dev) ReadContinuous(frequency physic.Frequency, precision Precision) (<-chan Sample, error)
- func (d *Dev) SetMode(mode Mode) error
- func (d *Dev) StopContinousRead()
- func (d *Dev) String() string
- type Mode
- type Opts
- type Precision
- type Sample
Examples ¶
Constants ¶
const I2CAddr uint16 = 0x5e
I2CAddr is the default I2C address for the TLV493D component.
const I2CAddr1 uint16 = 0x1f
I2CAddr1 is an alternative I2C address for TLV493D components.
Variables ¶
var DefaultOpts = Opts{ I2cAddress: I2CAddr, Reset: true, Mode: PowerDownMode, EnableTemperatureMeasurement: true, InterruptPadEnabled: false, ParityTestEnabled: true, TemperatureOffsetCompensation: 340, }
DefaultOpts are the recommended default options.
var FastMode = Mode{ // contains filtered or unexported fields }
FastMode is the mode using the most energy
var LowPowerMode = Mode{ // contains filtered or unexported fields }
LowPowerMode uses less energy than FastMode, with lower measurement rate
var MasterControlledMode = Mode{ // contains filtered or unexported fields }
MasterControlledMode refer to TLV493D documentation on how to use this mode
var PowerDownMode = Mode{ // contains filtered or unexported fields }
PowerDownMode shuts down the sensor. It can still reply to I2C commands.
var UltraLowPowerMode = Mode{ // contains filtered or unexported fields }
UltraLowPowerMode saves the most energy but with very low measurement rate
Functions ¶
This section is empty.
Types ¶
type Dev ¶
type Dev struct {
// contains filtered or unexported fields
}
Dev is an handle to a TLV493D hall effect sensor.
func (*Dev) EnableInterruptions ¶
EnableInterruptions controls if the sensor should send interruption of new measurement
func (*Dev) EnableParityTest ¶
EnableParityTest controls if the sensor should control the parity of the data transmitted
func (*Dev) EnableTemperatureMeasurement ¶
EnableTemperatureMeasurement controls the temperature sensor activation
func (*Dev) ReadContinuous ¶
func (d *Dev) ReadContinuous(frequency physic.Frequency, precision Precision) (<-chan Sample, error)
ReadContinuous returns a channel which will receive readings at regular intervals
func (*Dev) StopContinousRead ¶
func (d *Dev) StopContinousRead()
StopContinousRead stops a currently running continuous read
type Mode ¶
type Mode struct {
// contains filtered or unexported fields
}
Mode reprents the various power modes described in the documentation
type Opts ¶
type Opts struct { I2cAddress uint16 Reset bool Mode Mode InterruptPadEnabled bool // If enabled, this can cause I2C failures. See documentation. EnableTemperatureMeasurement bool // Disable to save power. ParityTestEnabled bool TemperatureOffsetCompensation int }
Opts holds the configuration options.
type Precision ¶
type Precision int
Precision represents a request for a compromise between I2C bandwidth versus measurement precision.
type Sample ¶
type Sample struct { Bx physic.MagneticFluxDensity By physic.MagneticFluxDensity Bz physic.MagneticFluxDensity Temperature physic.Temperature }
Sample contains the metrics measured by the sensor