Main Page   Compound List   File List   Compound Members   File Members  

a2d.h

Go to the documentation of this file.
00001 
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'a2d.h'
00005 // Title                        : Analog-to-digital converter functions
00006 // Author               : Pascal Stang - Copyright (C) 2002
00007 // Created              : 4/08/2002
00008 // Revised              : 4/30/2002
00009 // Version              : 1.1
00010 // Target MCU   : Atmel AVR series
00011 // Editor Tabs  : 3
00012 //
00013 // This code is distributed under the GNU Public License
00014 //              which can be found at http://www.gnu.org/licenses/gpl.txt
00015 //
00016 //*****************************************************************************
00017 
00018 #ifndef A2D_H
00019 #define A2D_H
00020 
00021 // defines
00022 
00023 // A2D clock prescaler select
00024 //              *selects how much the CPU clock frequency is divided
00025 //              to create the A2D clock frequency
00026 //              *lower division ratios make conversion go faster
00027 //              *higher division ratios make conversions more accurate
00028 // 0x00 -> CPU clk/2
00029 // 0x01 -> CPU clk/2
00030 // 0x02 -> CPU clk/4
00031 // 0x03 -> CPU clk/8
00032 // 0x04 -> CPU clk/16
00033 // 0x05 -> CPU clk/32
00034 // 0x06 -> CPU clk/64
00035 // 0x07 -> CPU clk/128
00036 #define ADC_PRESCALE                    0x06
00037 // do not change the mask value
00038 #define ADC_PRESCALE_MASK       0x07
00039 
00040 // A2D voltage reference select
00041 //              *this determines what is used as the
00042 //              full-scale voltage point for A2D conversions
00043 // 0x00 -> AREF pin, internal VREF turned off
00044 // 0x01 -> AVCC pin, internal VREF turned off
00045 // 0x02 -> Reserved
00046 // 0x03 -> Internal 2.56V VREF
00047 #define ADC_REFERENCE           0x01
00048 // do not change the mask value
00049 #define ADC_REFERENCE_MASK      0xC0
00050 
00051 // bit mask for A2D channel multiplexer
00052 #define ADC_MUX_MASK            0x1F
00053 
00054 // channel defines (for reference)
00055 // these channels supported by all AVRs with A2D
00056 #define ADC_CH_ADC0                             0x00
00057 #define ADC_CH_ADC1                             0x01
00058 #define ADC_CH_ADC2                             0x02
00059 #define ADC_CH_ADC3                             0x03
00060 #define ADC_CH_ADC4                             0x04
00061 #define ADC_CH_ADC5                             0x05
00062 #define ADC_CH_ADC6                             0x06
00063 #define ADC_CH_ADC7                             0x07
00064 #define ADC_CH_122V                             0x1E    // 1.22V voltage reference
00065 #define ADC_CH_AGND                             0x1F    // AGND
00066 // these channels supported only in ATmega128
00067 // differential with gain
00068 #define ADC_CH_0_0_DIFF10X              0x08
00069 #define ADC_CH_1_0_DIFF10X              0x09
00070 #define ADC_CH_0_0_DIFF200X     0x0A
00071 #define ADC_CH_1_0_DIFF200X     0x0B
00072 #define ADC_CH_2_2_DIFF10X              0x0C
00073 #define ADC_CH_3_2_DIFF10X              0x0D
00074 #define ADC_CH_2_2_DIFF200X     0x0E
00075 #define ADC_CH_3_2_DIFF200X     0x0F
00076 // differential
00077 #define ADC_CH_0_1_DIFF1X               0x10
00078 #define ADC_CH_1_1_DIFF1X               0x11
00079 #define ADC_CH_2_1_DIFF1X               0x12
00080 #define ADC_CH_3_1_DIFF1X               0x13
00081 #define ADC_CH_4_1_DIFF1X               0x14
00082 #define ADC_CH_5_1_DIFF1X               0x15
00083 #define ADC_CH_6_1_DIFF1X               0x16
00084 #define ADC_CH_7_1_DIFF1X               0x17
00085 
00086 #define ADC_CH_0_2_DIFF1X               0x18
00087 #define ADC_CH_1_2_DIFF1X               0x19
00088 #define ADC_CH_2_2_DIFF1X               0x1A
00089 #define ADC_CH_3_2_DIFF1X               0x1B
00090 #define ADC_CH_4_2_DIFF1X               0x1C
00091 #define ADC_CH_5_2_DIFF1X               0x1D
00092 
00093 // function prototypes
00094 
00095 // Initializes the A/D converter
00096 // (turns ADC on and prepares it for use)
00097 void a2dInit(void);
00098 
00099 // Turn off A/D converter
00100 void a2dOff(void);
00101 
00102 // sets the division ratio of the A/D converter clock
00103 // this function is automatically called from a2dInit()
00104 // with a default value
00105 void a2dSetPrescaler(unsigned char prescale);
00106 
00107 // configures which voltage reference the A/D converter uses
00108 // this function is automatically called from a2dInit()
00109 // with a default value
00110 void a2dSetReference(unsigned char ref);
00111 
00112 // starts a conversion on A/D channel# ch,
00113 // returns the value of the conversion when it is finished
00114 unsigned short a2dConvert10bit(unsigned char ch);
00115 unsigned char a2dConvert8bit(unsigned char ch);
00116 
00117 #endif

Generated at Fri Oct 25 15:36:37 2002 for avrlib by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001