IC – MCP4921 – D/A Converter 12-bit 1 channel SPI

Hardware

Chip:

 

BESTELLEN

Informatie (ENG):
The Microchip Technology Inc. MCP492X are 2.7 – 5.5V, low-power, low DNL, 12-Bit Digital-to-Analog Converters (DACs) with optional 2x buffered output and SPI interface. The MCP492X are DACs that provide high accuracy and low noise performance for industrial applications where calibration or compensation of signals (such as temperature, pressure and humidity) are required. The MCP492X are available in the extended temperature range and PDIP, SOIC, MSOP and TSSOP packages. The MCP492X devices utilize a resistive string architecture, with its inherent advantages of low DNL error, low ratio metric temperature coefficient and fast settling time. These devices are specified over the extended temperature range. The MCP492X include doublebuffered inputs, allowing simultaneous updates using the LDAC pin. These devices also incorporate a Power-On Reset (POR) circuit to ensure reliable power-up.
Features:
• 12-Bit Resolution
• ±0.2 LSB DNL (typ)
• ±2 LSB INL (typ)
• Single or Dual Channel
• Rail-to-Rail Output
• SPI™ Interface with 20 MHz Clock Support
• Simultaneous Latching of the Dual DACs w/LDAC
• Fast Settling Time of 4.5 µs
• Selectable Unity or 2x Gain Output
• 450 kHz Multiplier Mode
• External VREF Input
• 2.7V to 5.5V Single-Supply Operation
• Extended Temperature Range: -40°C to +125°C

Pinout

Arduino

Sluit de chip aan volgens onderstaand overzicht:

Met onderstaand arduino script kun je de uitgangsvoltage instellen:

Bron: http://www.bartvenneker.nl/Arduino/index.php?art=0015


Script met bibliotheek MCP492X

Arduino Library

This library is built around the Arduino default SPI library and uses the designated SPI pins, in addition to a configurable chip select pin, passed in the constructor.

Installing the library

Method 1: ZIP file

  1. Download this repository as a .ZIP file: Download Arduino-MCP492X
  2. Open Arduino IDE
  3. Click Sketch > Include Library > Add .ZIP library…
  4. Select the library
  5. Click Sketch > Include Library > Contributed Libraries > MCP492X

Note: This will install the library on your computer but will not include it within your project if you were to transfer the files to someone else. If you want it all-in-one, I recommend method 2.

Method 2: Include in your project folder

You can also save the .h and .cpp files directly in you arduino project’s folder, and then reference it as follows:

You may want to consider making a directory for just libraries though, if you project consists of several files. If the directory inside your project directory called “libs”, the include line changes to:

Code

This is the bare minimum to get started with one of these DACs in an Arduino project:

Function descriptions

begin()

Initializes the library, by starting the SPI bus and configuring some settings.

It’s required to call this in setup().

analogWrite(unsigned int value)

Writes a 12-bit value to the DAC output. If this is on an MCP4922, it uses channel A.

analogWrite(bool odd, unsigned int value)

Writes a 12-bit value to a specific DAC output. If this is on an MCP4921, the value passed for odd is ignored. Otherwise, 0 selects the “even” DAC (A), and 1 selects the “odd” DAC (B).

value remains the 12-bit value you want to write.

analogWrite(bool odd, bool buffered, bool gain, bool active, unsigned int value)

Provides full access to all the control bits you can send to the DAC. Consult the data sheet for more information on each of the control bits.

Download @: https://github.com/michd/Arduino-MCP492X

Arduino-MCP492X-master

Raspberry Pi

Sluit de IC aan zoals aangegeven op onderstaand schema:

Ps. Altijd de pinout van je Raspberry Pi controleren, deze kan verschillen per versie.


Instellen dmv console commando

Wat heb je nodig?

  • SPI aanzetten op de pi via raspi-config

De analoge waarde kan je via de console instellen dmv een 2-byte echo naar de SPI bus

Bron: https://swharden.com/blog/2016-09-28-generating-analog-voltages-with-the-raspberry-pi/


Python script ZONDER SPI interface aan op Raspberry pi

Voor onderstaand python script hoeft de SPI interface niet aan te staan, het is een soort van software bit-banging.

Bron: https://forum-raspberrypi.de/forum/thread/15880-mcp4921-ansprechen/


Python script icm bibliotheek

Wat heb je nodig?

  • SPI aanzetten op de pi via raspi-config

Raspberry Pi Library

Python Library for driving MCP4922 DAC (Digital to Analog Converter) on Raspberry Pi

Installation

To install the library run the following commands on a Raspberry Pi or other Debian-based OS system:

Install Git

If you don’t have it already:

Requirements

To run this module you need RPi.GPIO and spidev:

Clone the repository

Install with Setup.py

Software

Getting started

Go to the example directory and execute the test script:

This script will initialize the MCP4922 and incrementally increase the voltage on both channels. Then it will decrease the voltage and loop forever.

If you want to manually set the channel and voltage, you can use the other test script:

Use it in your own code

Setup

First import the required GPIO module in python:

Set your pin mode to BCM:

and then import the MCP4922 module:

MCP4922 Class

The MCP4922 Class takes 3 arguments: spibusspidevice and cs. To configure just simple use this code in python:

spibus

Select the bus for your MCP4922. Should be either 0 or 1. If no argument is given it will turn to the default of 0.

Have a closer look at the spidev module (https://github.com/doceme/py-spidev) for more details.

spidevice

Select the device connected to the bus, should be either 0 or 1. If no argument is given it will turn to the default of 1.

Also checkout the spidev documentation for more details.

cs

Chip select pin. Enter the pin number (Broadcom or Physical pin) where the MCP4922 is connected to. If no argument is given it will turn to the default of 8 (Broadcom pin numbering) or 24 (physical pin numbering).

setVoltage(channel, value)

This method sets the desired output voltage at the requested channel. It is as easy as:

This will set the voltage output to 50% of the reference voltage.

channel

The MCP4922 has two channels, you can select by giving the arguments 0 or 1. 0 is channel A, 1 is channel B.

Anything else will throw an error at you.

value

Interger value from 0 to 4095, where 4095 is 100% of the reference voltage.

If you insert a value beyond that reach it will be clamped to 4095 (or 0 if you give a negative value).

setVoltage_gain(channel, value)

The MCP4922 has the ability to output the double of the reference Voltage Reference Voltage is measured by the MCP4922 at pin 13 (VrefA) for Channel A and pin 11 (VrefB) for Channel B Note that the output voltage cannot exceed the supply voltage from pin 1 (VDD).

Example:

setVoltage_buffered(channel, value)

Using the buffer feature of the MCP4922, refer to the datasheet for details.

Example:

shutdown(channel)

Completely shutdown selected channel for power saving. Sets the output of selected channel to 0 and 500K Ohms. Read Datasheet (SHDN) for details.

Example:


Download @: https://github.com/mrwunderbar666/Python-RPi-MCP4922

Python-RPi-MCP4922-master

Afmetingen

GEEN GEGEVENS

Schema

GEEN GEGEVENS

Teardown

GEEN GEGEVENS

Datasheet

Fritzing

GEEN GEGEVENS

Downloads

GEEN GEGEVENS