#include "main.h"
Defines | |
#define | ADC_BUF_SIZE 1700 |
Size of the input-buffer. | |
Functions | |
void | adc_init (uint8_t channel) |
initialise ADC with "channel" | |
void | adc_select_channel (uint8_t channel) |
select "channel" | |
void | adc_LED (void) |
handels the LED output | |
void | adc_off (void) |
switches the ADC off | |
void | adc_set_nr_channels (int8_t nr) |
sets the nr of active channels | |
void | adc_set_presc (int8_t presc) |
sets the prescaler | |
void | adc_next_channel (void) |
switches to the next channel | |
int8_t | adc_stopped (void) |
checks, whether the ADC has stopped | |
void | adc_stop (void) |
stops the ADC | |
Variables | |
volatile uint8_t | adc [ADC_BUF_SIZE] |
input-buffer | |
volatile uint8_t | adc_channels |
nr of active channels | |
volatile double | adc_duration |
time for one sample point | |
volatile uint8_t | adc_prescaler |
the current prescaler |
Data acquisition.
30 March 2006
Sven Kreiss
|
Size of the input-buffer.
|
|
initialise ADC with "channel"
00104 { 00105 adc_count = 0; 00106 adc_stop_flag = 0; 00107 00108 adc_select_channel(channel); //set the channel 00109 adc_current_channel = channel; //save the number of the current channel 00110 adc_LED(); 00111 00112 ADCSRA = adc_prescaler & 7; //& 7: only assign first three bits 00113 //AD Enable, AD Start Conversion, AD Free Running, AD Interrupt Enable 00114 adc_starttime = us_time_get(); 00115 ADCSRA |= (1<<ADEN) | (1<<ADSC) | (1<<ADFR);//interrupt method: | (1<<ADIE); 00116 00117 if(adc_channels == 1) adc_single_channel(); 00118 else adc_multi_channels(); 00119 00120 //stop adc again 00121 adc_stop(); 00122 }
|
|
handels the LED output
00039 { 00040 if(adc_channels == 1) PORTA = (PORTA & 15) + (8 << 4); //& 15: assign only first 4 bits 00041 if(adc_channels == 2) PORTA = (PORTA & 15) + (12 << 4); //& 15: assign only first 4 bits 00042 if(adc_channels == 3) PORTA = (PORTA & 15) + (14 << 4); //& 15: assign only first 4 bits 00043 if(adc_channels == 4) PORTA = (PORTA & 15) + (15 << 4); //& 15: assign only first 4 bits 00044 }
|
|
switches to the next channel
00057 { 00058 uint8_t new = adc_current_channel; 00059 00060 new++; 00061 if(new > adc_channels) new = 1; 00062 adc_select_channel(new); 00063 }
|
|
switches the ADC off
|
|
select "channel"
00029 { 00030 if(channel == adc_current_channel) return; 00031 adc_current_channel = channel; 00032 00033 //Input Channel selection; obersten beiden bits wählen externe Referenz, wenn 0 00034 //=> ADMUX entspricht Channel 00035 ADMUX = (channel-1) + (1<<ADLAR) + (1<<REFS0); 00036 //ADMUX |= (1<<ADLAR); //left-align bits to allow to read the 8bit-value from ADCH 00037 }
|
|
sets the nr of active channels
00053 { 00054 adc_channels = nr; 00055 }
|
|
sets the prescaler
00066 { 00067 if(presc <= 7 && presc >= 1) adc_prescaler = presc; 00068 }
|
|
stops the ADC switches off the free running mode.
00127 { 00128 ADCSRA &= ~(1<<ADSC) & ~(1<<ADFR) & ~(1<<ADIE); 00129 adc_stop_flag = 1; 00130 00131 adc_duration = us_time_get_difference_d(adc_starttime) / ((double)ADC_BUF_SIZE / (double)adc_channels); 00132 }
|
|
checks, whether the ADC has stopped
00135 { 00136 return adc_stop_flag; 00137 }
|
|
input-buffer
|
|
nr of active channels
|
|
time for one sample point
|
|
the current prescaler
|