?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file ads7828.c \brief TI ADS7828 12-bit 8ch A/D Converter Driver Library. */
2 //*****************************************************************************
3 //
4 // File Name : 'ads7828.c'
5 // Title : TI ADS7828 12-bit 8ch A/D Converter Driver Library
6 // Author : Pascal Stang - Copyright (C) 2004
7 // Created : 2004.02.10
8 // Revised : 2004.02.19
9 // Version : 0.1
10 // Target MCU : Atmel AVR Series
11 // Editor Tabs : 4
12 //
13 // NOTE: This code is currently below version 1.0, and therefore is considered
14 // to be lacking in some functionality or documentation, or may not be fully
15 // tested. Nonetheless, you can expect most functions to work.
16 //
17 // This code is distributed under the GNU Public License
18 // which can be found at http://www.gnu.org/licenses/gpl.txt
19 //
20 //*****************************************************************************
21  
22 #include <avr/io.h>
23 #include <avr/interrupt.h>
24  
25 #include "global.h"
26 #include "i2c.h"
27 #include "ads7828.h"
28  
29 // global variables
30 u08 Ads7282RefMode;
31  
32 // Functions
33 u08 ads7828Init(u08 i2cAddr)
34 {
35 u08 channel = 0x80;
36  
37 // setup default A/D voltage reference
38 ads7828SetReference(0);
39  
40 // issue a convserion to test chip presence
41 // return TRUE if chip detected
42 // return FALSE if chip does not respond
43 return (i2cMasterSendNI(i2cAddr, 1, &channel) == I2C_OK);
44 }
45  
46 u16 ads7828Convert(u08 i2cAddr, u08 channel)
47 {
48 // re-order channel bits for
49 // logical single-ended channel selection
50 // channel bit0 -> C2
51 // channel bit1 -> C0
52 // channel bit2 -> C1
53 channel = (((channel>>1) | (channel&0x01)<<2)<<4) | ADS7828_CMD_SD;
54 // do conversion
55 return ads7828ConvertRaw(i2cAddr, channel);
56 }
57  
58 u16 ads7828ConvertDiff(u08 i2cAddr, u08 channel)
59 {
60 // clear single-ended channel bit
61 channel = (channel&0x07)<<4;
62 // do conversion
63 return ads7828ConvertRaw(i2cAddr, channel);
64 }
65  
66 u16 ads7828ConvertRaw(u08 i2cAddr, u08 channel)
67 {
68 u08 buffer[2];
69 // combine raw channel and reference bits
70 channel &= 0xF0;
71 channel |= Ads7282RefMode;
72 // start conversion on requested channel
73 i2cMasterSendNI(i2cAddr, 1, &channel);
74 // retrieve conversion result
75 i2cMasterReceiveNI(i2cAddr, 2, buffer);
76 // pack bytes and return result
77 return ((buffer[0]<<8) | buffer[1]);
78 }
79  
80 void ads7828SetReference(u08 ref)
81 {
82 if(ref)
83 {
84 // use internal reference
85 Ads7282RefMode = ADS7828_CMD_PDMODE2;
86 }
87 else
88 {
89 // use external reference
90 Ads7282RefMode = ADS7828_CMD_PDMODE0;
91 }
92 }
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3