00001
00086 #include "board.h"
00087 #include "print_funcs.h"
00088 #include "gpio.h"
00089 #include "power_clocks_lib.h"
00090 #include "adcifa.h"
00091
00094
00095 #if BOARD == UC3C_EK
00096 # define EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE 2
00097
00098 # define EXAMPLE_ADC_POTENTIOMETER_INP AVR32_ADCIFA_INP_ADCIN5
00099 # define EXAMPLE_ADC_POTENTIOMETER_INN AVR32_ADCIFA_INN_GNDANA
00100 # define EXAMPLE_ADC_POTENTIOMETER_PIN AVR32_ADCIN5_PIN
00101 # define EXAMPLE_ADC_POTENTIOMETER_FUNCTION AVR32_ADCIN5_FUNCTION
00102
00103 # define EXAMPLE_ADC_MIC_INP AVR32_ADCIFA_INP_GNDANA
00104 # define EXAMPLE_ADC_MIC_INN AVR32_ADCIFA_INN_ADCIN14
00105 # define EXAMPLE_ADC_MIC_PIN AVR32_ADCIN14_PIN
00106 # define EXAMPLE_ADC_MIC_FUNCTION AVR32_ADCIN14_FUNCTION
00107 #endif
00108
00109 #if !defined(EXAMPLE_ADC_MIC_INP) || \
00110 !defined(EXAMPLE_ADC_MIC_INN) || \
00111 !defined(EXAMPLE_ADC_MIC_PIN) || \
00112 !defined(EXAMPLE_ADC_MIC_FUNCTION)
00113 # error The ADCIFA configuration to use in this example is missing.
00114 #endif
00116
00117
00120 int main( void )
00121 {
00122
00123 static const gpio_map_t ADCIFA_GPIO_MAP =
00124 {
00125 {AVR32_ADCREF0_PIN,AVR32_ADCREF0_FUNCTION},
00126 {AVR32_ADCREFP_PIN,AVR32_ADCREFP_FUNCTION},
00127 {AVR32_ADCREFN_PIN,AVR32_ADCREFN_FUNCTION},
00128 #if BOARD == UC3C_EK
00129 {EXAMPLE_ADC_POTENTIOMETER_PIN, EXAMPLE_ADC_POTENTIOMETER_FUNCTION},
00130 {EXAMPLE_ADC_MIC_PIN, EXAMPLE_ADC_MIC_FUNCTION}
00131 #endif
00132 };
00133
00134 volatile avr32_adcifa_t *adcifa = &AVR32_ADCIFA;
00135
00136 S16 adc_values[EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE];
00137
00138
00139 adcifa_opt_t adcifa_opt = {
00140 .frequency = 1000000,
00141 .reference_source = ADCIFA_ADCREF0,
00142 .sample_and_hold_disable = FALSE,
00143 .single_sequencer_mode = FALSE,
00144 .free_running_mode_enable = FALSE,
00145 .sleep_mode_enable = FALSE
00146 };
00147
00148
00149 adcifa_sequencer_opt_t adcifa_sequence_opt = {
00150 .convnb = EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE,
00151 .resolution = ADCIFA_SRES_12B,
00152 .trigger_selection = ADCIFA_TRGSEL_SOFT,
00153 .start_of_conversion = ADCIFA_SOCB_ALLSEQ,
00154 .oversampling = ADCIFA_CSWS_WSTATE,
00155 .half_word_adjustment = ADCIFA_HWLA_NOADJ,
00156 .software_acknowledge = ADCIFA_SA_NO_EOS_SOFTACK
00157 };
00158
00159 #if BOARD == UC3C_EK
00160
00161 adcifa_sequencer_conversion_opt_t adcifa_sequence_conversion_opt[EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE] =
00162 {
00163 {
00164 .channel_p = EXAMPLE_ADC_POTENTIOMETER_INP,
00165 .channel_n = EXAMPLE_ADC_POTENTIOMETER_INN,
00166 .gain = ADCIFA_SHG_1
00167 },
00168 {
00169 .channel_p = EXAMPLE_ADC_MIC_INP,
00170 .channel_n = EXAMPLE_ADC_MIC_INN,
00171 .gain = ADCIFA_SHG_8
00172 }
00173 };
00174 #endif
00175
00176 volatile int i;
00177
00178
00179 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00180
00181
00182 init_dbg_rs232(FOSC0);
00183
00184
00185 gpio_enable_module(ADCIFA_GPIO_MAP, sizeof(ADCIFA_GPIO_MAP) / sizeof(ADCIFA_GPIO_MAP[0]));
00186
00187
00188 adcifa_get_calibration_data(adcifa, &adcifa_opt, 0);
00189
00190
00191 adcifa_configure(adcifa, &adcifa_opt, FOSC0);
00192
00193
00194 adcifa_configure_sequencer(adcifa, 0, &adcifa_sequence_opt, adcifa_sequence_conversion_opt);
00195
00196
00197 for (;;)
00198 {
00199
00200 for ( i=0 ; i < 1000000 ; i++);
00201
00202
00203 print_dbg("\x1B[2J\x1B[H\r\nADCIFA Example\r\n");
00204
00205
00206 adcifa_start_sequencer(adcifa, 0);
00207
00208
00209 if (adcifa_get_values_from_sequencer(adcifa,
00210 0,
00211 &adcifa_sequence_opt,
00212 adc_values) == ADCIFA_STATUS_COMPLETED)
00213 {
00214 #if BOARD == UC3C_EK
00215
00216 print_dbg("HEX Value for Channel potentiometer: 0x");
00217 print_dbg_hex(adc_values[0]);
00218 print_dbg("\r\n");
00219 print_dbg("HEX Value for Channel microphone: 0x");
00220 print_dbg_hex(~adc_values[1]);
00221 print_dbg("\r\n");
00222 #endif
00223 }
00224 }
00225 }