max

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

MAX

Package microchip implements drivers for a few I2C controlled IC's produced by Maxim Integrated. This package relies on x/exp/io/spi.

Drivers for the following IC's are implemented:

Sample usage:

package main

import (
	"fmt"

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

func main() {
	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()


	// 2.5V is the input reference of the DAC.
	dac, err := max.NewMAX5813(d, 2.5)

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

        // Set output of channel 1 to 1.3V.
        if err := dac.SetVoltage(1.3, 1); 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.
        if err := dac.SetInputCode(128, 1); err != nil {
		panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
        }
}

Documentation

Overview

Package max contains drivers for IC's produced by Maxim Integrated.

MAX581x

The implemententation for the MAX5813, MAX5814 and MAX5815 only implement the REF and CODEn_LOADn commands. The commands CODEn, LOADn, CODEn_LOAD_ALL, POWER, SW_CLEAR, SW_RESET, CONFIG, CODE_ALL, LOAD_ALL and CODE_ALL, CODE_ALL_LOAD_ALL are not implemented.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MAX5813

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

MAX5813 is a 4 channel DAC with a resolution of 8 bits. The datasheet is here: https://datasheets.maximintegrated.com/en/ds/MAX5813-MAX5815.pdf

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

// 2.5V is the input reference of the DAC.
dac, err := NewMAX5813(d, 2.5)

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

// Set output of channel 1 to 1.3V.
if err := dac.SetVoltage(1.3, 1); 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.
if err := dac.SetInputCode(128, 1); err != nil {
	panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
}
Output:

func NewMAX5813

func NewMAX5813(conn *i2c.Device, vref float64) (*MAX5813, error)

NewMAX5813 returns a new instance of MAX5813.

func (*MAX5813) Conn

func (m *MAX5813) Conn() *i2c.Device

Conn returns the connection to the I2C device.

func (MAX5813) SetInputCode

func (m MAX5813) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC using the CODEn_LOADn command.

func (MAX5813) SetVoltage

func (m MAX5813) 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.

func (*MAX5813) SetVref

func (m *MAX5813) SetVref(v float64) error

Vref sets the global reference for all channels. The device can use either an external reference or a internel reference, this depends on the wiring of the IC. Allowed values for the internel reference are 2.5V, 2.048V and 4.096V. If this function is called with one of these value the internel reference is set to this value using the REF command. For any other value the channels will use the input reference is equal to the

type MAX5814

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

MAX5814 is a 4 channel DAC with a resolution of 10 bits. The datasheet is here: https://datasheets.maximintegrated.com/en/ds/MAX5813-MAX5815.pdf

func NewMAX5814

func NewMAX5814(conn *i2c.Device, vref float64) (*MAX5814, error)

NewMAX5814 returns a new instance of MAX5814.

func (*MAX5814) Conn

func (m *MAX5814) Conn() *i2c.Device

Conn returns the connection to the I2C device.

func (MAX5814) SetInputCode

func (m MAX5814) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC using the CODEn_LOADn command.

func (MAX5814) SetVoltage

func (m MAX5814) 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.

func (*MAX5814) SetVref

func (m *MAX5814) SetVref(v float64) error

Vref sets the global reference for all channels. The device can use either an external reference or a internel reference, this depends on the wiring of the IC. Allowed values for the internel reference are 2.5V, 2.048V and 4.096V. If this function is called with one of these value the internel reference is set to this value using the REF command. For any other value the channels will use the input reference is equal to the

type MAX5815

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

MAX5815 is a 4 channel DAC with a resolution of 12 bits. The datasheet is here: https://datasheets.maximintegrated.com/en/ds/MAX5813-MAX5815.pdf

func NewMAX5815

func NewMAX5815(conn *i2c.Device, vref float64) (*MAX5815, error)

NewMAX5815 returns a new instance of MAX5814.

func (*MAX5815) Conn

func (m *MAX5815) Conn() *i2c.Device

Conn returns the connection to the I2C device.

func (MAX5815) SetInputCode

func (m MAX5815) SetInputCode(code, channel int) error

SetInputCode writes the digital input code to the DAC using the CODEn_LOADn command.

func (MAX5815) SetVoltage

func (m MAX5815) 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.

func (*MAX5815) SetVref

func (m *MAX5815) SetVref(v float64) error

Vref sets the global reference for all channels. The device can use either an external reference or a internel reference, this depends on the wiring of the IC. Allowed values for the internel reference are 2.5V, 2.048V and 4.096V. If this function is called with one of these value the internel reference is set to this value using the REF command. For any other value the channels will use the input reference is equal to the

Jump to

Keyboard shortcuts

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