microchip

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: 2 Imported by: 0

README

godoc

Microchip

Package microchip implements drivers for I2C controlled IC's produced by Microchip.

Drivers for the following IC's are implemented:

Sample usage:

package main

import (
	"fmt"

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

func main() {
	d, err := i2c.Open(&i2c.Devfs{
		Dev: "/dev/i2c-1",
	}, 0x60)

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

	// Reference voltage is 2.7V.
	dac, err := microchip.NewMCP4725(d, 2.7)

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

	// Set output of channel 1 to 1.3V. The MCP4725 has only 1 channel,
	// select other channels results in an error.
	if err := dac.SetVoltage(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. The value must be in range of 0 till 4096.
	if err := dac.SetInputCode(4095, 1); err != nil {
		panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
	}
}

Documentation

Overview

Package microchip implements drivers for a few I2C controlled chips produced by Microchip.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCP4725

type MCP4725 struct {
	Address int
	// contains filtered or unexported fields
}

The MCP4725 has a 14 bit wide EEPROM to store configuration bits (2 bits) and DAC input data (12 bits)

The MCP4275 also has a 19 bits DAC register. The master can read/write the DAC register or EEPROM using i2c interface.

The MCP4725 device address contains four fixed bits (1100 = device code) and three address bits (A2, A1, A0). The A2 and A1 bits are hard-wired during manufacturing, and the A0 bit is determined by the logic state of AO pin.

The MCP4725 has 2 modes of operation: normal mode and power-down mode. This driver only supports normal mode.

The datasheet of the device is here: http://ww1.microchip.com/downloads/en/DeviceDoc/22039d.pdf

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

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

// Reference voltage is 2.7V.
dac, err := NewMCP4725(d, 2.7)

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

// Set output of channel 1 to 1.3V. The MCP4725 has only 1 channel,
// select other channels results in an error.
if err := dac.SetVoltage(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. The value must be in range of 0 till 4096.
if err := dac.SetInputCode(4095, 1); err != nil {
	panic(fmt.Sprintf("failed to set voltage using output code: %v", err))
}
Output:

func NewMCP4725

func NewMCP4725(conn *i2c.Device, vref float64) (*MCP4725, error)

NewMCP4725 returns a new instance of MCP4725.

func (MCP4725) SetInputCode

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

SetInputCode sets voltage of the only channel of the MCP4725. The channel parameter is required in the signature of the function to be conform with the dac.DAC interface. Because the MCP4725 has only 1 channel it's only allowed value is 1.

func (MCP4725) SetVoltage

func (m MCP4725) SetVoltage(v float64, channel int) error

SetVoltage sets voltage of the only channel of the MCP4725. The channel parameter is required in the signature of the function to be conform with the dac.DAC interface. Because the MCP4725 has only 1 channel it's only allowed value is 1.

Jump to

Keyboard shortcuts

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