Main Page   Modules   Data Structures   File List   Data Fields   Globals  

a2d.h

Go to the documentation of this file.
00001 /*! \file a2d.h \brief Analog-to-Digital converter function library. */
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  : 4
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 #define ADC_PRESCALE_DIV2       0x00    ///< 0x01,0x00 -> CPU clk/2
00029 #define ADC_PRESCALE_DIV4       0x02    ///< 0x02 -> CPU clk/4
00030 #define ADC_PRESCALE_DIV8       0x03    ///< 0x03 -> CPU clk/8
00031 #define ADC_PRESCALE_DIV16      0x04    ///< 0x04 -> CPU clk/16
00032 #define ADC_PRESCALE_DIV32      0x05    ///< 0x05 -> CPU clk/32
00033 #define ADC_PRESCALE_DIV64      0x06    ///< 0x06 -> CPU clk/64
00034 #define ADC_PRESCALE_DIV128     0x07    ///< 0x07 -> CPU clk/128
00035 // default value
00036 #define ADC_PRESCALE            ADC_PRESCALE_DIV64
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 #define ADC_REFERENCE_AREF      0x00    ///< 0x00 -> AREF pin, internal VREF turned off
00044 #define ADC_REFERENCE_AVCC      0x01    ///< 0x01 -> AVCC pin, internal VREF turned off
00045 #define ADC_REFERENCE_RSVD      0x02    ///< 0x02 -> Reserved
00046 #define ADC_REFERENCE_256V      0x03    ///< 0x03 -> Internal 2.56V VREF
00047 // default value
00048 #define ADC_REFERENCE           ADC_REFERENCE_AVCC
00049 // do not change the mask value
00050 #define ADC_REFERENCE_MASK      0xC0
00051 
00052 // bit mask for A2D channel multiplexer
00053 #define ADC_MUX_MASK            0x1F
00054 
00055 // channel defines (for reference and use in code)
00056 // these channels supported by all AVRs with A2D
00057 #define ADC_CH_ADC0             0x00
00058 #define ADC_CH_ADC1             0x01
00059 #define ADC_CH_ADC2             0x02
00060 #define ADC_CH_ADC3             0x03
00061 #define ADC_CH_ADC4             0x04
00062 #define ADC_CH_ADC5             0x05
00063 #define ADC_CH_ADC6             0x06
00064 #define ADC_CH_ADC7             0x07
00065 #define ADC_CH_122V             0x1E    // 1.22V voltage reference
00066 #define ADC_CH_AGND             0x1F    // AGND
00067 // these channels supported only in ATmega128
00068 // differential with gain
00069 #define ADC_CH_0_0_DIFF10X      0x08
00070 #define ADC_CH_1_0_DIFF10X      0x09
00071 #define ADC_CH_0_0_DIFF200X     0x0A
00072 #define ADC_CH_1_0_DIFF200X     0x0B
00073 #define ADC_CH_2_2_DIFF10X      0x0C
00074 #define ADC_CH_3_2_DIFF10X      0x0D
00075 #define ADC_CH_2_2_DIFF200X     0x0E
00076 #define ADC_CH_3_2_DIFF200X     0x0F
00077 // differential
00078 #define ADC_CH_0_1_DIFF1X       0x10
00079 #define ADC_CH_1_1_DIFF1X       0x11
00080 #define ADC_CH_2_1_DIFF1X       0x12
00081 #define ADC_CH_3_1_DIFF1X       0x13
00082 #define ADC_CH_4_1_DIFF1X       0x14
00083 #define ADC_CH_5_1_DIFF1X       0x15
00084 #define ADC_CH_6_1_DIFF1X       0x16
00085 #define ADC_CH_7_1_DIFF1X       0x17
00086 
00087 #define ADC_CH_0_2_DIFF1X       0x18
00088 #define ADC_CH_1_2_DIFF1X       0x19
00089 #define ADC_CH_2_2_DIFF1X       0x1A
00090 #define ADC_CH_3_2_DIFF1X       0x1B
00091 #define ADC_CH_4_2_DIFF1X       0x1C
00092 #define ADC_CH_5_2_DIFF1X       0x1D
00093 
00094 // compatibility for new Mega processors
00095 // ADCSR hack apparently no longer necessary in new AVR-GCC
00096 #ifdef ADCSRA
00097 #ifndef ADCSR
00098     #define ADCSR   ADCSRA
00099 #endif
00100 #endif
00101 #ifdef ADATE
00102     #define ADFR    ADATE
00103 #endif
00104 
00105 // function prototypes
00106 
00107 //! Initializes the A/D converter
00108 // (turns ADC on and prepares it for use)
00109 void a2dInit(void);
00110 
00111 //! Turn off A/D converter
00112 void a2dOff(void);
00113 
00114 //! sets the division ratio of the A/D converter clock
00115 // this function is automatically called from a2dInit()
00116 // with a default value
00117 void a2dSetPrescaler(unsigned char prescale);
00118 
00119 //! configures which voltage reference the A/D converter uses
00120 // this function is automatically called from a2dInit()
00121 // with a default value
00122 void a2dSetReference(unsigned char ref);
00123 
00124 //! sets the a2d input channel
00125 void a2dSetChannel(unsigned char ch);
00126 
00127 //! start a conversion on the current a2d input channel
00128 void a2dStartConvert(void);
00129 
00130 //! return TRUE if conversion is complete
00131 u08 a2dIsComplete(void);
00132 
00133 //! starts a conversion on A/D channel# ch,
00134 // returns the 10-bit value of the conversion when it is finished
00135 unsigned short a2dConvert10bit(unsigned char ch);
00136 
00137 //! starts a conversion on A/D channel# ch,
00138 // returns the 8-bit value of the conversion when it is finished
00139 unsigned char a2dConvert8bit(unsigned char ch);
00140 
00141 #endif

Generated on Sun Feb 22 19:12:30 2004 for Procyon AVRlib by doxygen1.3-rc2