April
2004, Issue 165
BasicCard
101 (Part 2):
Use in a Liquid Nitrogen Monitor
by
Brian Millier
Now
that you’re familiar with ZeitControl’s BasicCard,
it’s time to take a closer look at the process of
programming one and incorporating it in a design.
Brian shows you how he integrated BasicCard technology
in the design of a liquid nitrogen generator.
Start
Interface
to the AVR MCU
Card
Firmware
Give
it a Try
Sources
and PDF
Last
month, I introduced you to ZeitControl’s BasicCard,
which is a smartcard that is programmed in Basic. In
Part 2, I’d like to further explore the programming
of these cards and discuss a project.
I
built a device that allows you to use BasicCards like
debit cards to control the dispensing of liquid from
a liquid nitrogen generator/storage tank. The idea is
to issue each liquid nitrogen user here at Dalhousie
University with a BasicCard. Each card is personalized
by entering the user’s name, account number, and a zero
balance. Card personalization is done on a PC using
a Windows-based application. This user-friendly application
interfaces to the BasicCard using the CyberMouse reader
that comes with the development kit.
To
access some liquid nitrogen (LN2), insert your BasicCard
into the custom controller connected to the 2 generator.
The controller checks to ensure that the card is properly
personalized for this use, and displays your name, account
number, and the number of liters of 2 previously consumed
during the current billing period. You then enter the
amount of 2 desired on the controller’s keypad. After
updating the BasicCard EEPROM variable, which stores
the accumulated 2 usage, the controller activates
a relay that opens a valve and lets the liquid nitrogen
flow for a long enough period to dispense the necessary
amount of 2.
Periodically,
the BasicCards are collected and another PC application
is run that zeroes out the accumulated 2 total. It
transfers that figure to a table that is used for the
actual billing process.
In
the past, an honor system was used in which users entered
their 2 usage on a sign-out sheet posted next to the
generator. We lost some 2 billings here at the university
because of dishonesty and low-ball estimates of the
actual amounts taken. Also, there was a significant
amount of clerical time spent tallying all of the entries
on the daily sign-up sheets.
CIRCUIT
DETAILS
Because
the prototype would be the only unit I would need, I
wanted to use a commercial development board and just
add the few custom parts needed for the design. I chose
the Futurlec 8535 development PCB because it’s inexpensive,
contains headers for commonly used peripherals, and
has a large enough prototype area to mount the few extra
components I needed to complete the design.
Figure
1 is a diagram of the circuit. Some of the circuitry
on the Futerlec board that is not required for this
project is not shown in the diagram. For example, the
in-circuit serial programming port for the 8535’s flash
program memory is not shown. There is one small change
that I had to make to the Futurlec board itself. The
board comes fitted with an 8-MHz MCU clock crystal.
I changed that to 3.579 MHz so that I could use a common
clock for both the MCU and BasicCard, which has a 5-MHz
maximum clock rate and communicates at 9600 bps when
clocked at 3.579 MHz.
|

(Click
here to enlarge)
|
Figure
1—The liquid nitrogen dispensing monitor was built
on a Futurlec 8535 development board. Apart from
the card socket, keypad/LCD, and relay driver, most
of the circuitry already exists on the development
board. |
I
mounted an Amphenol C702 10M0008 2834 smartcard socket
in the prototype area of the PCB. This socket contains
an NC switch that opens up when a card is inserted,
making it easy for the MCU to know when to establish
communications with the card. Although I connected this
line to port D3 of the ’8535 (INT1), I don’t use this
pin as an interrupt input, instead I poll the pin to
see when a card is either inserted or removed. There
are a few different phases in the program, and the removal
of a card must be handled differently in each case,
so using an interrupt to signal card-in-socket status
was not ideal for this project.
The
BasicCard interfaces to the ’8535 using only two port
lines. The *RESET input to the BasicCard is connected
to port D2, and the I/O line connects to port D4. As
I mentioned earlier, the BasicCard gets its clock signal
directly from the ’8535’s XTAL1 pin, which is its oscillator
buffer output. Although you have to be careful tapping
off a clock signal from an MCU’s oscillator output,
the BasicCard presents, in this case, such a small load
that the oscillator is unaffected by its presence.
The
user interface is the standard keypad/LCD. I had a Grayhill
series 88 keypad on hand, which contains the numbers
in a telephone-like arrangement, as well as several
extra keys labeled Enter, Clear, etc. that provide all
the necessary input functions. Eight lines are needed
to interface this Matrix keypad, and I used port A for
that purpose. Doing so meant I could not make use of
the eight-channel ADC contained in the ’8535, but I
didn’t need an ADC for this project. The Futurlec board
has a 10-pin header connected to this port, which made
it easy to connect the keypad using a ribbon cable.
I
didn’t need a large LCD, because there isn’t a lot of
information to display. Therefore, I used a 2 × 16 display,
and connected it to the ’8535 in 4-bit mode using six
lines of port C. The Futurlec board also provides a
14-pin header for the LCD, with all the signal and power
wiring taken care of, as well as POT1 for contrast adjustment.
Apart
from wiring a few lines to the smartcard socket, all
the circuitry I needed to add was the driver and relay
to activate the dispensing valve. This was a solenoid
valve that required 120 VAC to operate, so I decided
to use a relay to keep any inductive kickback from its
coil away from the MCU circuitry. Any relay with a 12-V
coil and contacts able to switch 1-A AC will do for
K1. If the coil needs more than a few hundred milliamps
to operate, you’ll need a larger transistor than a 2N3904
for Q1. Diode D1 is placed across the relay coil to
protect Q1 from the spike that occurs when the relay
turns off.
The
5-V power supply regulator is contained on the Futurlec
PCB, but the power transformer, bridge, and filter capacitor
are mounted externally. Photo 1 shows the development
board with the extra components needed for this project.
|

(Click
here to enlarge)
|
Photo
1—Check out the monitor before it’s mounted in its
cabinet. Note the BasicCard sticking out of the
card socket on the right-hand side. |
The
development board comes with a MAX232 for RS-232 communications
purposes. Although I did not use this feature, it would
be easy to wire the controller to a remote PC, for example,
if you want to log all the transactions in real time
to a computer file.
Atmel’s
AT90S8535 is a versatile MCU. In some respects it is
overkill for this application. With the program written
in compiled Basic, much of its 8-KB flash program memory
is unused. It contains 512 bytes of EEPROM, which is
unused apart from a few bytes used to store some valve
time calibration parameters. The eight-channel ADC,
UART, and SPI functions weren’t needed either. However,
the assembled Futurlec development board, including
the ’8535 MCU and programmer cable, cost less than $30,
so I thought it made a lot of sense to do things this
way.