Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

# 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 /// \ingroup driver_avr
    00017 /// \defgroup a2d A/D Converter Function Library (a2d.c)
    00018 /// \code #include "a2d.h" \endcode
    00019 /// \par Overview
    00020 ///     This library provides an easy interface to the analog-to-digital
    00021 ///     converter available on many AVR processors.  Updated to support
    00022 ///     the ATmega128.
    00023 //
    00024 //****************************************************************************
    00025 //@{
    00026
    00027 #ifndef A2D_H
    00028 #define A2D_H
    00029
    00030 // defines
    00031
    00032 // A2D clock prescaler select
    00033 //      *selects how much the CPU clock frequency is divided
    00034 //      to create the A2D clock frequency
    00035 //      *lower division ratios make conversion go faster
    00036 //      *higher division ratios make conversions more accurate
    00037 #define ADC_PRESCALE_DIV2       0x00    ///< 0x01,0x00 -> CPU clk/2
    00038 #define ADC_PRESCALE_DIV4       0x02    ///< 0x02 -> CPU clk/4
    00039 #define ADC_PRESCALE_DIV8       0x03    ///< 0x03 -> CPU clk/8
    00040 #define ADC_PRESCALE_DIV16      0x04    ///< 0x04 -> CPU clk/16
    00041 #define ADC_PRESCALE_DIV32      0x05    ///< 0x05 -> CPU clk/32
    00042 #define ADC_PRESCALE_DIV64      0x06    ///< 0x06 -> CPU clk/64
    00043 #define ADC_PRESCALE_DIV128     0x07    ///< 0x07 -> CPU clk/128
    00044 // default value
    00045 #define ADC_PRESCALE            ADC_PRESCALE_DIV64
    00046 // do not change the mask value
    00047 #define ADC_PRESCALE_MASK       0x07
    00048
    00049 // A2D voltage reference select
    00050 //      *this determines what is used as the
    00051 //      full-scale voltage point for A2D conversions
    00052 #define ADC_REFERENCE_AREF      0x00    ///< 0x00 -> AREF pin, internal VREF turned off
    00053 #define ADC_REFERENCE_AVCC      0x01    ///< 0x01 -> AVCC pin, internal VREF turned off
    00054 #define ADC_REFERENCE_RSVD      0x02    ///< 0x02 -> Reserved
    00055 #define ADC_REFERENCE_256V      0x03    ///< 0x03 -> Internal 2.56V VREF
    00056 // default value
    00057 #define ADC_REFERENCE           ADC_REFERENCE_AVCC
    00058 // do not change the mask value
    00059 #define ADC_REFERENCE_MASK      0xC0
    00060
    00061 // bit mask for A2D channel multiplexer
    00062 #define ADC_MUX_MASK            0x1F
    00063
    00064 // channel defines (for reference and use in code)
    00065 // these channels supported by all AVRs with A2D
    00066 #define ADC_CH_ADC0             0x00
    00067 #define ADC_CH_ADC1             0x01
    00068 #define ADC_CH_ADC2             0x02
    00069 #define ADC_CH_ADC3             0x03
    00070 #define ADC_CH_ADC4             0x04
    00071 #define ADC_CH_ADC5             0x05
    00072 #define ADC_CH_ADC6             0x06
    00073 #define ADC_CH_ADC7             0x07
    00074 #define ADC_CH_122V             0x1E    ///< 1.22V voltage reference
    00075 #define ADC_CH_AGND             0x1F    ///< AGND
    00076 // these channels supported only in ATmega128
    00077 // differential with gain
    00078 #define ADC_CH_0_0_DIFF10X      0x08
    00079 #define ADC_CH_1_0_DIFF10X      0x09
    00080 #define ADC_CH_0_0_DIFF200X     0x0A
    00081 #define ADC_CH_1_0_DIFF200X     0x0B
    00082 #define ADC_CH_2_2_DIFF10X      0x0C
    00083 #define ADC_CH_3_2_DIFF10X      0x0D
    00084 #define ADC_CH_2_2_DIFF200X     0x0E
    00085 #define ADC_CH_3_2_DIFF200X     0x0F
    00086 // differential
    00087 #define ADC_CH_0_1_DIFF1X       0x10
    00088 #define ADC_CH_1_1_DIFF1X       0x11
    00089 #define ADC_CH_2_1_DIFF1X       0x12
    00090 #define ADC_CH_3_1_DIFF1X       0x13
    00091 #define ADC_CH_4_1_DIFF1X       0x14
    00092 #define ADC_CH_5_1_DIFF1X       0x15
    00093 #define ADC_CH_6_1_DIFF1X       0x16
    00094 #define ADC_CH_7_1_DIFF1X       0x17
    00095
    00096 #define ADC_CH_0_2_DIFF1X       0x18
    00097 #define ADC_CH_1_2_DIFF1X       0x19
    00098 #define ADC_CH_2_2_DIFF1X       0x1A
    00099 #define ADC_CH_3_2_DIFF1X       0x1B
    00100 #define ADC_CH_4_2_DIFF1X       0x1C
    00101 #define ADC_CH_5_2_DIFF1X       0x1D
    00102
    00103 // compatibility for new Mega processors
    00104 // ADCSR hack apparently no longer necessary in new AVR-GCC
    00105 #ifdef ADCSRA
    00106 #ifndef ADCSR
    00107     #define ADCSR   ADCSRA
    00108 #endif
    00109 #endif
    00110 #ifdef ADATE
    00111     #define ADFR    ADATE
    00112 #endif
    00113
    00114 // function prototypes
    00115
    00116 //! Initializes the A/D converter.
    00117 /// Turns ADC on and prepares it for use.
    00118 void a2dInit(void);
    00119
    00120 //! Turn off A/D converter
    00121 void a2dOff(void);
    00122
    00123 //! Sets the division ratio of the A/D converter clock.
    00124 /// This function is automatically called from a2dInit()
    00125 /// with a default value.
    00126 void a2dSetPrescaler(unsigned char prescale);
    00127
    00128 //! Configures which voltage reference the A/D converter uses.
    00129 /// This function is automatically called from a2dInit()
    00130 /// with a default value.
    00131 void a2dSetReference(unsigned char ref);
    00132
    00133 //! sets the a2d input channel
    00134 void a2dSetChannel(unsigned char ch);
    00135
    00136 //! start a conversion on the current a2d input channel
    00137 void a2dStartConvert(void);
    00138
    00139 //! return TRUE if conversion is complete
    00140 u08 a2dIsComplete(void);
    00141
    00142 //! Starts a conversion on A/D channel# ch,
    00143 /// returns the 10-bit value of the conversion when it is finished.
    00144 unsigned short a2dConvert10bit(unsigned char ch);
    00145
    00146 //! Starts a conversion on A/D channel# ch,
    00147 /// returns the 8-bit value of the conversion when it is finished.
    00148 unsigned char a2dConvert8bit(unsigned char ch);
    00149
    00150 #endif
    00151 //@}