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

README

godoc

Microchip

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

MCP3x0x is a family of Analog Digital Converters (ADC). Currently the package contains drivers for the following ADC:

Sample usage:

package main

import (
	"fmt"

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

func main() {
	conn, err := spi.Open(&spi.Devfs{
		Dev:      "/dev/spidev32766.0",
		Mode:     spi.Mode0,
		MaxSpeed: 3600000,
	})

	if err != nil {
		panic(fmt.Sprintf("failed to open SPI device: %s", err))
	}

	defer conn.Close()

	adc := microchip.MCP3008{
		Conn: conn,
		Vref: 5.0,
	}

        // Read the voltage of channel 3...
	v, err := adc.Voltage(3)

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

        // ...or read the raw value of channel 3.
        c, err := adc.OutputCode(3)

	fmt.Printf("channel 3 reads %f Volts or digital output code %d", v, c)
}

Documentation

Overview

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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCP3004

type MCP3004 struct {
	Conn *spi.Device

	// Vref is the voltage on the reference input of the ADC.
	Vref float64

	InputType adc.InputType
}

MCP3004 is 10-bits ADC with 4 single-ended or 2 pseudo-differential inputs. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21295C.pdf

func (MCP3004) OutputCode

func (m MCP3004) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code.

func (MCP3004) Voltage

func (m MCP3004) Voltage(channel int) (float64, error)

Voltage returns the voltage of a channel.

type MCP3008

type MCP3008 struct {
	Conn *spi.Device

	// Vref is the voltage on the reference input of the ADC.
	Vref float64

	InputType adc.InputType
}

MCP3008 is 10-bits ADC with 8 single-ended or 4 pseudo-differential inputs. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21295C.pdf

Example
conn, err := spi.Open(&spi.Devfs{
	Dev:      "/dev/spidev32766.0",
	Mode:     spi.Mode0,
	MaxSpeed: 3600000,
})

if err != nil {
	panic(fmt.Sprintf("failed to open SPI device: %s", err))
}

defer conn.Close()

a := MCP3008{
	Conn: conn,
	Vref: 5.0,

	// Optional, default value is SingleEnded.
	InputType: adc.SingleEnded,
}

// Voltage the voltage on channel 3.
v, err := a.Voltage(3)
if err != nil {
	panic(fmt.Sprintf("failed to read channel 3 of MCP3008: %s", err))
}

fmt.Printf("read %f Volts from channel 3", v)
Output:

func (MCP3008) OutputCode

func (m MCP3008) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code.

func (MCP3008) Voltage

func (m MCP3008) Voltage(channel int) (float64, error)

Voltage returns the voltage of a channel.

type MCP3204

type MCP3204 struct {
	Conn *spi.Device

	// Vref is the voltage on the reference input of the ADC.
	Vref float64

	InputType adc.InputType
}

MCP3204 is 12-bits ADC with 4 single-ended or 2 pseudo-differential inputs. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21298e.pdf

func (MCP3204) OutputCode

func (m MCP3204) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code.

func (MCP3204) Voltage

func (m MCP3204) Voltage(channel int) (float64, error)

Voltage returns the voltage of a channel.

type MCP3208

type MCP3208 struct {
	Conn *spi.Device

	// Vref is the voltage on the reference input of the ADC.
	Vref float64

	InputType adc.InputType
}

MCP3208 is 12-bits ADC with 8 single-ended or 4 pseudo-differential inputs. Datasheet: http://ww1.microchip.com/downloads/en/DeviceDoc/21298e.pdf

func (MCP3208) OutputCode

func (m MCP3208) OutputCode(channel int) (int, error)

OutputCode queries the channel and returns its digital output code.

func (MCP3208) Voltage

func (m MCP3208) Voltage(channel int) (float64, error)

Voltage returns the voltage of a channel.

Jump to

Keyboard shortcuts

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