adc.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef __ADC_H__
00043 #define __ADC_H__
00044
00045 #include <avr/io.h>
00046 #include <stdio.h>
00047 #include <stdint.h>
00048 #include <stdbool.h>
00049
00050 #define adc_conversion_ongoing (ADCSRA |= (1<<ADSC))
00051 #define adc_conversion_done (!(ADCSRA |= (1<<ADSC)))
00052
00053
00054 typedef enum {
00055 ADC_TRIG_FREE_RUN = ((0<<ADTS2)|(0<<ADTS1)|(0<<ADTS0)),
00056 ADC_TRIG_ANACOMP = ((0<<ADTS2)|(0<<ADTS1)|(1<<ADTS0)),
00057 ADC_TRIG_EXTINT0 = ((0<<ADTS2)|(1<<ADTS1)|(0<<ADTS0)),
00058 ADC_TRIG_TIM0_COMPA = ((0<<ADTS2)|(1<<ADTS1)|(1<<ADTS0)),
00059 ADC_TRIG_TIM0_OVF = ((1<<ADTS2)|(0<<ADTS1)|(0<<ADTS0)),
00060 ADC_TRIG_TIM1_COMPB = ((1<<ADTS2)|(0<<ADTS1)|(1<<ADTS0)),
00061 ADC_TRIG_TIM1_OVF = ((1<<ADTS2)|(1<<ADTS1)|(0<<ADTS0)),
00062 ADC_TRIG_TIM1_CAPT = ((1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0))
00063 } adc_trig_t;
00064
00065
00066 typedef enum {
00067 ADC_PS_2 = ((0<<ADPS2)|(0<<ADPS1)|(1<<ADPS0)),
00068 ADC_PS_4 = ((0<<ADPS2)|(1<<ADPS1)|(0<<ADPS0)),
00069 ADC_PS_8 = ((0<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)),
00070 ADC_PS_16 = ((1<<ADPS2)|(0<<ADPS1)|(0<<ADPS0)),
00071 ADC_PS_32 = ((1<<ADPS2)|(0<<ADPS1)|(1<<ADPS0)),
00072 ADC_PS_64 = ((1<<ADPS2)|(1<<ADPS1)|(0<<ADPS0)),
00073 ADC_PS_128 = ((1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0))
00074 } adc_ps_t;
00075
00076
00077
00078
00079
00080 typedef enum {
00081 ADC_REF_AREF = ((0<<REFS1)|(0<<REFS0)),
00082 ADC_REF_AVCC = ((0<<REFS1)|(1<<REFS0)),
00083 ADC_REF_INT = ((1<<REFS1)|(1<<REFS0))
00084 } adc_ref_t;
00085
00086
00087 typedef enum {
00088 ADC_CHAN_ADC0 = ((0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0)),
00089 ADC_CHAN_ADC1 = ((0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(1<<MUX0)),
00090 ADC_CHAN_ADC2 = ((0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(0<<MUX0)),
00091 ADC_CHAN_ADC3 = ((0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(1<<MUX1)|(1<<MUX0)),
00092 ADC_CHAN_ADC4 = ((0<<MUX4)|(0<<MUX3)|(1<<MUX2)|(0<<MUX1)|(0<<MUX0)),
00093 ADC_CHAN_ADC5 = ((0<<MUX4)|(0<<MUX3)|(1<<MUX2)|(0<<MUX1)|(1<<MUX0)),
00094 ADC_CHAN_ADC6 = ((0<<MUX4)|(0<<MUX3)|(1<<MUX2)|(1<<MUX1)|(0<<MUX0)),
00095 ADC_CHAN_ADC7 = ((0<<MUX4)|(0<<MUX3)|(1<<MUX2)|(1<<MUX1)|(1<<MUX0))
00096 } adc_chan_t;
00097
00098
00099 typedef enum {
00100 ADC_ADJ_RIGHT = 0,
00101 ADC_ADJ_LEFT = 1
00102 } adc_adj_t;
00103
00104 int adc_init(adc_chan_t chan, adc_trig_t trig, adc_ref_t ref, adc_ps_t prescale);
00105 void adc_deinit(void);
00106 int adc_conversion_start(void);
00107 int16_t adc_result_get(adc_adj_t adjust);
00108
00109 #endif
00110