00001
00087 #include "board.h"
00088 #include "print_funcs.h"
00089 #include "gpio.h"
00090 #include "power_clocks_lib.h"
00091 #include "acifa.h"
00092
00095
00096 #if BOARD == UC3C_EK
00097
00098
00099 # define EXAMPLE_AC_ACMP0_INPUT 1
00100 # define EXAMPLE_AC_ACMP0_PIN AVR32_AC1AP1_PIN
00101 # define EXAMPLE_AC_ACMP0_FUNCTION AVR32_AC1AP1_FUNCTION
00102
00103 # define EXAMPLE_AC_ACMPN0_INPUT 1
00104 # define EXAMPLE_AC_ACMPN0_PIN AVR32_AC1AN1_PIN
00105 # define EXAMPLE_AC_ACMPN0_FUNCTION AVR32_AC1AN1_FUNCTION
00106
00107 # define EXAMPLE_AC_ACMP1_INPUT 0
00108 # define EXAMPLE_AC_ACMP1_PIN AVR32_AC0AP0_PIN
00109 # define EXAMPLE_AC_ACMP1_FUNCTION AVR32_AC0AP0_FUNCTION
00110
00111 # define EXAMPLE_AC_ACMPN1_INPUT 0
00112 # define EXAMPLE_AC_ACMPN1_PIN AVR32_AC0AN0_PIN
00113 # define EXAMPLE_AC_ACMPN1_FUNCTION AVR32_AC0AN0_FUNCTION
00114
00115 # define EXAMPLE_AC_ACMP2_INPUT 2
00116 # define EXAMPLE_AC_ACMP2_PIN AVR32_AC0BP0_PIN
00117 # define EXAMPLE_AC_ACMP2_FUNCTION AVR32_AC0BP0_FUNCTION
00118
00119 # define EXAMPLE_AC_ACMPN2_INPUT 0
00120 # define EXAMPLE_AC_ACMPN2_PIN AVR32_AC0BN0_PIN
00121 # define EXAMPLE_AC_ACMPN2_FUNCTION AVR32_AC0BN0_FUNCTION
00122 #endif
00124
00125 #if !defined(EXAMPLE_AC_ACMP0_INPUT) || \
00126 !defined(EXAMPLE_AC_ACMP0_PIN) || \
00127 !defined(EXAMPLE_AC_ACMP0_FUNCTION) || \
00128 !defined(EXAMPLE_AC_ACMPN0_INPUT) || \
00129 !defined(EXAMPLE_AC_ACMPN0_PIN) || \
00130 !defined(EXAMPLE_AC_ACMPN0_FUNCTION)|| \
00131 !defined(EXAMPLE_AC_ACMP1_INPUT) || \
00132 !defined(EXAMPLE_AC_ACMP1_PIN) || \
00133 !defined(EXAMPLE_AC_ACMP1_FUNCTION) || \
00134 !defined(EXAMPLE_AC_ACMPN1_INPUT) || \
00135 !defined(EXAMPLE_AC_ACMPN1_PIN) || \
00136 !defined(EXAMPLE_AC_ACMPN1_FUNCTION)|| \
00137 !defined(EXAMPLE_AC_ACMP2_INPUT) || \
00138 !defined(EXAMPLE_AC_ACMP2_PIN) || \
00139 !defined(EXAMPLE_AC_ACMP2_FUNCTION) || \
00140 !defined(EXAMPLE_AC_ACMPN2_INPUT) || \
00141 !defined(EXAMPLE_AC_ACMPN2_PIN) || \
00142 !defined(EXAMPLE_AC_ACMPN2_FUNCTION)
00143 #error The ADCIFA configuration to use in the example is missing.
00144 #endif
00145
00149 int main( void )
00150 {
00151
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;
00168 volatile avr32_acifa_t *acifa1 = &AVR32_ACIFA1;
00169
00170 volatile int i;
00171
00172
00173 pcl_switch_to_osc(PCL_OSC0, FOSC0, OSC0_STARTUP);
00174
00175
00176 init_dbg_rs232(FOSC0);
00177
00178
00179 gpio_enable_module(ACIFA_GPIO_MAP, sizeof(ACIFA_GPIO_MAP) / sizeof(ACIFA_GPIO_MAP[0]));
00180
00181
00182 acifa_configure(acifa1,
00183 ACIFA_COMP_SELA,
00184 EXAMPLE_AC_ACMP0_INPUT,
00185 EXAMPLE_AC_ACMPN0_INPUT,
00186 FOSC0);
00187
00188
00189 acifa_start(acifa1,
00190 ACIFA_COMP_SELA);
00191
00192
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
00205 acifa_start(acifa0,
00206 (ACIFA_COMP_SELA|ACIFA_COMP_SELB));
00207
00208
00209
00210 for (;;)
00211 {
00212
00213 for ( i=0 ; i < 1000000 ; i++);
00214
00215
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 }