ConfigADC.c

00001 /***************************************************************************** 00002 * * 00003 * ********** * 00004 * ************ * 00005 * *** *** * 00006 * *** +++ *** * 00007 * *** + + *** * 00008 * *** + CHIPCON CC1010 * 00009 * *** + + *** HAL - ConfigADC * 00010 * *** +++ *** * 00011 * *** *** * 00012 * *********** * 00013 * ********* * 00014 * * 00015 ***************************************************************************** 00016 * * 00017 ***************************************************************************** 00018 * Author: ROH * 00019 ***************************************************************************** 00020 * Revision history: * 00021 * * 00022 * $Log: ConfigADC.c,v $ 00023 * Revision 1.1 2002/10/14 13:04:29 tos 00024 * Initial version in CVS. 00025 * 00026 * * 00027 ****************************************************************************/ 00028 00029 #include <chipcon/hal.h> 00030 00031 //---------------------------------------------------------------------------- 00032 // bool halConfigADC(...) 00033 // 00034 // Description: 00035 // This function configures the ADC. The _option_ argument is used to 00036 // select operational mode, _clkFreq_ gives the device clock frequency in 00037 // kHz, and _threshold_ is used to set the threshold value for some 00038 // operational modes. An interrupt is generated in all modes (except 00039 // for reset-generating mode in which a reset is generated instead) whenever 00040 // the 8 MSB of the measured sample is greater or equal to the threshold 00041 // value. Thus, if an interrupt for each sample is desired, the threshold 00042 // should be set to 0 (and the ADC and GLOBAL_ADC_DES interrupts enabled.) 00043 // After configuring the ADC it must be powered up using the ADC_POWER(bool) 00044 // macro. It should be powered down again when not in use to conserve power. 00045 // The correct ADC input must be selected using the ADC_SELECT_INPUT(input) 00046 // macro and started using the ADC_RUN(bool) macro for continuous modes. 00047 // The ADC_SAMPLE_SINGLE macro is used to initiate a sample acquisition in 00048 // single-conversion mode, and the ADC_RUNNING macro can be used to 00049 // determine whether the sample is complete 00050 // The ADC_GET_SAMPLE_10BIT or ADC_GET_SAMPLE_8BIT macros return the latest 00051 // sample value. 00052 // 00053 // Arguments: 00054 // byte options 00055 // One or more of the below defined constants define the desired 00056 // operational mode. 00057 // word clkFreq 00058 // The XOSC clock frequency in kHz. 00059 // byte threshold 00060 // The threshold value for generating interrupts (and stopping in 00061 // multi-conversion, stopping mode) or reset (in multi-conversion, 00062 // reset-generating mode). 00063 // 00064 // Return value: 00065 // void 00066 //---------------------------------------------------------------------------- 00067 void halConfigADC(byte options, xdata word clkFreq, xdata byte threshold) { 00068 clkFreq= (clkFreq-250*8)/(250*16); 00069 ADCON2=(options&0x80)|((byte)clkFreq&0x3F); 00070 if (options&ADC_INTERRUPT_ENABLE) { 00071 EXIF&=~0x40; 00072 ADIE=1; 00073 } 00074 ADCON=0x80|(options&0x38); 00075 ADTRH=threshold; 00076 }

Generated on Fri Aug 27 10:04:02 2004 for Cheap Sensor Network by doxygen 1.3.8