adcifa_example.c File Reference


Detailed Description

ADCIFA example driver for AVR UC3.

This file provides an example for the ADCIFA on AVR UC3 devices.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file adcifa_example.c.

#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "power_clocks_lib.h"
#include "adcifa.h"

Go to the source code of this file.

Defines

ADCIFA channels choice
#define EXAMPLE_ADC_MIC_FUNCTION   AVR32_ADCIN14_FUNCTION
#define EXAMPLE_ADC_MIC_INN   AVR32_ADCIFA_INN_ADCIN14
#define EXAMPLE_ADC_MIC_INP   AVR32_ADCIFA_INP_GNDANA
#define EXAMPLE_ADC_MIC_PIN   AVR32_ADCIN14_PIN
#define EXAMPLE_ADC_POTENTIOMETER_FUNCTION   AVR32_ADCIN5_FUNCTION
#define EXAMPLE_ADC_POTENTIOMETER_INN   AVR32_ADCIFA_INN_GNDANA
#define EXAMPLE_ADC_POTENTIOMETER_INP   AVR32_ADCIFA_INP_ADCIN5
#define EXAMPLE_ADC_POTENTIOMETER_PIN   AVR32_ADCIN5_PIN
#define EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE   2

Functions

int main (void)
 main function : initialization and loop to display ADC values


Define Documentation

#define EXAMPLE_ADC_MIC_FUNCTION   AVR32_ADCIN14_FUNCTION

Definition at line 106 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_MIC_INN   AVR32_ADCIFA_INN_ADCIN14

Definition at line 104 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_MIC_INP   AVR32_ADCIFA_INP_GNDANA

Definition at line 103 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_MIC_PIN   AVR32_ADCIN14_PIN

Definition at line 105 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_POTENTIOMETER_FUNCTION   AVR32_ADCIN5_FUNCTION

Definition at line 101 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_POTENTIOMETER_INN   AVR32_ADCIFA_INN_GNDANA

Definition at line 99 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_POTENTIOMETER_INP   AVR32_ADCIFA_INP_ADCIN5

Definition at line 98 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADC_POTENTIOMETER_PIN   AVR32_ADCIN5_PIN

Definition at line 100 of file adcifa_example.c.

Referenced by main().

#define EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE   2

Definition at line 96 of file adcifa_example.c.

Referenced by main().


Function Documentation

int main ( void   ) 

main function : initialization and loop to display ADC values

Definition at line 120 of file adcifa_example.c.

References ADCIFA_ADCREF0, adcifa_configure(), adcifa_configure_sequencer(), ADCIFA_CSWS_WSTATE, adcifa_get_calibration_data(), adcifa_get_values_from_sequencer(), ADCIFA_HWLA_NOADJ, ADCIFA_SA_NO_EOS_SOFTACK, ADCIFA_SHG_1, ADCIFA_SHG_8, ADCIFA_SOCB_ALLSEQ, ADCIFA_SRES_12B, adcifa_start_sequencer(), ADCIFA_STATUS_COMPLETED, ADCIFA_TRGSEL_SOFT, EXAMPLE_ADC_MIC_FUNCTION, EXAMPLE_ADC_MIC_INN, EXAMPLE_ADC_MIC_INP, EXAMPLE_ADC_MIC_PIN, EXAMPLE_ADC_POTENTIOMETER_FUNCTION, EXAMPLE_ADC_POTENTIOMETER_INN, EXAMPLE_ADC_POTENTIOMETER_INP, EXAMPLE_ADC_POTENTIOMETER_PIN, and EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE.

00121 {
00122   // GPIO pin/adc-function map.
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; // ADCIFA IP registers address
00135 
00136   S16 adc_values[EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE];
00137 
00138   // ADC Configuration
00139   adcifa_opt_t adcifa_opt = {
00140                               .frequency                = 1000000,  // ADC frequency (Hz)
00141                               .reference_source         = ADCIFA_ADCREF0, // Reference Source
00142                               .sample_and_hold_disable  = FALSE,    // Disable Sample and Hold Time
00143                               .single_sequencer_mode    = FALSE,    // Single Sequencer Mode 
00144                               .free_running_mode_enable = FALSE,    // Free Running Mode 
00145                               .sleep_mode_enable        = FALSE     // Sleep Mode
00146                             };
00147   
00148   // Sequencer Configuration
00149   adcifa_sequencer_opt_t adcifa_sequence_opt = {
00150                                                   .convnb               = EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE, // Number of sequence
00151                                                   .resolution           = ADCIFA_SRES_12B,         // Resolution selection
00152                                                   .trigger_selection    = ADCIFA_TRGSEL_SOFT,      // Trigger selection
00153                                                   .start_of_conversion  = ADCIFA_SOCB_ALLSEQ,      // Conversion Management
00154                                                   .oversampling         = ADCIFA_CSWS_WSTATE,      // Oversampling Management 
00155                                                   .half_word_adjustment = ADCIFA_HWLA_NOADJ,       // Half word Adjustment
00156                                                   .software_acknowledge = ADCIFA_SA_NO_EOS_SOFTACK // Software Acknowledge
00157                                                };
00158     
00159   #if BOARD == UC3C_EK
00160   // Conversions in the Sequencer Configuration  
00161   adcifa_sequencer_conversion_opt_t adcifa_sequence_conversion_opt[EXAMPLE_ADCIFA_NUMBER_OF_SEQUENCE] = 
00162                                                 {
00163                                                     {
00164                                                       .channel_p = EXAMPLE_ADC_POTENTIOMETER_INP,   // Positive Channel
00165                                                       .channel_n = EXAMPLE_ADC_POTENTIOMETER_INN,   // Negative Channel
00166                                                       .gain      = ADCIFA_SHG_1                     // Gain of the conversion
00167                                                     },
00168                                                     {
00169                                                       .channel_p = EXAMPLE_ADC_MIC_INP,             // Positive Channel
00170                                                       .channel_n = EXAMPLE_ADC_MIC_INN,             // Negative Channel
00171                                                       .gain      = ADCIFA_SHG_8                     // Gain of the conversion
00172                                                     }                                                                     
00173                                                 };
00174   #endif
00175 
00176   volatile int i;
00177 
00178   // switch to oscillator 0
00179   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00180 
00181   // init debug serial line
00182   init_dbg_rs232(FOSC0);
00183 
00184   // Assign and enable GPIO pins to the ADC function.
00185   gpio_enable_module(ADCIFA_GPIO_MAP, sizeof(ADCIFA_GPIO_MAP) / sizeof(ADCIFA_GPIO_MAP[0]));
00186 
00187   // Get ADCIFA Factory Configuration
00188   adcifa_get_calibration_data(adcifa, &adcifa_opt, 0);
00189   
00190   // Configure ADCIFA core
00191   adcifa_configure(adcifa, &adcifa_opt, FOSC0);
00192   
00193   // Configure ADCIFA sequencer 0
00194   adcifa_configure_sequencer(adcifa, 0, &adcifa_sequence_opt, adcifa_sequence_conversion_opt);
00195     
00196   // do a loop
00197   for (;;)
00198   {
00199     // slow down operations
00200     for ( i=0 ; i < 1000000 ; i++);
00201 
00202     // display a header to user
00203     print_dbg("\x1B[2J\x1B[H\r\nADCIFA Example\r\n");
00204 
00205     // Start ADCIFA sequencer 0
00206     adcifa_start_sequencer(adcifa, 0);
00207     
00208     // Get Values from sequencer 0
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         // display value to user
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 }


Generated on Fri Feb 19 02:24:12 2010 for AVR32 - ADCIFA Driver by  doxygen 1.5.5