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 LPC2000. */
    00002 //*****************************************************************************
    00003 //
    00004 // File Name    : 'a2d.c'
    00005 // Title        : Analog-to-Digital Converter Driver for LPC2000
    00006 // Author       : Pascal Stang - Copyright (C) 2006
    00007 // Created      : 2006.04.09
    00008 // Revised      : 2006.04.15
    00009 // Version      : 0.1
    00010 // Target MCU   : LPC2000 ARM processors
    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 // system includes
    00019 #include "lpc2000.h"
    00020 #include "global.h"
    00021
    00022 // local includes
    00023 #include "a2d.h"
    00024
    00025 void a2dInit(void)
    00026 {
    00027     // set ADC to:
    00028     // - CLKDIV as appropriate
    00029     // - single conversion mode
    00030     // - 10-bit accuracy
    00031     // - powered-up
    00032     ADCR = (((PCLK/4500000))<<8) | ADCR_CLKS_10BIT | ADCR_PDN;
    00033 }
    00034
    00035 int a2dConvert(int channel)
    00036 {
    00037     uint32_t result=0;
    00038
    00039     // start conversion on requested channel
    00040     ADCR &= ~(ADCR_SEL_MASK|ADCR_START_NOW);    // clear previous channel and conversion
    00041     ADCR |= (1<<channel);   // select new channel
    00042     ADCR |= ADCR_START_NOW; // start conversion
    00043
    00044     // wait for end-of-conversion
    00045     while(!(result & ADDR_DONE)) result = ADDR;
    00046
    00047     // return data
    00048     return (result & ADDR_VALUE_MASK)>>6;
    00049 }
    00050