Anda di halaman 1dari 5

Phyboard-Wega-AM335x ADC Guide.

In this article we will be learning how to use ADC in AM335x based Phyboard-Wega
board, the reference has been taen fro! "I#s wii AM335x ADC Driver's Guide$
An analog-to-digital con%erter &abbre%iated ADC' is a de%ice that uses sa!(ling to
con%ert a continuous )uantity to a discrete ti!e re(resentation in digital for!$
"he "*C+ADC+** &"ouchscreen+ADC+subsyste!' is an , channel general (ur(ose
ADC, with o(tional su((ort for interlea%ing "ouch *creen con%ersions$ "he
"*C+ADC+** can be used and configured in one of the following a((lication
o(tions-
, general (ur(ose ADC channels
. wire "*, with . general (ur(ose ADC channels
5 wire "*, with 3 general (ur(ose ADC channels
, wire "*

ADC used is /0 bit *A1 ADC with a sa!(le rate of 022 3*P* &3ilo *a!(les Per
*econd'$ "he ADC sa!(les the analog signal when 4start of con%ersion4 signal is
high and continues sa!(ling / cloc cycle after the falling edge$ It ca(tures the signal
at the end of sa!(ling (eriod and starts con%ersion$ It uses /0 cloc cycles to digiti5e
the sa!(led in(ut6 then an 4end of con%ersion4 signal is enabled high indicating that
the digital data ADC78"9//-2: is ready for *W to consu!e$ A new con%ersion
cycle can be initiated after the (re%ious data is read$ Please note that the ADC out(ut
is (ositi%e binary weighted data$
Hardware Setup:
;or ADC channels on board refer <section = >x(ansion connector? fro! hardware
!anual of (hy@7A1D-Wega fro! below lin$
ft(-AAft($(hytec$deA(ubAProductsAIndiaA(hy@7A1D-W>BA-AM335xACinuxADocADA1DWA1>-MAE8AC-W>BA$(df
Driver e!e"tio#:
>nable the following o(tions in the linux ernel as follows$
Device Drivers --->
[*] Staging drivers --->
[*] Industrial I/O support --->
[*] Enable buffer support within IIO
*> Industrial I/O loc! free software ring
> Industrial I/O buffering based on !fifo
-*- Enable triggered sa"pling support
#$% &a'i"u" nu"ber of consu"ers per trigger
(nalog to digital converters --->
*> )I*s (D+ driver
Also enable the <"ouch *creen AADC chi(s? su((ort$
Device Drivers --->
Multifunction device drivers -->
<*> TI ADC / Touch Screen chip support
Addi#g P!at$or% data:
ADC (latfor! data is added in board file&archAar!A!ach-o!a(0Aboard-(c!25/$c' as
shown below$
,include linu'/platfor"-data/ti-adc.h>
static struct adc-data a"//0'-adc-data 1 2
.adc-channels 1 34
56
static struct "fd-tscadc-board tscadc 1 2
.tsc-init 1 7a"//0'-touchscreen-data4
.adc-init 1 7a"//0'-adc-data4
56
"he (ara!eter 4adc+channels4 needs to hold data related to how !any channels you
want to use for ADC$
If ADC and touchscreen are used together, add (latfor! data as shown abo%e$
If ADC alone is being used, you will need to re!o%e (latfor! data for touch
screen$

>xa!(le below$ Eotice adc+channels is increased to , in the adc initiali5ation$



static struct adc-data a"//0'-adc-data 1 2
.adc-channels 1 84
56
/*
static struct tsc-data a"//0'-touchscreen-data 1 2
.wires 1 34
.'-plate-resistance 1 $994
.steps-to-configure 1 04
56 */
static struct "fd-tscadc-board tscadc 1 2
/* .tsc-init 1 7a"//0'-touchscreen-data4 */
.adc-init 1 7a"//0'-adc-data4
56
&eti#g ADC:
"o test ADC, Connect a DC %oltage su((ly to each of the AIE2 through AIE= (ins
&based on your channel configuration', and %ary %oltage between 2 and /$,%
reference %oltage$
7nce the ernel is booted you can see the iio de%ice created as shown below$
root:ph;<O(=D->E?(-(&//0'@A ls -al /s;s/bus/iio/devices/iioB@device9/
drw'r-'r-' 0 root root 9 (ug C0 9/@3/ .
drw'r-'r-' 3 root root 9 (ug C0 9/@3/ ..
drw'r-'r-' $ root root 9 (ug C0 9/@3/ buffer
-r--r--r-- C root root 39DE (ug C0 9/@3/ dev
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltage9-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltageC-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltage$-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltage/-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltage3-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltage0-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltageE-raw
-r--r--r-- C root root 39DE (ug C0 9/@3/ in-voltageF-raw
-rw-r--r-- C root root 39DE (ug C0 9/@3/ "ode
-r--r--r-- C root root 39DE (ug C0 9/@3/ na"e
drw'r-'r-' $ root root 9 (ug C0 9/@3/ power
drw'r-'r-' $ root root 9 (ug C0 9/@3/ scan-ele"ents
lrw'rw'rw' C root root 9 (ug C0 9/@3/ subs;ste"
-> ../../../../../../bus/iio
-rw-r--r-- C root root 39DE (ug C0 9/@3/ uevent
root:ph;<O(=D->E?(-(&//0'@A
Mode o$ operatio#:
When the ADC se)uencer finishes cycling through all the enabled channels, the user
can decide if the se)uencer should sto( &one-shot !ode', or loo( bac and schedule
again &continuous !ode'$ If one-shot !ode is enabled, then the se)uencer will only
be scheduled one ti!e &the se)uencer DW will auto!atically disable the *te(>nable
bit after it is scheduled which will guarantee only one sa!(le is taen (er channel'$
When the user wants to continuously tae sa!(les, continuous !ode needs to be
enabled$ 7ne cannot read ADC data fro! one channel o(erating in 7ne-shot !ode
and and other in continuous !ode at the sa!e ti!e$
Oneshot mode:
"o read a single ADC %alue, ADC has to be configured in one-shot !ode$ If not in
one-shot !ode, "his can be set by-
root:ph;<O(=D->E?(-(&//0'@A echo oneshot > /s;s/bus/iio/devices/iioB@device9/"od
e
Continuous Mode:
"o read data continuously, ADC has to be configured in continuous !ode$ "his can
be done by-
root:ph;<O(=D->E?(-(&//0'@A echo continuous > /s;s/bus/iio/devices/iioB@device9/
"ode
ADC Setup:
*et u( the channels in use &you can enable any co!bination of the channels you
want'$
root:ph;<O(=D->E?(-(&//0'@A echo C > /s;s/bus/iio/devices/iioB@device9/scan-ele"
ents/in-voltage9-en
root:ph;<O(=D->E?(-(&//0'@A echo C > /s;s/bus/iio/devices/iioB@device9/scan-ele"
ents/in-voltage$-en
root:ph;<O(=D->E?(-(&//0'@A echo C > /s;s/bus/iio/devices/iioB@device9/scan-ele"
ents/in-voltage3-en
If you are using continuous !ode then you need to *et u( the buffer length, and
enable the buffer$
root:ph;<O(=D->E?(-(&//0'@A echo C99 > /s;s/bus/iio/devices/iioB@device9/buffer/
length
"o enable the buffer use the following co!!and$
root:ph;<O(=D->E?(-(&//0'@A echo C > /s;s/bus/iio/devices/iioB@device9/buffer/en
able
"o disable the buffer use the following co!!and$
root:ph;<O(=D->E?(-(&//0'@A echo 9 > /s;s/bus/iio/devices/iioB@device9/buffer/en
able
'or%u!a (ed $or Ca!"u!atio#:
"o cross %erify the digital %alues read use,
D 1 Gin * #$Hn - C% / Gref
>here@
D 1 Digital value
Gin 1 Input voltage
n 1 Io of bits
Gref 1 reference voltage
>x- 1ead %alue on channel AIE. for in(ut %oltage su((lied 2$52-
;or!ula-
Gin 1 9.09 * #$HC$ -C %/ C.8
Gin 1 CC/F.0
Falue read fro! sysfs-
root:ph;<O(=D->E?(-(&//0'@A cat /s;s/bus/iio/devices/iioB@device9/in-voltage3-ra
w
CC09