2 * Copyright Droids Corporation, Microb Technology, Eirbot (2005)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: main.c,v 1.5.4.3 2007-09-06 08:15:37 zer0 Exp $
23 #include <aversive/wait.h>
30 #include <aversive/pgmspace.h>
41 fdevopen(uart0_dev_send,NULL);
49 printf_P(PSTR("\n\nHello everybody\n This is the ADC test\n"));
54 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0 );
56 printf_P(PSTR("polling : ADC0 = %i\n"),a);
61 adc_launch( ADC_REF_AVCC | MUX_ADC1 );
63 /* this function should take less time */
64 a = adc_get_value( ADC_NO_CONFIG );
66 printf_P(PSTR("pre-launch : ADC1 = %i\n"),a);
69 /* test of free running mode */
71 a = adc_get_value( ADC_REF_AVCC | MUX_ADC2 | ADC_MODE_TRIGGERED );
72 printf_P(PSTR("free run mode : ADC2 = %i\n"),a);
74 /* this function should take less time */
75 a = adc_get_value( ADC_REF_AVCC | MUX_ADC3 | ADC_MODE_TRIGGERED );
76 printf_P(PSTR("free run mode : ADC3 = %i\n\n"),a);
80 /* test of different outputs formats */
82 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0 | ADC_MODE_16_BITS );
83 printf_P(PSTR("normal output 16: ADC0 = %u ( div = %u)\n"),
84 a, ((uint16_t)a)/(1<<6));
86 b = adc_get_value32( (void*)(ADC_REF_AVCC | MUX_ADC0 |
88 printf_P(PSTR("normal output 16(32): ADC0 = %ld ( div = %lu)\n"),
91 /* ADC_MODE_10_BITS default */
92 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0 );
93 printf_P(PSTR("normal output 10: ADC0 = %u\n"),a);
95 /* ADC_MODE_10_BITS default */
96 b = adc_get_value32( (void*)(ADC_REF_AVCC | MUX_ADC0 ) );
97 printf_P(PSTR("normal output 10(32): ADC0 = %lu\n"),b);
99 printf_P(PSTR("now try a signed differential conversion\n"));
101 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0 | ADC_MODE_10_BITS );
102 b = adc_get_value( ADC_REF_AVCC | MUX_ADC1 | ADC_MODE_10_BITS );
103 printf_P(PSTR("computed : ADC0-ADC1 = %i\n"),
104 ((int16_t)a - (int16_t)b) /2);
106 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0_ADC1);
108 printf_P(PSTR("signed output 10: ADC0-ADC1 = %i\n"),a);
110 b = adc_get_value32( (void*)(ADC_REF_AVCC | MUX_ADC0_ADC1 ) );
111 printf_P(PSTR("signed output 10(32): ADC0-ADC1 = %li\n"),b);
113 a = adc_get_value( ADC_REF_AVCC | MUX_ADC0_ADC1 |
115 printf_P(PSTR("signed output 16: ADC0-ADC1 = %i ( div = %i)\n"),
118 b = adc_get_value32( (void*)(ADC_REF_AVCC | MUX_ADC0_ADC1 |
119 ADC_MODE_16_BITS ) );
120 printf_P(PSTR("signed output 16(32): ADC0-ADC1 = %li ( div = %li)\n\n"),
123 /* test of interrupt mode : we scan once the 8
126 adc_register_event(event);
127 adc_launch( ADC_REF_AVCC | MUX_ADC0 | ADC_MODE_INT );
138 void event(int16_t result)
144 /* The printf in an interrupt is not a good idea, but ok for
145 * the test program */
146 printf_P(PSTR("from interrupt : ADC%i = %i\n"),i,result);
149 adc_launch( ADC_REF_AVCC | ( MUX_ADC0 + i ) | ADC_MODE_INT );
151 i = 0; /* end, reinitialisation for the next time */