acifa_example.c File Reference


Detailed Description

ACIFA example driver for AVR UC3.

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

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

Definition in file acifa_example.c.

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

Go to the source code of this file.

Defines

ACIFA channels configuration for the example
#define EXAMPLE_AC_ACMP0_FUNCTION   AVR32_AC1AP1_FUNCTION
#define EXAMPLE_AC_ACMP0_INPUT   1
#define EXAMPLE_AC_ACMP0_PIN   AVR32_AC1AP1_PIN
#define EXAMPLE_AC_ACMP1_FUNCTION   AVR32_AC0AP0_FUNCTION
#define EXAMPLE_AC_ACMP1_INPUT   0
#define EXAMPLE_AC_ACMP1_PIN   AVR32_AC0AP0_PIN
#define EXAMPLE_AC_ACMP2_FUNCTION   AVR32_AC0BP0_FUNCTION
#define EXAMPLE_AC_ACMP2_INPUT   2
#define EXAMPLE_AC_ACMP2_PIN   AVR32_AC0BP0_PIN
#define EXAMPLE_AC_ACMPN0_FUNCTION   AVR32_AC1AN1_FUNCTION
#define EXAMPLE_AC_ACMPN0_INPUT   1
#define EXAMPLE_AC_ACMPN0_PIN   AVR32_AC1AN1_PIN
#define EXAMPLE_AC_ACMPN1_FUNCTION   AVR32_AC0AN0_FUNCTION
#define EXAMPLE_AC_ACMPN1_INPUT   0
#define EXAMPLE_AC_ACMPN1_PIN   AVR32_AC0AN0_PIN
#define EXAMPLE_AC_ACMPN2_FUNCTION   AVR32_AC0BN0_FUNCTION
#define EXAMPLE_AC_ACMPN2_INPUT   0
#define EXAMPLE_AC_ACMPN2_PIN   AVR32_AC0BN0_PIN

Functions

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


Define Documentation

#define EXAMPLE_AC_ACMP0_FUNCTION   AVR32_AC1AP1_FUNCTION

Definition at line 101 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP0_INPUT   1

Definition at line 99 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP0_PIN   AVR32_AC1AP1_PIN

Definition at line 100 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP1_FUNCTION   AVR32_AC0AP0_FUNCTION

Definition at line 109 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP1_INPUT   0

Definition at line 107 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP1_PIN   AVR32_AC0AP0_PIN

Definition at line 108 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP2_FUNCTION   AVR32_AC0BP0_FUNCTION

Definition at line 117 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP2_INPUT   2

Definition at line 115 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMP2_PIN   AVR32_AC0BP0_PIN

Definition at line 116 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN0_FUNCTION   AVR32_AC1AN1_FUNCTION

Definition at line 105 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN0_INPUT   1

Definition at line 103 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN0_PIN   AVR32_AC1AN1_PIN

Definition at line 104 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN1_FUNCTION   AVR32_AC0AN0_FUNCTION

Definition at line 113 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN1_INPUT   0

Definition at line 111 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN1_PIN   AVR32_AC0AN0_PIN

Definition at line 112 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN2_FUNCTION   AVR32_AC0BN0_FUNCTION

Definition at line 121 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN2_INPUT   0

Definition at line 119 of file acifa_example.c.

Referenced by main().

#define EXAMPLE_AC_ACMPN2_PIN   AVR32_AC0BN0_PIN

Definition at line 120 of file acifa_example.c.

Referenced by main().


Function Documentation

int main ( void   ) 

main function : do init and loop to display ADC values

Definition at line 149 of file acifa_example.c.

References ACIFA_COMP_SELA, ACIFA_COMP_SELB, acifa_configure(), acifa_is_aca_inp_higher(), acifa_is_acb_inp_higher(), acifa_start(), EXAMPLE_AC_ACMP0_FUNCTION, EXAMPLE_AC_ACMP0_INPUT, EXAMPLE_AC_ACMP0_PIN, EXAMPLE_AC_ACMP1_FUNCTION, EXAMPLE_AC_ACMP1_INPUT, EXAMPLE_AC_ACMP1_PIN, EXAMPLE_AC_ACMP2_FUNCTION, EXAMPLE_AC_ACMP2_INPUT, EXAMPLE_AC_ACMP2_PIN, EXAMPLE_AC_ACMPN0_FUNCTION, EXAMPLE_AC_ACMPN0_INPUT, EXAMPLE_AC_ACMPN0_PIN, EXAMPLE_AC_ACMPN1_FUNCTION, EXAMPLE_AC_ACMPN1_INPUT, EXAMPLE_AC_ACMPN1_PIN, EXAMPLE_AC_ACMPN2_FUNCTION, EXAMPLE_AC_ACMPN2_INPUT, and EXAMPLE_AC_ACMPN2_PIN.

00150 {
00151   // GPIO pin/adc-function map.
00152   static const gpio_map_t ACIFA_GPIO_MAP =
00153   {
00154     {AVR32_ADCREF0_PIN,AVR32_ADCREF0_FUNCTION},
00155     {AVR32_ADCREFP_PIN,AVR32_ADCREFP_FUNCTION},
00156     {AVR32_ADCREFN_PIN,AVR32_ADCREFN_FUNCTION},
00157 #if BOARD == UC3C_EK
00158     {EXAMPLE_AC_ACMP0_PIN, EXAMPLE_AC_ACMP0_FUNCTION},
00159     {EXAMPLE_AC_ACMPN0_PIN, EXAMPLE_AC_ACMPN0_FUNCTION},
00160     {EXAMPLE_AC_ACMP1_PIN, EXAMPLE_AC_ACMP1_FUNCTION},
00161     {EXAMPLE_AC_ACMPN1_PIN, EXAMPLE_AC_ACMPN1_FUNCTION},
00162     {EXAMPLE_AC_ACMP2_PIN, EXAMPLE_AC_ACMP2_FUNCTION},
00163     {EXAMPLE_AC_ACMPN2_PIN, EXAMPLE_AC_ACMPN2_FUNCTION}
00164 #endif
00165   };
00166 
00167   volatile avr32_acifa_t *acifa0 = &AVR32_ACIFA0; // ACIFA0 IP registers address
00168   volatile avr32_acifa_t *acifa1 = &AVR32_ACIFA1; // ACIFA1 IP registers address
00169 
00170   volatile int i;
00171 
00172   // switch to oscillator 0
00173   pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00174 
00175   // init debug serial line
00176   init_dbg_rs232(FOSC0);
00177 
00178   // Assign and enable GPIO pins to the AC function.
00179   gpio_enable_module(ACIFA_GPIO_MAP, sizeof(ACIFA_GPIO_MAP) / sizeof(ACIFA_GPIO_MAP[0]));
00180 
00181   // configure ACIFA
00182   acifa_configure(acifa1,
00183                   ACIFA_COMP_SELA,
00184                   EXAMPLE_AC_ACMP0_INPUT,
00185                   EXAMPLE_AC_ACMPN0_INPUT,
00186                   FOSC0);
00187 
00188   // Start the ACIFA.
00189   acifa_start(acifa1,
00190               ACIFA_COMP_SELA);
00191 
00192   // configure ACIFA
00193   acifa_configure(acifa0,
00194                   ACIFA_COMP_SELA,
00195                   EXAMPLE_AC_ACMP1_INPUT,
00196                   EXAMPLE_AC_ACMPN1_INPUT,
00197                   FOSC0);
00198   acifa_configure(acifa0,
00199                   ACIFA_COMP_SELB,
00200                   EXAMPLE_AC_ACMP2_INPUT,
00201                   EXAMPLE_AC_ACMPN2_INPUT,
00202                   FOSC0);
00203   
00204   // Start the ACIFA.
00205   acifa_start(acifa0,
00206               (ACIFA_COMP_SELA|ACIFA_COMP_SELB));
00207 
00208   
00209   // do a loop
00210   for (;;)
00211   {
00212     // slow down operations
00213     for ( i=0 ; i < 1000000 ; i++);
00214 
00215     // display a header to user
00216     print_dbg("\x1B[2J\x1B[H\r\nACIFA Example\r\n");
00217 
00218 #if BOARD == UC3C_EK
00219     if (acifa_is_aca_inp_higher(acifa1))
00220     {
00221       print_dbg("ACMP0 > ACMPN0");
00222       print_dbg("\r\n");
00223     }
00224     else
00225     {
00226       print_dbg("ACMP0 < ACMPN0");
00227       print_dbg("\r\n");
00228     }
00229     if (acifa_is_aca_inp_higher(acifa0))
00230     {
00231       print_dbg("ACMP1 > ACMPN1");
00232       print_dbg("\r\n");
00233     }
00234     else
00235     {
00236       print_dbg("ACMP1 < ACMPN1");
00237       print_dbg("\r\n");
00238     } 
00239  
00240     if (acifa_is_acb_inp_higher(acifa0))
00241     {
00242       print_dbg("ACMP2 > ACMPN2");
00243       print_dbg("\r\n");
00244     }
00245     else
00246     {
00247       print_dbg("ACMP2 < ACMPN2");
00248       print_dbg("\r\n");
00249     }    
00250 #endif
00251   }
00252 
00253 }


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