Giter Site home page Giter Site logo

mcp49xx-rs's Introduction

Rust MCP49xx and MCP48xx digital-to-analog converter (DAC) driver

crates.io Docs Build Status Coverage Status Maintenance Intention

This is a platform-agnostic Rust driver for the MCP49xx and MCP48xx SPI digital-to-analog converters (DAC), based on the embedded-hal traits.

This driver allows you to:

  • Set a channel to a value.
  • Shutdown a channel.
  • Use buffering on commands.
  • Select gain.

The devices

The Microchip Technology Inc. MCP49xx devices are single/dual channel 8-bit, 10-bit and 12-bit buffered voltage output Digital-to-Analog Converters (DACs). The devices operate from a single 2.7V to 5.5V supply with an SPI compatible Serial Peripheral Interface. The user can configure the full-scale range of the device to be Vref or 2*Vref by setting the gain selection option bit (gain of 1 of 2).

The user can shut down the device by setting the Configuration Register bit. In Shutdown mode, most of the internal circuits are turned off for power savings, and the output amplifier is configured to present a known high resistance output load (500 kΩ, typical).

The devices include double-buffered registers, allowing synchronous updates of the DAC output using the LDAC pin. These devices also incorporate a Power-on Reset (POR) circuit to ensure reliable power-up.

The devices utilize a resistive string architecture, with its inherent advantages of low Differential Non-Linearity (DNL) error and fast settling time. These devices are specified over the extended temperature range (+125°C).

The devices provide high accuracy and low noise performance for consumer and industrial applications where calibration or compensation of signals (such as temperature, pressure and humidity) are required.

This driver is compatible with these devices:

Device Resolution Channels Buffering
MCP4801 8-bit 1 Not supported
MCP4802 8-bit 2 Not supported
MCP4811 10-bit 1 Not supported
MCP4812 10-bit 2 Not supported
MCP4821 12-bit 1 Not supported
MCP4822 12-bit 2 Not supported
MCP4901 8-bit 1 Supported
MCP4902 8-bit 2 Supported
MCP4911 10-bit 1 Supported
MCP4912 10-bit 2 Supported
MCP4921 12-bit 1 Supported
MCP4922 12-bit 2 Supported

Datasheets:

Usage

To use this driver, import this crate and an embedded_hal implementation, then instantiate the appropriate device. In the following examples an instance of the device MCP4921 will be created as an example. Other devices can be created with similar methods like: Mcp49xx::new_mcp4822(...).

Please find additional examples using hardware in this repository: driver-examples

extern crate embedded_hal;
extern crate linux_embedded_hal;
extern crate mcp49xx;

use linux_embedded_hal::{Pin, Spidev};
use mcp49xx::{Command, Mcp49xx};

fn main() {
    let spi = Spidev::open("/dev/spidev0.0").unwrap();
    let cs = Pin::new(25);
    let mut mcp4921 = Mcp49xx::new_mcp4921(spi, cs);

    let cmd = Command::default();
    let cmd = cmd.double_gain().value(50);

    // enable double gain and set value
    mcp4921.send(cmd).unwrap();

    // keeps double gain enabled but changes value
    mcp4921.send(cmd.value(100)).unwrap();

    // Get SPI device and CS pin back
    let (_spi, _chip_select) = mcp4921.destroy();
}

Support

For questions, issues, feature requests, and other changes, please file an issue in the github project.

License

Licensed under either of

at your option.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

mcp49xx-rs's People

Contributors

eldruin avatar windfisch avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

30350n

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.