Contiki 2.5
Files | Macros | Functions
Analog Digital Converter (ADC)

Files

file  adc-drv.c
 
 ADC driver implementation

 
file  adc-drv.h
 
    ADC driver definitions

 

Macros

#define ADC_SINGLE_CONVERSION   0xFF
 
#define ADC_FREE_RUNNING   0x00
 
#define ADC_ANALOG_COMPARATOR   (1 << ADTS0)
 
#define ADC_EXT_INTERRUPT   (1 << ADTS1)
 
#define ADC_TIMER0_COMP_FLAG   ((1 << ADTS1) | (1 << ADTS0))
 
#define ADC_TIMER0_OVERFLOW   (1 << ADTS2)
 
#define ADC_TIMER1_COMP_FLAG   ((1 << ADTS2) | (1 << ADTS0))
 
#define ADC_TIMER1_OVERFLOW   ((1 << ADTS2) | (1 << ADTS1))
 
#define ADC_TIMER1_CAPTURE   ((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0))
 
#define ADC_REF_AREF   0
 
#define ADC_REF_AVCC   (1 << REFS0)
 
#define ADC_REF_1100MV_INT   (1 << REFS1)
 
#define ADC_REF_2560MV_INT   ((1 << REFS1)| (1 << REFS0))
 

Functions

void adc_init (uint8_t mode, uint8_t ref)
 Initialize the ADC module. More...
 
void adc_set_mux (uint8_t mux)
 With this function you can set the ADX multiplexer. More...
 
uint16_t adc_get_value (void)
 This function returns the ADC data register value. More...
 
uint16_t adc_get_value_from (uint8_t chn)
 This function returns the ADC data register value of the given ADC channel. More...
 
void adc_deinit (void)
 This function stops all running ADC. More...
 

Detailed Description

The ATmega1284p has 8 ADC-channels. You can run the ADC in different modes like just "single coversion", "free running" or "auto triggered" by timer or interrupts. Moreover it is possible to get differential values of two ADC-channels (with or without a gain factor)

Macro Definition Documentation

#define ADC_ANALOG_COMPARATOR   (1 << ADTS0)

mode: ADC Analog Comparator

Note
Sets the ADC to comparator mode.

Definition at line 159 of file adc-drv.h.

#define ADC_EXT_INTERRUPT   (1 << ADTS1)

mode: External Interrupt Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever changes on external interrupt will occur.

Definition at line 165 of file adc-drv.h.

#define ADC_FREE_RUNNING   0x00

mode: ADC Free Running Mode

Note
The ADC runs all the time. An interrupt occurs whenever one ADC cycle will finish

Definition at line 154 of file adc-drv.h.

#define ADC_REF_1100MV_INT   (1 << REFS1)

ref: Internal 1.1V Reference

Note
The ADC reference voltage is provided by internal 1.1V

Definition at line 215 of file adc-drv.h.

#define ADC_REF_2560MV_INT   ((1 << REFS1)| (1 << REFS0))

ref: Internal 2.56V Reference

Note
The ADC reference voltage is provided by internal 2.56V

Definition at line 220 of file adc-drv.h.

#define ADC_REF_AREF   0

ref: External Reference Voltage (Aref)

Note
The ADC reference voltage is provided by the external reference pin Aref

Definition at line 205 of file adc-drv.h.

#define ADC_REF_AVCC   (1 << REFS0)

ref: Supply Voltage Reference (AVcc)

Note
The ADC reference voltage is provided by the supply voltage.

Definition at line 210 of file adc-drv.h.

Referenced by key_init(), and temp_get().

#define ADC_SINGLE_CONVERSION   0xFF

mode: ADC Single Conversion

Note
The ADC will make just one conversion cycle (normal use)

Definition at line 148 of file adc-drv.h.

Referenced by adc_init().

#define ADC_TIMER0_COMP_FLAG   ((1 << ADTS1) | (1 << ADTS0))

mode: Timer0 Compare Flag Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever Timer0 Compare Flag is set.

Definition at line 171 of file adc-drv.h.

#define ADC_TIMER0_OVERFLOW   (1 << ADTS2)

mode: Timer0 Compare Flag Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever Timer0 overflow occurs.

Definition at line 177 of file adc-drv.h.

#define ADC_TIMER1_CAPTURE   ((1 << ADTS2) | (1 << ADTS1) | (1 << ADTS0))

mode: Timer1 Compare Flag Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever Timer0 Capture Flag is set.

Definition at line 195 of file adc-drv.h.

#define ADC_TIMER1_COMP_FLAG   ((1 << ADTS2) | (1 << ADTS0))

mode: Timer1 Compare Flag Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever Timer0 Compare Flag is set.

Definition at line 183 of file adc-drv.h.

#define ADC_TIMER1_OVERFLOW   ((1 << ADTS2) | (1 << ADTS1))

mode: Timer1 Compare Flag Trigger

Note
Enables the auto trigger mode. The ADC will start a conversion, whenever Timer0 overflow occurs.

Definition at line 189 of file adc-drv.h.

Function Documentation

void adc_deinit ( void  )

This function stops all running ADC.

This will disable the adc.

Definition at line 83 of file adc-drv.c.

uint16_t adc_get_value ( void  )

This function returns the ADC data register value.

Use adc_set_mux to preselect the ADC-channel or differential input.

Returns
The ADC-value of preselected mux

Definition at line 65 of file adc-drv.c.

Referenced by adc_get_value_from().

uint16_t adc_get_value_from ( uint8_t  chn)

This function returns the ADC data register value of the given ADC channel.

Parameters
chnThe ADC channel (ADC0 ... ADC7)
Returns
The ADC-value
                       This function is more efficient for the single
                       conversion mode. Just select the ADC channel (or
                       differential settings) and get the result.

Definition at line 78 of file adc-drv.c.

References adc_get_value(), and adc_set_mux().

void adc_init ( uint8_t  mode,
uint8_t  ref 
)

Initialize the ADC module.

Parameters
modeSelect an ADC mode like single conversion or free running, etc.
refThe ADC reference voltage source.

Definition at line 42 of file adc-drv.c.

References ADC_SINGLE_CONVERSION.

void adc_set_mux ( uint8_t  mux)

With this function you can set the ADX multiplexer.

                       Here you select the ADC channel or choose differential
        value between two ADC-channels with or without gain.
Parameters
muxSelect single ADC channel (ADC_CHANNEL_0 ... ADC_CHANNEL_7) or differential input of various ADC-channels with or without gain

Definition at line 53 of file adc-drv.c.

Referenced by adc_get_value_from().