00001 /* 00002 * Copyright Droids Corporation, Microb Technology, Eirbot (2005) 00003 * 00004 * This program is free software; you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation; either version 2 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Revision : $Id: adc.h,v 1.9 2008-01-08 20:05:04 zer0 Exp $ 00019 * 00020 */ 00033 #ifndef _ADC_H_ 00034 #define _ADC_H_ 00035 00036 #include <aversive.h> 00037 00038 #include <adc_archs.h> 00039 #include <adc_config.h> 00040 00041 /* 00042 * You must always specify a MUX and a REF flag. 00043 * MUX selection flags : 00044 * 00045 * A lot of them exist, for more, see the capabilities of your uC in 00046 * the datasheet. Typical examples: 00047 * 00048 * MUX_ADC0 : selects input 0 00049 * MUX_ADC0_ADC1 : selects the electrical signal ADC0-ADC1 00050 * MUX_ADC0_ADC1_GAIN10 : selects the electrical signal (ADC0-ADC1) *10 00051 * ... 00052 * MUX_VBG : selects the internal bandgap reference 00053 * MUX_GND : selects the GND pin (0V) 00054 * 00055 * See your Datasheet, and adc_archs.h for more info. 00056 * 00057 * 00058 * 00059 * Reference flags : use one of these four : 00060 * 00061 * ADC_REF_AREF : a reference must be connected to the AREF pin : 00062 * default 00063 * ADC_REF_AVCC : using AVCC as reference : recommended for default !!! 00064 * ADC_REF_VREF : using the internal reference 00065 * ADC_REF_VREF2 : internal ref, with options. Beware, this does not 00066 * work on all devices, see your Datasheet !! 00067 * 00068 * For some controllers (actually only ATtiny25-45-85) you can specify 00069 * more options, just use (1<<REFS2)|(1<<REFS0) 00070 * 00071 * YOU NEED TO SPECIFY THIS VALUE FOR EACH CONVERSION CONFIGURATION !!!!! 00072 */ 00073 00074 00079 #define ADC_MODE_INT 0x0200 00080 00084 #define ADC_MODE_TRIGGERED 0x0400 00085 00086 /* 00087 * Using one of this flags selects in which form the result is given 00088 * 00089 * These flags select the output format. The signed options are only 00090 * for the differential measurement ! Don't use them for single ended 00091 * measurements, or the results will be wrong. 00092 * 00093 * ADC_MODE_10_BITS : This format will give you a result between 0 and 00094 * 1023 This format is default, you do not need to 00095 * specify the flag. 00096 00097 * ADC_MODE_16_BITS : This will use all the span of the uint16_t (or 00098 * int16_t for a differential conversion) beware !! 00099 * Cast your result in the correct type since the 00100 * type depends of the type of channel you select. 00101 */ 00102 #define ADC_MODE_10_BITS 0 00103 #define ADC_MODE_16_BITS ADLAR_MASK_IN_CONFIG 00104 00109 #define ADC_RESULT_SIGNED 0x1000 00110 00111 00116 #define ADC_NO_CONFIG 0xFFFF 00117 00118 00119 /**************/ 00120 00121 00126 void adc_init(void); 00127 00131 void adc_shutdown(void); 00132 00133 00138 void adc_register_event(void (*f)(int16_t)); 00139 00140 00141 00147 void adc_launch(uint16_t conversion_config); 00148 00149 00159 int16_t adc_get_value(uint16_t conversion_config); 00160 00161 00166 extern int32_t adc_get_value32(void * conversion_config); 00167 00168 00169 00170 #endif // _ADC_H_