MCP4922

MCP4922

This Ada library is designed to format messages for the SPI MCP4922 dual 12-bit DAC chip.

The formatted 2-byte message must be written to the chip by the calling program. This routine simply performs the message formatting function.

API Summary

The public portion of the package spec is as follows:

package MCP4922 is

type Unit_Type is (
    DAC_A,
    DAC_B
);

type Value_Type is range 0 .. 2**12-1;

type Buffering_Type is
    (Buffered,                  -- Requires assertion of /LDAC pin
    Unbuffered                  -- /LDAC tied low
);

type Gain_Type is
    (Gain_1X,                   -- 1X (Vout = Vref * D/4096)
    Gain_2X                     -- 2X (Vout = 2 * Vref * D/4096)
);

------------------------------------------------------------------
-- Create a 2-byte message for the MCP4922 DAC
------------------------------------------------------------------
procedure Format
    (Unit :     in      Unit_Type;                      -- DAC_A or DAC_B
    Value :     in      Value_Type;                     -- Value to xmit
    Buffer :       out  SPI_Data_Type;                  -- Buffer(1..2)
    Buffering : in      Buffering_Type := Unbuffered;   -- /LDAC control
    Gain :      in      Gain_Type := Gain_1X;           -- 1X or 2X Gain
    Shutdown :  in      Boolean := False                -- /Shutdown control
);

end MCP4922;

Type Unit_Type

This type is used to specify which DAC unit is being referenced in the dual DAC chip:

  • DAC_A - references unit A
  • DAC_B - references unit B

Type Buffering_Type

  • Buffered - Write data appears for A and B simultaneously with /LDAC pin assertion.
  • Unbuffered - Write data appears immediately for A or B

Gain_Type

  • Gain_1X - Output gain is unity
  • Gain_2X - Output gain is 2X

Procedure Format

This procedure formats a byte message string to send to the MCP4922 chip, to change a DAC output value.

procedure Format
    (Unit :     in      Unit_Type;                      -- DAC_A or DAC_B
    Value :     in      Value_Type;                     -- Value to xmit
    Buffer :       out  SPI_Data_Type;                  -- Buffer(1..2)
    Buffering : in      Buffering_Type := Unbuffered;   -- /LDAC control
    Gain :      in      Gain_Type := Gain_1X;           -- 1X or 2X Gain
    Shutdown :  in      Boolean := False                -- /Shutdown control
);
  • Unit - selects DAC unit A or B.
  • Value - the 12-bit value to be sent to the DAC unit.
  • Buffer - will receive the two byte message that is being created for the DAC chip.
  • Buffering - selects whether un/buffered outputs will be used.
  • Gain - Use unity or 2X gain
  • Shutdown - Normally false, but when true shuts down the chip to save power

Related

Wiki: Examples
Wiki: Home
Wiki: Setup

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks