tlv493d

package
v3.6.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2021 License: Apache-2.0 Imports: 6 Imported by: 3

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
// 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

Examples

Constants

View Source
const I2CAddr uint16 = 0x5e

I2CAddr is the default I2C address for the TLV493D component.

View Source
const I2CAddr1 uint16 = 0x1f

I2CAddr1 is an alternative I2C address for TLV493D components.

Variables

View Source
var DefaultOpts = Opts{
	I2cAddress:                    I2CAddr,
	Reset:                         true,
	Mode:                          PowerDownMode,
	EnableTemperatureMeasurement:  true,
	InterruptPadEnabled:           false,
	ParityTestEnabled:             true,
	TemperatureOffsetCompensation: 340,
}

DefaultOpts are the recommended default options.

View Source
var FastMode = Mode{
	// contains filtered or unexported fields
}

FastMode is the mode using the most energy

View Source
var LowPowerMode = Mode{
	// contains filtered or unexported fields
}

LowPowerMode uses less energy than FastMode, with lower measurement rate

View Source
var MasterControlledMode = Mode{
	// contains filtered or unexported fields
}

MasterControlledMode refer to TLV493D documentation on how to use this mode

View Source
var PowerDownMode = Mode{
	// contains filtered or unexported fields
}

PowerDownMode shuts down the sensor. It can still reply to I2C commands.

View Source
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 New

func New(i i2c.Bus, opts *Opts) (*Dev, error)

New creates a new TLV493D driver for a 3D hall effect sensors

func (*Dev) EnableInterruptions

func (d *Dev) EnableInterruptions(enable bool) error

EnableInterruptions controls if the sensor should send interruption of new measurement

func (*Dev) EnableParityTest

func (d *Dev) EnableParityTest(enable bool) error

EnableParityTest controls if the sensor should control the parity of the data transmitted

func (*Dev) EnableTemperatureMeasurement

func (d *Dev) EnableTemperatureMeasurement(enable bool) error

EnableTemperatureMeasurement controls the temperature sensor activation

func (*Dev) Halt

func (d *Dev) Halt() error

Halt implements conn.Resource.

func (*Dev) Read

func (d *Dev) Read(precision Precision) (Sample, error)

Read returns a sample from the last measurement of the sensor

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) SetMode

func (d *Dev) SetMode(mode Mode) error

SetMode sets the power mode of the sensor

func (*Dev) StopContinousRead

func (d *Dev) StopContinousRead()

StopContinousRead stops a currently running continuous read

func (*Dev) String

func (d *Dev) String() string

String implements conn.Resource.

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.

const (
	// HighPrecisionWithTemperature reads the full 12-bit value for each axis
	// and the temperature
	HighPrecisionWithTemperature Precision = 0
	// LowPrecision reads only 8-bits for each axis. Temperature is not read.
	LowPrecision Precision = 1
)

type Sample

Sample contains the metrics measured by the sensor

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL