ti

package
v0.0.0-...-9eb3501 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2020 License: MPL-2.0 Imports: 3 Imported by: 0

README

godoc

Texas Instruments

Package ti implements drivers for I2C controlled IC's produced by Texas Instruments.

Drivers for the following IC's are implemented:

Sample usage:

package main

import (
	"fmt"

	"github.com/advancedclimatesystems/io/i2c/ti"
	"golang.org/x/exp/io/i2c"
)

func main() {
	// We are going to write 5.5 volt to channel 0.
	volts := 5.5
	channel := 0

	dev, err := i2c.Open(&i2c.Devfs{
		Dev: "/dev/i2c-0",
	}, 0x48)

	if err != nil {
		panic(fmt.Sprintf("failed to open device: %v", err))
	}
	defer dev.Close()

	// Create the DAC. The reference voltage is set to 10V.
	dac := ti.NewDAC5578(dev, 10)

	// Write volts to the channel.
	if err = dac.SetVoltage(volts, channel); err != nil {
		panic(fmt.Sprintf("failed to set voltage: %v", err))
	}

	// It's also possible to set output of a channel with digital output
        // code. Because the DAC5578 has a resolution of 8 bits the value must
        // be between 0 and 255.
	if err := dac.SetInputCode(255, channel); err != nil {
		panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
	}
}

Documentation

Overview

Package ti contains drivers for IC's produces by Texas Instruments.

Package ti contains drivers for IC's produced by Texas Instruments.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADS1100

type ADS1100 struct {
	// contains filtered or unexported fields
}

ADS1100 is a 16-bit ADC. It's PGA can be set to 1, 2, 4 or 8. Allowed values for the data rate are 8, 16, 32 or 128 SPS.

Example
d, err := i2c.Open(&i2c.Devfs{
	Dev: "/dev/i2c-0",
}, 0x1c)

if err != nil {
	panic(fmt.Sprintf("failed to open device: %v", err))
}
defer d.Close()

// 4.048 is Vref, 16 is the data rate and the PGA is set to 1.
adc, err := NewADS1100(d, 4.048, 16, 1)

if err != nil {
	panic(fmt.Sprintf("failed to create ADS1100: %v", err))
}

// Retrieve voltage of channel 1...
v, err := adc.Voltage(1)

if err != nil {
	panic(fmt.Sprintf("failed to read channel 1 of ADS1100: %s", err))
}

// ...read the raw value of channel 1. PGA has not been applied.
c, err := adc.OutputCode(1)

if err != nil {
	panic(fmt.Sprintf("failed to read channel 1 of ADS1100: %s", err))
}

fmt.Printf("channel 1 reads %f or digital output code  %d", v, c)
Output:

func NewADS1100

func NewADS1100(conn *i2c.Device, vref float64, rate, pga int) (*ADS1100, error)

NewADS1100 returns an ADS1100.

func (*ADS1100) DataRate

func (a *ADS1100) DataRate() (int, error)

DataRate reads the config register of the ADC returns the current value of the data rate.

func (ADS1100) OutputCode

func (a ADS1100) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code. The maximum code depends on the selected data rate. The higher the data rate, the lower the number of bits used.

func (*ADS1100) PGA

func (a *ADS1100) PGA() (int, error)

PGA reads the config register of the ADC and returns the current PGA.

func (*ADS1100) SetDataRate

func (a *ADS1100) SetDataRate(r int) error

SetDataRate writes the value for the data rate to the ADC.

func (*ADS1100) SetPGA

func (a *ADS1100) SetPGA(v int) error

SetPGA writes the value for the Programmable Gain Amplifier to the ADC. Valid values are 1, 2, 4 and 8.

func (ADS1100) Voltage

func (a ADS1100) Voltage(channel int) (float64, error)

Voltage queries the channel of an ADC and returns its voltage.

type ADS1110

type ADS1110 struct {
	// contains filtered or unexported fields
}

ADS1110 is a 16-bits ADC. It's PGA can be set to 1, 2, 4 or 8. Allowed values are 15, 30, 60 or 240 SPS. The ADS1110 always uses an internal voltage reference of 2.048V.

func NewADS1110

func NewADS1110(conn *i2c.Device, rate, pga int) (*ADS1110, error)

NewADS1110 returns an ADS1110.

func (*ADS1110) DataRate

func (a *ADS1110) DataRate() (int, error)

DataRate reads the config register of the ADC returns the current value of the data rate.

func (ADS1110) OutputCode

func (a ADS1110) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code. The maximum code depends on the selected data rate. The higher the data rate, the lower the number of bits used.

func (*ADS1110) PGA

func (a *ADS1110) PGA() (int, error)

PGA reads the config register of the ADC and returns the current PGA.

func (*ADS1110) SetDataRate

func (a *ADS1110) SetDataRate(r int) error

SetDataRate writes the value for the data rate to the ADC.

func (*ADS1110) SetPGA

func (a *ADS1110) SetPGA(v int) error

SetPGA writes the value for the Programmable Gain Amplifier to the ADC. Valid values are 1, 2, 4 and 8.

func (ADS1110) Voltage

func (a ADS1110) Voltage(channel int) (float64, error)

Voltage queries the channel of an ADC and returns its voltage.

type DAC5578

type DAC5578 struct {
	// contains filtered or unexported fields
}

DAC5578 is a 8 channel DAC with a resolution of 8 bits. The datasheet is here: http://www.ti.com/lit/ds/symlink/dac5578.pdf

Example
// We are going to write 5.5 volt to channel 0.
volts := 5.5
channel := 0

dev, err := i2c.Open(&i2c.Devfs{
	Dev: "/dev/i2c-0",
}, 0x48)

if err != nil {
	panic(fmt.Sprintf("failed to open device: %v", err))
}
defer dev.Close()

// Create the DAC. The reference voltage is set to 10V.
dac := NewDAC5578(dev, 10)

// Write volts to the channel.
err = dac.SetVoltage(volts, channel)
if err != nil {
	panic(fmt.Sprintf("failed to set voltage: %v", err))
}

// It's also possible to set output of a channel with digital output
// code. The value must be between 0 and 255.
if err := dac.SetInputCode(255, channel); err != nil {
	panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
}
Output:

func NewDAC5578

func NewDAC5578(conn *i2c.Device, vref float64) *DAC5578

NewDAC5578 returns a new instance of DAC5578.

func NewDAC6578

func NewDAC6578(conn *i2c.Device, vref float64) *DAC5578

NewDAC6578 returns a new instance of DAC5578.

func NewDAC7578

func NewDAC7578(conn *i2c.Device, vref float64) *DAC5578

NewDAC7578 returns a new instance of DAC5578.

func (*DAC5578) SetInputCode

func (d *DAC5578) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC

func (*DAC5578) SetVoltage

func (d *DAC5578) SetVoltage(v float64, channel int) error

SetVoltage set output voltage of channel. Using the Vref the input code is calculated and then SetInputCode is called.

type DAC6578

type DAC6578 struct {
	// contains filtered or unexported fields
}

DAC6578 is a 8 channel DAC with a resolution of 10 bits. The datasheet is here: http://www.ti.com/lit/ds/symlink/dac6578.pdf

func (*DAC6578) SetInputCode

func (d *DAC6578) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC

func (*DAC6578) SetVoltage

func (d *DAC6578) SetVoltage(v float64, channel int) error

SetVoltage set output voltage of channel. Using the Vref the input code is calculated and then SetInputCode is called.

type DAC7578

type DAC7578 struct {
	// contains filtered or unexported fields
}

DAC7578 is a 8 channel DAC with a resolution of 10 bits. The datasheet is here: http://www.ti.com/lit/ds/symlink/dac7578.pdf

func (*DAC7578) SetInputCode

func (d *DAC7578) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC

func (*DAC7578) SetVoltage

func (d *DAC7578) SetVoltage(v float64, channel int) error

SetVoltage set output voltage of channel. Using the Vref the input code is calculated and then SetInputCode is called.

Jump to

Keyboard shortcuts

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