Sunteți pe pagina 1din 9

12 Issue 99 October 1998 Circuit Cellar INK

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

Issue 99 October 1998 13 www.circuitcellar.com


components to squeeze al l the
power out of a 9-V battery. By
the way, Il l al so tel l you how I
found the communi cati on proto-
col used by the cal cul ator.
Whi l e thi s desi gn doesnt
pretend to sol ve al l your mea-
surement probl ems at once, i ts
si mpl e, cheap, and powerful
enough to be useful i n the si tua-
ti ons I descri bed above.
Its fl exi bi l i ty makes i t i deal
for acqui si ti on i n the l ab, on the
producti on l i ne, i n the fi el d, or
wherever you need a cl ear, graphi cal ,
and i mmedi ate (yet sophi sti cated)
data di spl ay.
MACHINE MUSCLE
The data l ogger consi sts of the
graphi c cal cul atorwi th i ts 64 128
LCD screen and keyboardand the
anal og i nterface. I l eft the cal cul ator
untouched, and the anal og i nterface
fi ts i n a smal l , separate pl asti c box
(see Photo 1). They are joi ned onl y by
the umbi l i cal seri al data connecti on.
The i nterface enabl es me to read
the vol tage at up to ei ght i nputs wi th
1-mV resol uti on i n the 04096-mV
range, thanks to a 12-bi t ADC. The
data i s converted to the ri ght protocol
by a PIC mi crocontrol l er and sent to
the cal cul ator for di spl ay and storage.
Once the data i s recei ved by the
graphi ng cal cul ator, i ts i mmedi atel y
avai l abl e for graphi ng, vi ewi ng, zoom-
i ng, panni ng, or l i sti ng. You can appl y
al l the cal cul ators functi ons to your
data set, ei ther by hand or through
si mpl e programs.
Stati sti cal (e.g., l i near, exponenti al ,
pol ynomi al regressi ons, mean, or devi a-
ti on) and mathemati cal (e.g., i ntegrati on,
deri vati on) anal yses are onl y a few key-
strokes away. Al l of thi s can be done
i n the fi el d wi th no other hardware
except the l ogger i tsel fa capabi l i ty
not found i n the most expensi ve data
l oggers avai l abl e today.
The uni t i s battery powered and
works for more than 200 h on standard
batteri es whi l e retai ni ng more than
20 KB of data for at l east one year. I
use separate batteri es for the cal cul ator
and anal og i nterface. Batteri es make
thi s devi ce sui tabl e for mobi l e use, as
wel l as el i mi nati ng ground l oops, whi ch
i s a common nui sance for PC users.
USING COMPONENTWARE
Componentware i s a popul ar
buzzword i n the IT communi ty. It
stands for software enti ti es (some-
ti mes as bi g as a ful l -featured word
processor) that you can reuse as bui l d-
i ng bl ocks for other programs wi thout
havi ng to know too many detai l s.
What does componentware have to
do wi th hardware desi gn? A l ot. A 16
2 LCD, an RF tuner, and a stamp-
si zed control l er (e.g., Basi c Stamp,
Domi no, Pi cSti c, or Basi c Ti ger) com-
pri se the hardware counterpart of
componentware techni ques.
Once upon a ti me, we had l i brari es
of subci rcui ts that worked wel l . But
today, we have fat, whi te-box compo-
nents. The l i st goes on to i ncl ude DC-
to-DC converters, modem on a chi p,
LCD vol tmeters, wal l -wart power sup-
pl i es, and even a whol e PC!
Is the componentware a good de-
si gn techni que? I thi nk so. When you
have a 16 2 LCD, you dont
need to know the detai l s about
LCD pol ari zers or backl i ghti ng
probl ems. Just l eave these prob-
l ems to LCD speci al i sts, and
concentrate on your speci fi c ap-
pl i cati on.
Addi ng components together
i ncreases the abstracti on l evel
and, consequentl y, the desi gners
freedom and power. Wi th so many
probl ems al ready sol ved, you can
concentrate on sol uti ons to new
probl ems.
Al l of thi s comes at no extra
cost. Most whi te-box components
are deri ved from hi gh-vol ume
consumer devi ces. Everyone ben-
efi ts from the opti mi zed pri ce,
i ndustri al qual i ty, uni formi ty,
and reduced ti me to market.
In thi s desi gn, I go a step
further and use a graphi c cal cu-
l ator as a whi te-box component
to bui l d a data l ogger. Admi t-
tedl y, thi nki ng of a pocket cal -
cul ator as a component i s a
l i ttl e wi l d, and we may never
see such a component as a stan-
dard.
Neverthel ess, the general
approach i s effecti ve, and the
benefi ts can appl y to a number of
desi gns. For one thi ng, i t i ncreases
desi gner power, putti ng a graphi cal
LCD, a programmi ng l anguage, l ots of
memory, and PC connecti vi ty at your
di sposal .
Usi ng a cal cul ator al so cuts devel op-
ment ti me, so i t takes just days (not
weeks or even months, i f you i ncl ude
the cal cul ator math) to go from i deas to
prototype. Thi s techni que al so si mpl i -
fi es the probl em-sol vi ng path: a si mpl e
concept, si mpl e el ectroni cs, and si mpl e
software yi el d a compl ex resul t.
You al so get l ower power consump-
ti on (at l east 200 h on standard batter-
i es), whi ch i s more than 20 ti mes a
comparabl e PC-based sol uti on.
Al so, usi ng the cal cul ator cuts cost.
Just one, off quanti ty, sel l s for the
pri ce of an LCD al one. Overal l costs
are more than 20 ti mes l ess than any
PC-based sol uti on of comparabl e power.
You get i ncreased fl exi bi l i ty, l ow
cost, and an easi l y repl aceabl e fl ash-
reprogrammabl e i nput board, enabl i ng
Figure 1The unit can accommodate a variety of sensors. Up to eight
sensors can be read at the at the same time with 1-mV steps from 0 to
4096 mV. aThis setup reads temperatures ranging 0100C with a
resolution of 0.1C. bThe light sensor is placed in front of an LED to
nonintrusively monitor a devices on/off status. The diodes reduce the
maximum output to a safe 3.6 V.
LM35
+

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

Issue 99 October 1998 15 www.circuitcellar.com


i ssue vari ous characters after
that attenti on request (see
Photo 2). I qui ckl y di scovered
that the cal cul ator was wai t-
i ng for a $13 character.
A request packet from the
cal cul ator fol l ows thi s vi tal
si gn from the PC (50 bytes,
starti ng wi th :!), where
the cal cul ator defi nes the vari abl e to
be sent. As expected, al l nontri vi al pack-
ets start wi th a col on character and
are termi nated by a si mpl e negated
checksum. Wi th the excepti on of the
l ast packet, al l requi re an
acknowl edgement message from the
reci pi ent ($06).
Si nce I di dnt know how a val ue
packet i s made, I reversed the si tuati on,
maki ng the Vi sual Basi c program act
as a Casi o cal cul ator i ssui ng the
-c-`v-' command that was just
recei ved. At the same ti me, the real
Casi o cal cul ator i ssued S-rc'. In
thi s reversed setup, the cal cul ator
i ssued a 50-byte vari abl e-address packet,
starti ng wi th :\l.
I rei terated thi s process, conti nuousl y
reversi ng the sender wi th the recei ver,
someti mes si mul ati ng S-rc' and
someti mes si mul ati ng -c-`v-'.
Packet after packet, the whol e protocol
was di scovered, as depi cted i n Fi gure 2.
MAIN CODE
The software copes wi th communi -
cati on protocol s over a seri al l i ne,
combi ni ng sl eep mode and watchdog
techni ques to achi eve mi ni mal power
consumpti on, l ow-power ADC dri vi ng,
and data conversi on to the Casi o format.
Compl ete packet templ ates are stored
i n data tabl es i n program memory. At
thi s poi nt, I found !|U i nval uabl e.
Onl y segments wi th vari abl e val -
ues are repl aced by real data read from
the ADC i n real ti me. Most parts of
the i nput packet are i gnored, and onl y
the vari abl e name i s stored to sel ect
the ri ght ADC i nput. When i ssui ng
-c-`v-', you can speci fy any other
vari abl e name to sel ect a di fferent i nput.
Even the si mpl er communi cati on
protocol must deal wi th errors and
i nterrupti ons. To keep program over-
head l ow, I set up the watchdog ti mer
to reset the devi ce i f i t wai ts for an
answer from the cal cul ator for more
than 2 s.
Once reset (and for most of the ti me),
the devi ce i s l eft i n sl eep mode. Its
awakened by another WDT ti meout or
by recei vi ng a character.
In the former case, the devi ce goes
back i nto sl eep mode. In the l atter
Photo 1The circuit fits inside a small
plastic box just as large as the calculator.
The micro jack connector hangs out,
connecting to the calculator serial port. The
box is stuck to the bottom of the calculator
for operating. This arrangement gives the
calculator a stable and comfortable slope.
Photo 2I used Visual Basic to
discover the inner secrets of the
Casio protocol. With VB5 its
easy to set up a quick and dirty
serial protocol debugger. Tasks
responding automatically to a
control character, trying various
serial speeds, or sending packet
strings are left to a simple
program loop. Thanks to Visual
Basics interpretative nature, you
can stop the program, issue any
other command manually, then
continue execution. This way
you avoid writing lots of code.
Here, the characters sent by the
Casio are in red, and the analog
interface response is in black.
FX9750G), but I dont expect any
di fferences i n the protocol between
si mi l ar model s.
CASIO PROTOCOL
The Internet i s now an i nval uabl e
resource for desi gners. After a ni ght of
browsi ng, I found some commented
programs for l oadi ng cal cul ator pro-
grams to and from a PC. I found onl y
parti al i nformati on about how to trans-
mi t or recei ve si ngl e vari abl es i nstead
of programs, but i t served as a good
starti ng poi nt.
I assumed that the vari abl e transfer
format probabl y wasnt so di fferent
from the program transfer format.
Notabl y, even the offi ci al Casi o FA-122
backup software can be found onl i ne.
I knew that the communi cati on
was a 9600-bps hal f-dupl ex TTL seri al
stream, and I knew communi cati ons
shoul d start wi th ACK/NACK-styl e,
si ngl e-character messages. Packets
fol l ow, starti ng wi th col ons ($3A) and
termi nati ng wi th checksums.
I al so had PIC sampl es, some good
ready-made seri al and BCD routi nes,
and a mi crojack pl ug. Thats al l I
needed to start experi menti ng.
Usi ng a TTLtoRS-232 l evel con-
verter, I connected the cal cul ator to
the PC seri al port so I coul d moni tor
whats goi ng on.
After I i ssued the -c-`v-'
command on the Casi o, i t sent out a
$15 character and, after 1 s, i t aborted
(a $22 character sent to the PC pri or
to i nterrupt communi cati ons).
I made a Vi sual Basi c program to
16 Issue 99 October 1998 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

Issue 99 October 1998 17 www.circuitcellar.com


case, the LED fl ashes, the ADC awak-
ens, and the communi cati on fl ow
restarts.
When the mi cro sl eeps, the ADC i s
l eft i n ful l power-down mode. The
shutdown pi n i s a three-l evel sel ecti on
i nput, and the MAX186 sl eeps wi th
that pi n at 0.
It i s awakened by putti ng the pi n
i n a hi gh i mpedance state, whi ch i s
done l ong before the conversi on starts
to l et the vol tage reference capaci tor
charge compl etel y.
The MAX186 i nput can be recon-
fi gured to bi pol ar i nput mode (wi th
i nput spanni ng from V
ref
/2 to +V
ref
/2)
or pseudodi fferenti al i nput mode by
changi ng the command word that i s
ORed i n the -aclL code segment.
Fi gure 3 shows the si gnal s i nvol ved
and how the control word i s made.
The Casi o needs vari abl es i n BCD
format wi th separated exponent di g-
i ts. The most si gni fi cant di gi ts come
fi rst. The BCD conversi on and the bi t-
bangi ng seri al -port routi nes are de-
ri ved from publ i c-domai n Mi crochi p
l i brari es.
INSIDE THE BOX
The fi nal ci rcui t di agram i s shown
i n Fi gure 4. Si nce thi s i s a l ow-power,
unshi el ded, mi xed A/D ci rcui t, the
overal l resul t depends on the qual i ty
of the l ayout.
Even though were al l accustomed
to 12-bi t converters, you must take
great care to correct groundi ng so you
have stabl e readi ngs of the l east si g-
ni fi cant bi ts. The anal og and di gi tal
grounds must be kept separate. They
have to be joi ned onl y at one poi nt (as
near as possi bl e to the regul ator ground).
Bypass capaci tors are mandatory, and
capaci tors on the i nputs are equal l y
necessary.
The MAX186 has a good pi n l ayout,
whi ch hel ps separate i nput l i nes from
data l i nes, and a stabl e readout i s
easi l y obtai nabl e. But i n noi sy envi ron-
ments, consi der averagi ng i n software
to further reduce uncertai nty.
The ei ghth anal og i nput i s l eft
unconnected on the prototype. Thi s
arrangement enabl ed me to bri ng the
power out to the ni ne-pi n i nput con-
nector, thus poweri ng external sensors.
However, i ts ful l y supported by soft-
ware, so i f you need i t, si mpl y add an
i nput capaci tor and feel free to use i t.
Of course, power suppl y i s cri ti cal
i n every battery-operated devi ce.
Power-up ri se ti mes must be short
because there i s no external reset
ci rcui try for the mi cro. The MCLR
pi n i s ti ed di rectl y to V
CC
.
The l ow-power regul ator i s more
del i cate than a regul ar 78L05. It requi res
an output el ectrol yti c capaci torbetter
i f i ts tantal um.
The requi red current i s i mpul si ve,
consi sti ng of a 50-A offset (sl eepi ng
mi cro and ADC), 1.5 mA duri ng seri al
communi cati on wi th the cal cul ator, a
si ngl e pul se of 1.5 mA for a few mi l l i -
seconds (A/D conversi on), and a 1-ms
peak for LED fl ashi ng (current gi ven
by the LED seri es resi stor).
The LED fl ashes once per conversi on.
I recommend a red LED because i t
produces more l i ght wi th the same
current.
I brought the power suppl y to i nput
pi n 8 i n case some sensor needs i t. Be
sure to take sensor power requi rements
i nto account when esti mati ng battery
l i fe. If the sensor si nks a si gni fi cant
amount of current, consi der poweri ng
i t through one of the free PIC I/O pi ns,
whi ch wi l l power off when not i n use.
I assembl ed the whol e ci rcui t usi ng
a prototypi ng board, and i t fi ts i nsi de
a smal l pl asti c box thats onl y the si ze
of the cal cul ator. The box contai ns al l
the ci rcui ts and the battery. Onl y the
mi cro jack connector (connecti ng to
the cal cul ator seri al port) hangs out.
As you see from Photo 1, theres a
l ot of space l eft on the board. If possi bl e,
use a 90 jack to keep the uni t even
more compact and rugged.
Figure 4Using a graphing calculator as the output and processing device results in a simplified circuit diagram. The 5-V power rail is brought to the input connector to feed
external sensors. If the quiescent current does not concern you, then the popular 78L05 can replace the LP2950CZ.
18 Issue 99 October 1998 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

Issue 99 October 1998 19 www.circuitcellar.com


Alberto Ricci Bitti is a software de-
signer at Eptar, an industrial-control-
ler firm. He has written software for
systems such as meteorological
equipment, specialized TV sets, pro-
fessional satellite devices, industrial
machinery controllers, and energy-
management devices. You may reach
Alberto at a.riccibitti@ra.nettuno.it.
SOFTWARE
Source code i n offi ci al Mi crochi p
mnemoni cs i s avai l abl e vi a the
Ci rcui t Cel l ar web si te.
SOURCES
PIC16C84, PIC16F84
Mi crochi p Technol ogy, Inc.
(602) 786-7200
Fax: (602) 786-7277
www.mi crochi p.com
MAX186
Maxi m Integrated Products
(408) 737-7600
www.maxi m-i c.com
FX9750G
Casi o El ectroni cs Co., Ltd.
www.casi o-usa.com
LM2936, MAX186, PIC16C84,
PIC16F84
Di gi -Key Corp.
(218) 681-6674
Fax: (218) 681-3380
www.di gi -key.com
REFERENCES
MPLAB IDE free assembl er and
si mul ator software, 1997 techni cal
l i brary, www.mi crochi p.com.
Casi o, FA-122 software and PC l i nk
schemati cs, members.tri pod.com/
~carol i no/.
Casi o, FX9750G User Guide,
A340606-27.
Maxi m Integrated Products, MAX186
MAX188 low-power, 8-channel,
serial 12-bit ADC, Datasheet 19-
0123, August, 1996.
Maxi m Integrated Products, MAX192
low-power, 8-channel, serial 10-bit
ADC, Datasheet 190123, March,
1994.
Mi crochi p Technol ogy, PI Cmicro
mid-range MCU family reference
manual, Datasheet DS33023A,
December 1997.
A BROADER VISION
Si nce thi s desi gn was announced i n
I NK 95, Ive recei ved l ots of E-mai l
from i nterested readers. Each one had
a di fferent vi si on of what thi s l i ttl e
desi gn can be used forfrom tracki ng
the accuracy of a GPS-l ocked PLL and
pl otti ng weather data, to shovi ng a
waveform from an i nstrument and
moni tori ng a central heaters operati on,
or counti ng peopl e comi ng i n a door.
The number of possi bl e appl i cati ons
expl oded. Bui l t-i n di spl ay and the capa-
bi l i ty of bei ng programmed, combi ned
wi th very l ow cost, are the key factors.
I encourage you to expand the capa-
bi l i ti es of the data l ogger. The code i s
ful l y commented, and the PIC program
memory i s onl y hal f ful l .
I do have a coupl e suggesti ons. As a
fi rst step, try addi ng a pul se-counter
mode. There are l ots of thi ngs worth
counti ng, and many sensors (e.g., Steve
and Jeffs l i ghtni ng sensor [I NK 90])
have pul se outputs.
Secondl y, dri ve outputs by i mpl e-
menti ng the Casi o command S-rc'
to make the i nterface bi di recti onal .
The Casi o i s sl ow but powerful enough
to read i n the i nput, make some com-
putati ons, and send output to the
outsi de worl d. In thi s way, i t woul d
mi grate from the worl d of moni tori ng
and di spl ayi ng events to the broader
worl d of (pocket) computer control . I
Circuit Cellar INK, the Computer Applications Journal.
Reprinted by permission. For subscription information,
call (860) 875-2199 or subscribe circellar.com
DALLAS
NEW
#23
4C
PG. 23

S-ar putea să vă placă și