The FoxG20 has a 10 bit, 4-channel ADC circuit integrated right into the CPU. Thanks to the work of a few enthusiasts on our Forums & newsgroups, we now also have Linux support for it. Let me show you how easy it is to connect an analog probe and acquire voltage values.
First of all, let's wire up something in order to have a signal to read. To keep things simple, we will connect AD0 between two identical 10k resistances. Try out the following schema:
AVDD (J6.33) --+
|
VREF (J6.34) --+
|
10k
|
AD0 (J6.30) --+
|
10k
|
AGND (J6.35) --+
|
GND (J6.40) --+
Connected in this way, AD0 will sit halfway between VREF (= AVDD = 3.3V) and AGND (= GND = 0V); if you use a multimeter to check the voltage among AD0 and GND, it should read 1.65V.
Now, download the driver code at91_adc_driver-20100518_0821.tgz; unpack it, compile it and copy the resulting module to the FoxG20:
tar zxvf at91_adc_driver-20100518_0821.tgz cd at91_adc_driver KDIR=<position of your kernel tree> make scp at91_adc.ko root@<ip address of your fox g20>:
When you insert it into your Fox, the module will provide a very simple interface in sysfs:
debarm:~# insmod at91_adc.ko debarm:~# tree /sys/bus/platform/devices/at91_adc/ /sys/bus/platform/devices/at91_adc/ |-- chan0 |-- chan1 |-- chan2 |-- chan3 |-- modalias |-- power | `-- wakeup |-- subsystem -> ../../../bus/platform `-- uevent 2 directories, 7 files
The four read-only pseudofiles chan0 - chan3 represent the four ADC channels. Reading any of them will give you back a number between 0 and 1023, representing a 10 bit quantization of the attached voltage - here 0 means 0V, while 1023 represents the full 3.3V signal.
So, let's try it out:
debarm:~# cat /sys/bus/platform/devices/at91_adc/chan0 509
For the lazy, here's a Perl one-liner for converting the 10 bit logical level back into a voltage:
debarm:~# perl -ne'printf "%.2f\n", 3.3*$_/1024;' /sys/bus/platform/devices/at91_adc/chan0 1.64
Other information and complete code can be found on http://sourceforge.net/apps/trac/acme-dev/browser/kernel-stuff se also the Open Source Bay on SourceForge