© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 6 of 52
The following PBASIC code fragment (taken from the complete program template shown later in this
section) can be used to read a single scan from the TSL1401-DB. It consists of five lines of code, which
are shown and discussed individually:
SHIFTOUT SI, CLK, 0, [1\1]
SI
and
CLK
are defined in the larger program’s preamble as
PIN
s and connect to like-named ports on
the TSL1401-DB. This statement clocks out
SI
as a single bit of synchronous serial data, which starts a
new exposure interval.
PWM CLK, 128, 1
We want to clock through all 128 pixels as fast as possible, since we’re just timing an exposure here, not
reading data. The
PWM
statement fits the bill perfectly. The
128
in this statement is the duty cycle
(50%), not the number of pulses. The number of pulses is given by the
1
, which represents the length of
time to output the PWM signal. For the BS2, this is nominally 1mS. (Actually it’s more like 1.2mS and
consists of about 150 cycles.)
PULSOUT SI, exp >> 1 MIN 1016 - 1016
This statement sets the exposure time.
exp
can be either a constant or a variable and represents the
length of the exposure in microseconds. The reason for using
PULSOUT
instead of
PAUSE
, say, is that
the timing resolution is so much finer. And the reason for sending the pulse on
SI
is that it’s not used for
anything else durng this time, and, so long as we don’t clock the pulse with
CLK
the sensor chip is
unaffected. The value subtracted from the pulse width (1016) represents the timing overhead from the
PBASIC program, minus the start-of-integration delay to the 18
th
clock in the
PWM
statement. This
means that the minimum exposure time will be about 2.032mS.
Note:
Timings for BASIC Stamps other than the BS2 will vary, and the value subtracted will need to
be adjusted accordingly.
SHIFTOUT SI, CLK, 0, [1\1]
This clocks out the
SI
pulse again to end the exposure and begin actual data readout.
SHIFTIN AO, CLK, LSBPRE, [pdata(0)\16, pdata(1)\16, pdata(2)\16, pdata(3)\16]
SHIFTIN A0, CLK, LSBPRE, [pdata(4)\16, pdata(5)\16, pdata(6)\16, pdata(7)\16]
These two statements read 128 bits of thresholded pixel data from the
AO
pin into an eight-position
word array, declared
pdata word(8)
, least-signficant bits first. Doing it “inline” like this is faster than
doing it in a loop.
Here are the waveforms from the above acquisition routine, with the various sections annotated:
Tri-
Stated
Tri-
Stated
Tri-
Stated
1
129
1
2 3 4 5 6 7 8 9 10
. . .
129
SI
CLK
AO
SHIFTOUT
SHIFTOUT
SHIFTIN16 x 8
PWMOUT
PULSOUT
IDLE
IDLE
150
2V Input Threshold
Thresholded Data