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

# a2d.c

    00001 /*! \file a2d.c \brief Analog-to-digital Converter Driver for ADuC7000. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'a2d.c'
    00005 // Title        : Analog-to-digital Converter Driver for ADuC7000
    00006 // Author       : Pascal Stang - Copyright (C) 2005
    00007 // Created      : 2/5/2005
    00008 // Revised      : 2/5/2005
    00009 // Version      : 0.1
    00010 // Target MCU   : Analog Devices ADuC7000 ARM 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 #include "aduc7026.h"
    00019
    00020 #include "global.h"
    00021 #include "a2d.h"
    00022
    00023 // functions
    00024 void a2dInit(void)
    00025 {
    00026     #define ADCENCONV           (1<<7)
    00027     #define ADCBUSY             (1<<6)
    00028     #define ADCPWR              (1<<5)
    00029     #define ADCMODE_SE          (0x00<<3)
    00030     #define ADCMODE_DIFF        (0x01<<3)
    00031     #define ADCMODE_PDIFF       (0x02<<3)
    00032     #define ADCMODE_MASK        (0x03<<3)
    00033     #define ADCCONV_SINGLE      (0x03)
    00034     #define ADCCONV_CONT        (0x04)
    00035
    00036     // set ADC to ON
    00037     ADCCON |= ADCPWR;
    00038
    00039     // select reference
    00040     REFCON = 0x01;  // internal 2.5V reference
    00041 }
    00042
    00043 int a2dConvert(int channel)
    00044 {
    00045     // set conversion mode to single-ended
    00046     ADCCON &= ~ADCMODE_MASK;
    00047     ADCCON |= ADCMODE_SE;
    00048     // set channel for conversion
    00049     ADCCP = channel;
    00050     // start conversion
    00051     ADCCON |= ADCENCONV | ADCCONV_SINGLE;
    00052     // wait until complete
    00053     while(!ADCSTA);
    00054     // return result
    00055     return ADCDAT>>16;
    00056 }