2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: adc.h,v 1.7.4.3 2007-09-06 08:15:37 zer0 Exp $
22 * \brief Interface of the ADC Module
24 * \todo some ATtiny support to add
28 * This module provides access to the built-in ADC unit of the AVR
38 #include <adc_archs.h>
39 #include <adc_config.h>
42 * You must always specify a MUX and a REF flag.
43 * MUX selection flags :
45 * A lot of them exist, for more, see the capabilities of your uC in
46 * the datasheet. Typical examples:
48 * MUX_ADC0 : selects input 0
49 * MUX_ADC0_ADC1 : selects the electrical signal ADC0-ADC1
50 * MUX_ADC0_ADC1_GAIN10 : selects the electrical signal (ADC0-ADC1) *10
52 * MUX_VBG : selects the internal bandgap reference
53 * MUX_GND : selects the GND pin (0V)
55 * See your Datasheet, and adc_archs.h for more info.
59 * Reference flags : use one of these four :
61 * ADC_REF_AREF : a reference must be connected to the AREF pin :
63 * ADC_REF_AVCC : using AVCC as reference : recommended for default !!!
64 * ADC_REF_VREF : using the internal reference
65 * ADC_REF_VREF2 : internal ref, with options. Beware, this does not
66 * work on all devices, see your Datasheet !!
68 * For some controllers (actually only ATtiny25-45-85) you can specify
69 * more options, just use (1<<REFS2)|(1<<REFS0)
71 * YOU NEED TO SPECIFY THIS VALUE FOR EACH CONVERSION CONFIGURATION !!!!!
76 * Set this flag for using interruptions instead of polling.
77 * If you use this, do not call the adc_get_value() function !
79 #define ADC_MODE_INT 0x0200
82 * Flag for triggered mode.
84 #define ADC_MODE_TRIGGERED 0x0400
87 * Using one of this flags selects in which form the result is given
89 * These flags select the output format. The signed options are only
90 * for the differential measurement ! Don't use them for single ended
91 * measurements, or the results will be wrong.
93 * ADC_MODE_10_BITS : This format will give you a result between 0 and
94 * 1023 This format is default, you do not need to
97 * ADC_MODE_16_BITS : This will use all the span of the uint16_t (or
98 * int16_t for a differential conversion) beware !!
99 * Cast your result in the correct type since the
100 * type depends of the type of channel you select.
102 #define ADC_MODE_10_BITS 0
103 #define ADC_MODE_16_BITS ADLAR_MASK_IN_CONFIG
106 * this flag is used internally of the module, use it only if you set
107 * manually a differential channel.
109 #define ADC_RESULT_SIGNED 0x1000
113 * This specifies a conversion with no config (uses the previous
114 * parameters) always use this flag alone !!
116 #define ADC_NO_CONFIG 0xFFFF
123 * Initialisation of ADC internal registers
124 * Can be called for a wake up after a shutdown command
129 * Shut down the ADC, for power consumption
131 void adc_shutdown(void);
135 * Register callback event. The parameter function is called when the
136 * conversion is finished.
138 void adc_register_event(void (*f)(int16_t));
143 * Launch a conversion : this function launches a conversion with the
144 * specified configuration. The conversion_config is casted to an
147 void adc_launch(uint16_t conversion_config);
151 * This function gets an ADC value. If a conversion has been
152 * previously started, with EXACTLY the same config (or specifying
153 * ADC_NO_CONFIG) then it waits for it to finish. Else it launches a
154 * new one with the given config, and polls the result.
156 * This function should not be used if you use interrupts, but only
157 * can be used with triggered (or free run mode)
159 int16_t adc_get_value(uint16_t conversion_config);
163 * Just a int32_t version for compatibility with control_system
164 * function prototypes.
166 extern int32_t adc_get_value32(void * conversion_config);