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 ¶
NewMCP4725 returns a new instance of MCP4725.
func (MCP4725) SetInputCode ¶
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 ¶
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.