Escolar Documentos
Profissional Documentos
Cultura Documentos
www.circuitcellar.com
X-Y Graphing Data Logger
FEATURE
ARTICLE
Alberto Ricci Bitti
l
With more data than
he can handle (and
always in some in-
convenient place),
Alberto constructed a
powerful, handheld,
programmable data
logger from his Casio
pocket calculator. And
as a reward, Design98
judges made it their
first PIC.
i ke any other
desi gner, I have to
cope wi th l ots of data
everyday. Raw data i n
need of anal ysi s comes from every
desi gn phase and from al l rel ated
si tes. From wri ti ng speci fi cati ons to
devel opment, from producti on tests to
on-si te veri fi cati on, we end up wi th
tons of measurements.
A graph i s often the best way to
poi nt out the key features of what you
measure. Its useful for i nstantaneous
communi cati ons and easy to document
for l ater reference. Its accepted for
corporate qual i ty system records, too.
PCs are powerful graphi ng tool s,
and maybe thats why al most al l recent
i nstruments have some ki nd of PC
i nterface. So, you just take out your
dazzl i ng new computer-i nterfaceabl e
meter, connect i t to nearest PC, and
start measuri ng. Ri ght?
Wrong. Someti mes you want to
take measurements i n the fi el d, and
you cant take the i nstruments out of
T H E C O M P U T E R A P P L I C A T I O N S J O U R N A L
INK
the l ab. Somethi ng other than the PC
can col l ect the data, but i ts fool ed by
groundi ng probl ems.
Other ti mes you need a battery-
operated i nstrument, but a l aptop i s
too expensi ve, or i t has to be used
el sewhere, or the batteri es dont l ast
l ong enough. And dont forget that
you have to convert data to spread-
sheet format to get the graphi cs.
What i f you need to col l ect data for
a whol e week? Can your preci ous
equi pment be l ocked for such a l ong
ti me?
My sol uti on: a si mpl e yet powerful
graphi cal data-acqui si ti on uni t bui l t
from a pocket cal cul ator. I appl i ed a
component-ori ented approach that
resul ted i n a shortened devel opment
cycl e and overal l qual i ty i mprove-
ment.
The uni t doesnt just col l ect data.
It al so di spl ays i t for further i nvesti ga-
ti on, and i t offers pl enty of anal yti cal
and stati sti cal bui l t-i n functi ons.
I appl i ed l ow-power techni ques and
Circuit Cellar INK
100 nF
out 10 mV/C
Pin 8 (+5 V)
Pin 1 (X)
Pin 9 (GND)
1 F
Pin 8 (+5 V)
Pin 7 (Y)
Pin 9 (GND)
10 k
LDR
2 1N4148
a) b)
Figure 2Here is the main flow of the Casio communication
protocol. Apart from reversed-TTL logic levels, its a familiar
half-duplex with 9600 bps, no parity, eight data bits, and two
stop bits. A level converter and inverter like the MAX232 is all
that's needed to interface the Casio to a PC serial port.
14 Issue 99 October 1998 Circuit Cellar INK
www.circuitcellar.com
you to retai n the cal cul ator. Pl us, onl y
data acqui si ti on and transmi ssi on need
to be tested, and you save on producti on
costs because you dont need compl i -
cated pl asti cs and el ectroni cs.
Documentati on i s si mpl er, too.
Just add a Capturi ng data chapter to
the cal cul ators manual .
Si ze and wei ght are al so reduced.
Even prototypes are handhel d, wei ghi ng
onl y 290 g (i ncl udi ng batteri es), and
seri es producti on si zes can be reduced
further.
LOW-POWER GUYS
Every successful project rel i es on
component sel ecti on, especi al l y battery-
operated desi gns. Maxi ms MAX186 i s
a l ow-power 12-bi t ADC. It needs
mi ni mal external hardware and features
a ni ce i nternal 4.096-V reference that
si zes each step to a handy 1 mV.
The MAX186 sports ei ght si ngl e-
ended i nputs, whi ch i s more than
enough for most appl i cati ons. The
same i nputs can be reconfi gured as
four bi pol ar and pseudodi fferenti al
i nputs by si mpl y changi ng the com-
mand word. Its sui tabl e for readi ng
data di rectl y from a l arge vari ety of
sensors (see Fi gure 1).
The MAX186 generates i ts cl ock
i nternal l y, and the enti re operati on i s
control l ed through a four-wi re SPI,
QSPI, or Mi crowi re seri al i nterface.
The devi ce i s put i n standby mode vi a
a three-l evel i nput pi n or wi th a soft-
ware command word.
It consumes 1.5 mA typi cal whi l e
operati ng, whi ch drops to a mere 2 A
i n ful l power-down mode. There i s
al so an i nteresti ng fast power-down
mode (not used i n thi s desi gn) that
consumes 30 A wi th a wake-up ti me
as short as 5 s.
If 10 bi ts are enough for your taste,
you can repl ace the MAX186 wi th the
MAX192. Its ful l y pi n- and software-
compati bl e wi th the MAX186. Pri ce
asi de, the onl y di fference resi des i n the
preci si on of the two l ower bi ts, whi ch
arent guaranteed for the MAX192.
The chi p needs a si ngl e 5-V power
suppl y. Wi th such a l ow power requi re-
ment, the drai n of the power regul ator
i tsel f becomes i mportant. Ordi nary
regul ators such as the 78L05 can eas-
i l y drai n more current than the whol e
ci rcui t.
You need speci fi c l ow-dropout
regul ators l i ke the LM2936 to get
maxi mum battery l i fe. The LM2936
has a qui escent current of onl y 9 A,
and i ts i nternal l y protected from
reverse battery connecti on.
FLASH RISC GLUE
An ei ght-bi t RISC mi crocontrol l er
gl ues the ADC to the Casi o seri al
i nput. Because my goal s i ncl uded
rapi d devel opment ti me and l ow cost,
I focused on smal l fl ash- or EEPROM-
based RISC mi crocontrol l ers.
The si mpl i fi ed RISC archi tecture i s
easy to l earn, and erasabl e parts l et
you concentrate on the probl em i n-
stead of the UV eraser. As a bonus,
these parts usual l y have si mpl e, ul tra-
cheap PC-port-based programmers.
I chose the PIC16C84 (an EEPROM
part) and the newer PIC16F84 (an
i mproved fl ash versi on) from Mi cro-
chi p. A useful characteri sti c of the PIC
archi tecture i s i ts support of data
tabl es that are as l ong as the program
memory. Thi s characteri sti c i s a resul t
of the !|U i nstructi on.
These PICs are powerful enough to
handl e seri al communi cati ons enti rel y
i n software wi th a 4-MHz cl ock. A
faster part (you can fi nd 50-MHz PIC
cl ones) i s unnecessary.
The PIC draws onl y a few mi croamps
when sl eepi ng (even wi th the watch-
dog ti mer enabl ed), and best of al l , i ts
cheap and avai l abl e. MPLAB, a profes-
si onal grade assembl er and si mul ator,
i s di stri buted for free by Mi crochi p,
al ong wi th l ots of useful l i brari es.
THE GRAPHIC ENGINE
The Casi o FX-9750G graphi ng
cal cul ator has 32 KB of RAM for data
or programs and a 64 128 bl ack and
whi te LCD. The FX-9750G i s a member
of a l arger fami l y that i ncl udes mod-
el s wi th col or LCDs and up to 64 KB
of memory. Its a powerful and enjoyabl e
math tool , but i t costs about the same
as a graphi c LCD modul e al one.
It runs on four LR03 batteri es for
200 h, and sensi ti ve data and programs
are mai ntai ned for up to one year by a
separate l i thi um battery. Im gl ad the
Casi o fol ks el ected to use a standard
mi ni ature stereo jack as the seri al port
connector for external peri pheral s.
The data protocol i s bui l t around a
standard 9600-bps hal f-dupl ex seri al
stream, wi th one start bi t, two stop
bi ts, and ei ght data bi ts wi th no pari ty.
Interfaci ng the FX-9750G to a PC i s
a matter of adapti ng TTLtoRS-232
l evel s. A MAX232 can do the job. I
bui l t one of the dozens of si mi l ar
ci rcui ts I found on the Internet,
coupl ed wi th the FA-122 Wi ndows
backup software.
I havent tested the compati bi l i ty
wi th other cal cul ators (besi des the
High impedance *SHDN
*CS
SCLK
DOUT
DIN
MSB LSB
1 X X
> 1 ms > 1.5 s > 10 s
Input
selection
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Single
ended
channel 0
channel 2
channel 4
channel 6
channel 1
channel 3
channel 5
channel 7
differential
(+) ()
ch. 0 ch. 1
ch. 2 ch. 3
ch. 4 ch. 5
ch. 6 ch. 7
ch. 1 ch. 0
ch. 3 ch. 2
ch. 5 ch. 4
ch. 7 ch. 6
Acquisition-mode
selection
0 0 bipolar, differential
from 2.048 V to +2.048 V
0 1 not allowed
1 0 unipolar, differential
1 1 unipolar, single ended
Figure 3The analog inputs of the MAX186 can be switched to bipolar and pseudodifferential mode by changing
the control word. In bipolar mode, the input spans between 2.048 V instead of the usual 04.096 V. The last two bits
in the control word select the power-down mode. Here, they are overridden, forcing the shutdown pin (*SHDN) low.
Circuit Cellar INK
www.circuitcellar.com
ii)
iii)
viii)
vii)
iv)
v)
Straightening CurvesLinearizing a Tank-Level Sensor
Most sensors outputs are nonl i near. To use them practi cal l y, they must be
strai ghtened usi ng i nterpol ati on tabl es or anal yti cal model s.
Regressi on model s are popul ar anal yti cal tool s for substi tuti ng data tabl es
wi th cl ean, conti nuous functi ons that are el egant and practi cal . Duri ng cal i brati on,
functi on substi tutes requi re onl y three or four poi nts to be measured, as compared
to the many more poi nts that tabl es requi re.
The vol ume of l i qui d i n the 25-l tank i n Fi gure i i s measured usi ng a fl oat
and potenti ometer. The output i s proporti onal to the angl e. The tanks i rregul ar
shape makes an anal yti cal approach i m-
practi cal . Its better to measure the sensor
output at known l i qui d quanti ti es.
Photo iThe output i s connected to
the x i nput, and the program i n Li sti ng 1
i s run. Each cycl e, exactl y 1 l of l i qui d i s
added unti l the tank i s ful l . At the end,
`l1 stores the l i ters of l i qui d, and `l
stores the sensors output l evel . Successi ve
data mani pul ati on i s done manual l y.
Photo iiSel ecti ng STAT gi ves you the
sampl ed data i n i ts raw form, as i t appears
on the defaul t entry page. Here, edi ti ng
and sorti ng can take pl ace. F1 l ets you
vi ew data graphi cal l y, and SET l ets you
check the current graphi ng preferences.
Photo iiiThe preferences for F1 are
set as a scatter graph wi th smal l box
markers. I want to pl ot the l i ters over the
sensors output, so I sel ect `l for x and
`l1 for y. Showi ng the i nverse functi on
i s si mpl y a matter of exchangi ng coordi nates
here. Exi t goes to the previ ous menu.
Photo ivThe di spl ay scal es automati -
cal l y to fi t al l the data, but you can zoom
i n or pan i n each di recti on. The dotted gri d
i s shown every 50 mV for x and 5 l for y.
Note the gap at about 5 l (after the fi fth
marker), whi ch i s due to the pump ni che.
Photo vTo draw the fi rst-order regres-
si on l i ne, just press . Other regressi on
model s (e.g., medi an-medi an, second- to
fourth-order pol ynomi al s, l ogari thmi c, and
exponenti al ) are obtai ned the same way.
Photo viThe fi rst-order regressi on i s
too coarse for rel i abl e measurements, but
i ts easy to try other curves. The second-
order one, shown here, fi ts the data ni cel y.
Photo viiZoomi ng shows that the
error at the pump ni che gap i s negl i gi bl e.
Photo viiiPressi ng ` bri ngs up the
coeffi ci ents and the regressi on formul a,
ready to be used for l i neari zi ng the
sensors output. Thanks to the second-
order characteri sti c, a ful l data tabl e i s no
l onger necessary. I can do the cal i brati on
wi th onl y three poi nts.
+ 4 V
Sensor
output
Span 35
Pump
niche
Float
Figure i
vi)
i)
Circuit Cellar INK
www.circuitcellar.com
S-q'h,h,,o,1 > `l1
S-q',h,,o,1 > `l
!o 1> h |o 0
-c-`v-'
> `l|h
ocal- 1,1, h
ocal- 1,1,
Ur`!- '-l-,: Ur`!-!rc
h-Xl
Listing 1This simple program makes 25 samples and places them in EIJ. Another list is filled with
ascending numbers used as x-axis values on an x-y graph. EIJ is the equivalent of an array in the Casio
world.
SETTING UP THE CASIO
Whi l e operati ng, the anal og i nter-
face box i s stuck to the bottom of the
cal cul ator, bel ow the LCD, wi th
TESA removabl e bi adhesi ve stri ps.
Thi s arrangement gi ves the cal cul ator
a stabl e and comfortabl e sl ope, and i t
l eaves the i nput connector i n a handy
pl ace, free from obstacl es.
To reveal the mi cro jack socket,
remove the rubber cover that comes
wi th the cal cul ator. If the jack i s l eft
unconnected or the uni t i s powered
off, a om -o message i s di spl ayed.
You dont need any parti cul ar pro-
grammi ng ski l l to use the acqui si ti on
uni t. One i nstructi on does i t al l .
Issui ng -c-`v-' di rectl y (-cv
softkey i n the N 1 menu) di spl ays
the val ue read from channel x. You
can mani pul ate the x vari abl e l i ke any
other ordi nary vari abl e, exactl y the
same way you woul d i f you entered i t
manual l y. Val ue i s expressed i n mi l l i -
vol ts, and ranges from 0 to 4095.
-c-`v-' i s usual l y i ssued under
program control , as i n Li sti ng 1. But, I
l i ke to mani pul ate graphs manual l y. Its
an i nstructi ve, hi ghl y i nteracti ve way.
Neverthel ess, every keystroke can
be repl aced by a matchi ng keyword to
be i ssued under program control .
From the programmi ng standpoi nt,
compl ex tasks (e.g., di spl ayi ng a
whol e graph or computi ng a fourth-
order regressi on) count as onl y a
si ngl e i nstructi on.
You can speci fy other vari abl e
names i nstead of x. Each vari abl e
sel ects a di fferent i nput. Vari abl es
supported are x, y, v, w, z, s, t, and u.
Other names are seen as al i ases and
wont cause errors.
FIRST GRAPH
Look at the real -worl d exampl e i n
the si debar Strai ghteni ng curves
Li neari zi ng a Tank-Level Sensor.
Here, a fl oat dri ves a potenti ometer
sensi ng the l i qui d l evel i n a 25-l , i r-
regul arl y shaped tank.
I want to fi gure out the rel ati on-
shi p between the sensor output and
the quanti ty of l i qui d l eft i n the tank
and to gather enough data to bui l d a
model for the control processor.
The compl ex rel ati onshi p between
angl e, hei ght, and vol ume makes an
anal yti cal approach i mpracti cal . It
woul d be better to measure the sensor
output at known l i qui d quanti ti es.
The potenti ometer output i s brought
to i nput x. Its powered at 4 V to avoi d
damagi ng the i nputs.
In Li sti ng 1, you see the si mpl e
control program thats requi red. `l
i s the equi val ent of an array i n the
Casi o worl d. S-q al l ocates the
memory space for a l i st and i ni ti al i zes
i t. Here, two l i stsone for the l i qui d
quanti ty and one for the sensor output
are created and fi l l ed wi th data i n a
si mpl e for-next l oop.
At each cycl e, 1 l of l i qui d i s added
and a measurement i s taken. Thi s
process conti nues unti l the tank i s
ful l . When the program ends, the two
l i sts hol d the quanti ty of l i qui d as
wel l as the sensors output l evel .
Even i f data vi sual i zati on commands
coul d be i ncl uded i n the program, i t i s
conveni ent to l ook at nonrepeti ti ve
tasks manual l y.
The S|l| menu l ets you exami ne
the data tabl es. If you sel ect the F
submenu and F1, ar1 i s then
di spl ayed as an x-y scatter graph of
`l1 (l i ters) over `l (sensor
output).
Al though nonl i near, i ts i mmedi -
atel y cl ear that the sensor output i s
sui tabl e for measurements. An anom-
al y at about 5 l , due to the presence of
a pump ni che that reduces the avai l -
abl e vol ume, i s equal l y evi dent.
MODELING DATA
By means of regressi on, the measured
data can be shaped i nto a functi on that
fi ts i nto a ni ce formul a. Formul as are
not onl y easy to i mpl ement, they al so
gi ve us a better understandi ng of the
data and can si gni fi cantl y reduce the
number of poi nts needed for cal i brati on.
In thi s exampl e, the ori gi nal data
set i s made of 26 poi nts. Knowi ng
that a sensors output i s a second-
order functi on enabl es a three-poi nt-
onl y cal i brati on wi thout appreci abl e
degradati on. The cal i brati on procedure
can then be reduced to readi ng the
output at three conveni ent posi ti ons
(empty, ful l , and hal fway).
On the Casi o, compl ex regressi ons
are a si ngl e keystroke away. When a
graph i s di spl ayed, as i n Photos v, vi ,
and vi i i n the si debar, the softkey l i ne
l i sts a vari ety of popul ar regressi on
functi ons to choose from. Pressi ng N
bri ngs out the coeffi ci ents for fi rst-order
regressi on l i ne. LlU puts a graph
over the sampl ed data.
As you see from Photo vi , a si mpl e
strai ght l i ne l eaves a l ot to be desi red.
The shi ft-zoom combi nati on bri ngs up
the zoom menu, whi l e pressi ng one of
the arrow keys pans the whol e di spl ay
i n the i ndi cated di recti on.
The ` softkey swi tches to the
second-order regressi on. Thi s ti me, the
graph i s very near to al most al l the
sampl es. The overal l resul t doesnt vary
appreci abl y regardl ess of the regressi on
order (e.g., x
3
, x
4
). Other regressi on
model s (e.g., l ogari thmi c, exponenti al )
dont gi ve si gni fi cantl y better resul ts.
You can i nteract wi th your data and
try out as many functi ons as you l i ke,
expl ori ng the possi bi l i ti es wi thout
havi ng to wri te a si ngl e l i ne of code. It
i s i mpossi bl e to l i st here al l the func-
ti ons i n the 425-page Casi o FX9750G
user gui de. Theres al so a ful l set of
stati sti cal tool suseful when moni -
tori ng producti on sampl e parameters,
weather data, pol l uti on, and so on.
Circuit Cellar INK