<HTML>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>HiPi::Interface::MCP49XX</title></head>
<BODY TOPMARGIN=4 BGCOLOR=#FFFFFF TEXT=#000000 VLINK=#0000CC LINK=#0000CC ALINK=#0000CC>
<FONT FACE="Arial, Lucida, Helvetica" >
<TABLE WIDTH="100%" ALIGN=CENTER CELLPADDING=1 CELLSPACING=0>
<TR>
<TD WIDTH="100%" ALIGN=CENTER>
<A HREF="contents.htm"><img align=center src="home.png" BORDER=0 ALT="Contents"></A>
<A HREF="mod_interface.htm"><img align=center src="up.png" BORDER=0 ALT="Up"></A>
<A HREF="mod_interface_mcp23S17.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_serlcd.htm"><img align=center src="forward.png" BORDER=0 ALT="Next"></A>
</TD>
</TR>
<TR>
<TD COLSPAN=2 HEIGHT=2 BGCOLOR="#C0C0C0">
</TD>
</TR>
</TABLE>
<H2>HiPi::Interface::MCP49XX</H2><p>This module provides an interface to the MCP49XX and MCP48XX series of digital to analog converters with SPI interface.</p>
<p>The interface should work for any of the MCP4801, MCP4811, MCP4821, MCP4802, MCP4812, MCP4822, MCP4901, MCP4911, MCP4921, MCP4902, MCP4912, and MCP4922 converters according to their datasheets. Code actually tested with a 4902 dual channel converter.</p>
<p>It uses <A HREF="mod_device_spi.htm">HiPi::Device::SPI</A> as a backend</p>
<h2>Object Constructor and Methods</h2>
<h5>my $dac = HiPi::Interface::MCP49XX->new( %params );</h5>
<pre> Returns a new instance of the HiPi::Interface::MCP49XX class.
required key => value pair in %params and its default
type => MCP4902
the type parameter accepts one of the constants below that defines
which type of converter you have
MCP4801 MCP4811 MCP4821 MCP4802 MCP4812 MCP4822
MCP4901 MCP4911 MCP4921 MCP4902 MCP4912 MCP4922
you can import these constants into your namespace using:
use HiPi::Interface::MCP49XX qw( :mcp );
optional key => value pairs that affect the converter
gain => 0,
buffer => 0,
shiftvalue => 0,
gain -- boolean flag -- some of the converters supported allow the
option of multiplying the output voltage to 2x the proportion of the
reference voltage specified by your value setting.
e.g. If you have a 12 bit resolution convertor (max value 4095) and you
specify the max value ( 4095 ), if the reference voltage is 2V5 then
the output voltage will be 5V0.
Set gain => 1 to switch this voltage doubling on.
buffer -- boolean flag determining whether to set the input buffer
control bit on writes. Specified in the MCP4XXX data sheets, I've no
idea what it does. Leaving at 0 ( false ) works for me.
shiftvalue -- boolean flag -- by default ( shiftvalue == 0 ) whatever
the resolution of your particular converter, you should specify values
between 1 and 4095 when writing to the device. This means that all the
supported devices are interchangable and you don't have to alter your
code to suit the different device resolutions.
If, however, you want to specify values in terms of the specific
resolution of your converter
i.e. for an 8 bit converter you want to specify values 0 - 255
for a 10 bit converter you want to specify values 0 - 1023
for a 12 bit converter you want to specify values 0 - 4095
then you should set shiftvalue => 1
optional key => values pairs that are passed to HiPi::Device::SPI
devicename => '/dev/spidev0.0',
speed => SPI_SPEED_MHZ_1,
bitsperword => 8,
delay => 0,
You probably want to specify the devicename explicitly depending
on which cable select pin you have connected the MCP4XXX
For SPI0_CEO_N
my $adc = HiPi::Interface::MCP49XX->new(
devicename => '/dev/spidev0.0',
);
For SPI0_CE1_N
my $adc = HiPi::Interface::MCP49XX->new(
devicename => '/dev/spidev0.1',
);
See <A HREF="topic_gpiopins.htm">Raspberry Pi GPIO Pin layout</A> for pin locations.</pre>
<h5>$dac->write( $value, $channel );</h5>
<pre> $value is the setting you want to apply.
if the current setting of $dac->shiftvalue is false then $value should
be a number between 0 and 4095
if the current setting of $dac->shiftvalue is true then the range for
$value is determined by the resolution of your converter.
i.e. for an 8 bit device you must specify values 0 - 255
for a 10 bit device you must specify values 0 - 1023
for a 12 bit device you must specify values 0 - 4095
$channel is only used when your converter has two channels.
If $channel is 0 or undefined then the write is to channel A
If $channel is any true value and your converter has a second
channel then the write is to channel B.
In your code if dealing with a known 2 channel converter you may
wish to always be explicit
$dev->write( $aval, 0 );
$dev->write( $bval, 1 );
Code that does not specify a channel always writes to channel A and
is portable across all supported converters.</pre>
<h5>$dac->shutdown( $channel );</h5>
<pre> Shutdown the specified channel by passing the flag defined in
the converter datasheets.
$channel is 0 or 1 for channel A or B
defaults to channel A if $channel undefined.</pre>
<h5>$dac->shiftvalue( $optionalnewval );</h5>
<pre> get/set shiftvalue flag true/false</pre>
<h5>$dac->gain( $optionalnewval );</h5>
<pre> get/set gain flag true/false</pre>
<h5>$dac->buffer( $optionalnewval );</h5>
<pre> get/set buffer flag true/false
</pre>
</FONT>
<br>
<p>
<br>
<hr>
<br>
<center>
<A HREF="contents.htm"><img align=center src="home.png" BORDER=0 ALT="Contents"></A>
<A HREF="mod_interface.htm"><img align=center src="up.png" BORDER=0 ALT="Up"></A>
<A HREF="mod_interface_mcp23S17.htm"><img align=center src="back.png" BORDER=0 ALT="Previous"></A>
<A HREF="mod_interface_serlcd.htm"><img align=center src="forward.png" BORDER=0 ALT="Next"></A>
</center>
<HR>
<br>
<center><FONT FACE="Arial, Lucida, Helvetica" size="2" color="#000080">HiPi Modules Copyright © 2013 - 2016 Mark Dootson</font></center>
</BODY></HTML>