| Line No. | Rev | Author | Line |
|---|---|---|---|
| 1 | 6 | kaklik | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| 2 | <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> |
||
| 3 | <title>Procyon AVRlib: ads7828.c Source File</title> |
||
| 4 | <link href="dox.css" rel="stylesheet" type="text/css"> |
||
| 5 | </head><body> |
||
| 6 | <!-- Generated by Doxygen 1.4.2 --> |
||
| 7 | <div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
||
| 8 | <h1>ads7828.c</h1><a href="ads7828_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file ads7828.c \brief TI ADS7828 12-bit 8ch A/D Converter Driver Library. */</span> |
||
| 9 | 00002 <span class="comment">//*****************************************************************************</span> |
||
| 10 | 00003 <span class="comment">//</span> |
||
| 11 | 00004 <span class="comment">// File Name : 'ads7828.c'</span> |
||
| 12 | 00005 <span class="comment">// Title : TI ADS7828 12-bit 8ch A/D Converter Driver Library</span> |
||
| 13 | 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2004</span> |
||
| 14 | 00007 <span class="comment">// Created : 2004.02.10</span> |
||
| 15 | 00008 <span class="comment">// Revised : 2004.02.19</span> |
||
| 16 | 00009 <span class="comment">// Version : 0.1</span> |
||
| 17 | 00010 <span class="comment">// Target MCU : Atmel AVR Series</span> |
||
| 18 | 00011 <span class="comment">// Editor Tabs : 4</span> |
||
| 19 | 00012 <span class="comment">//</span> |
||
| 20 | 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span> |
||
| 21 | 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span> |
||
| 22 | 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span> |
||
| 23 | 00016 <span class="comment">//</span> |
||
| 24 | 00017 <span class="comment">// This code is distributed under the GNU Public License</span> |
||
| 25 | 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span> |
||
| 26 | 00019 <span class="comment">//</span> |
||
| 27 | 00020 <span class="comment">//*****************************************************************************</span> |
||
| 28 | 00021 |
||
| 29 | 00022 <span class="preprocessor">#include <avr/io.h></span> |
||
| 30 | 00023 <span class="preprocessor">#include <avr/interrupt.h></span> |
||
| 31 | 00024 |
||
| 32 | 00025 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> |
||
| 33 | 00026 <span class="preprocessor">#include "<a class="code" href="i2c_8h.html">i2c.h</a>"</span> |
||
| 34 | 00027 <span class="preprocessor">#include "<a class="code" href="ads7828_8h.html">ads7828.h</a>"</span> |
||
| 35 | 00028 |
||
| 36 | 00029 <span class="comment">// global variables</span> |
||
| 37 | 00030 u08 Ads7282RefMode; |
||
| 38 | 00031 |
||
| 39 | 00032 <span class="comment">// Functions</span> |
||
| 40 | <a name="l00033"></a><a class="code" href="group__ads7828.html#ga0">00033</a> u08 <a class="code" href="group__ads7828.html#ga0">ads7828Init</a>(u08 i2cAddr) |
||
| 41 | 00034 { |
||
| 42 | 00035 u08 channel = 0x80; |
||
| 43 | 00036 |
||
| 44 | 00037 <span class="comment">// setup default A/D voltage reference</span> |
||
| 45 | 00038 <a class="code" href="group__ads7828.html#ga1">ads7828SetReference</a>(0); |
||
| 46 | 00039 |
||
| 47 | 00040 <span class="comment">// issue a convserion to test chip presence</span> |
||
| 48 | 00041 <span class="comment">// return TRUE if chip detected</span> |
||
| 49 | 00042 <span class="comment">// return FALSE if chip does not respond</span> |
||
| 50 | 00043 <span class="keywordflow">return</span> (<a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &channel) == I2C_OK); |
||
| 51 | 00044 } |
||
| 52 | 00045 |
||
| 53 | <a name="l00046"></a><a class="code" href="group__ads7828.html#ga2">00046</a> u16 <a class="code" href="group__ads7828.html#ga2">ads7828Convert</a>(u08 i2cAddr, u08 channel) |
||
| 54 | 00047 { |
||
| 55 | 00048 <span class="comment">// re-order channel bits for</span> |
||
| 56 | 00049 <span class="comment">// logical single-ended channel selection</span> |
||
| 57 | 00050 <span class="comment">// channel bit0 -> C2</span> |
||
| 58 | 00051 <span class="comment">// channel bit1 -> C0</span> |
||
| 59 | 00052 <span class="comment">// channel bit2 -> C1</span> |
||
| 60 | 00053 channel = (((channel>>1) | (channel&0x01)<<2)<<4) | <a class="code" href="group__ads7828.html#ga11">ADS7828_CMD_SD</a>; |
||
| 61 | 00054 <span class="comment">// do conversion</span> |
||
| 62 | 00055 <span class="keywordflow">return</span> <a class="code" href="group__ads7828.html#ga4">ads7828ConvertRaw</a>(i2cAddr, channel); |
||
| 63 | 00056 } |
||
| 64 | 00057 |
||
| 65 | <a name="l00058"></a><a class="code" href="group__ads7828.html#ga3">00058</a> u16 <a class="code" href="group__ads7828.html#ga3">ads7828ConvertDiff</a>(u08 i2cAddr, u08 channel) |
||
| 66 | 00059 { |
||
| 67 | 00060 <span class="comment">// clear single-ended channel bit</span> |
||
| 68 | 00061 channel = (channel&0x07)<<4; |
||
| 69 | 00062 <span class="comment">// do conversion</span> |
||
| 70 | 00063 <span class="keywordflow">return</span> <a class="code" href="group__ads7828.html#ga4">ads7828ConvertRaw</a>(i2cAddr, channel); |
||
| 71 | 00064 } |
||
| 72 | 00065 |
||
| 73 | <a name="l00066"></a><a class="code" href="group__ads7828.html#ga4">00066</a> u16 <a class="code" href="group__ads7828.html#ga4">ads7828ConvertRaw</a>(u08 i2cAddr, u08 channel) |
||
| 74 | 00067 { |
||
| 75 | 00068 u08 buffer[2]; |
||
| 76 | 00069 <span class="comment">// combine raw channel and reference bits</span> |
||
| 77 | 00070 channel &= 0xF0; |
||
| 78 | 00071 channel |= Ads7282RefMode; |
||
| 79 | 00072 <span class="comment">// start conversion on requested channel</span> |
||
| 80 | 00073 <a class="code" href="i2c_8c.html#a24">i2cMasterSendNI</a>(i2cAddr, 1, &channel); |
||
| 81 | 00074 <span class="comment">// retrieve conversion result</span> |
||
| 82 | 00075 <a class="code" href="i2c_8c.html#a25">i2cMasterReceiveNI</a>(i2cAddr, 2, buffer); |
||
| 83 | 00076 <span class="comment">// pack bytes and return result</span> |
||
| 84 | 00077 <span class="keywordflow">return</span> ((buffer[0]<<8) | buffer[1]); |
||
| 85 | 00078 } |
||
| 86 | 00079 |
||
| 87 | <a name="l00080"></a><a class="code" href="group__ads7828.html#ga1">00080</a> <span class="keywordtype">void</span> <a class="code" href="group__ads7828.html#ga1">ads7828SetReference</a>(u08 ref) |
||
| 88 | 00081 { |
||
| 89 | 00082 <span class="keywordflow">if</span>(ref) |
||
| 90 | 00083 { |
||
| 91 | 00084 <span class="comment">// use internal reference</span> |
||
| 92 | 00085 Ads7282RefMode = <a class="code" href="group__ads7828.html#ga22">ADS7828_CMD_PDMODE2</a>; |
||
| 93 | 00086 } |
||
| 94 | 00087 <span class="keywordflow">else</span> |
||
| 95 | 00088 { |
||
| 96 | 00089 <span class="comment">// use external reference</span> |
||
| 97 | 00090 Ads7282RefMode = <a class="code" href="group__ads7828.html#ga20">ADS7828_CMD_PDMODE0</a>; |
||
| 98 | 00091 } |
||
| 99 | 00092 } |
||
| 100 | </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by |
||
| 101 | <a href="http://www.doxygen.org/index.html"> |
||
| 102 | <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address> |
||
| 103 | </body> |
||
| 104 | </html> |
Powered by WebSVN v2.8.3