© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 27 of 52
OWOUT owio, 0, [DUMPFLAGS]
OWIN owio, 0, [flags]
IF (flags = $FF) THEN
OWOUT owio, 1, [DUMPFLAGS]
OWIN owio, 0, [flags]
ENDIF
The first
DUMPFLAGS
is sent without a prepended reset. Then the byte variable
flags
is read and
compared with
$FF
. If it’s equal, that means the firmware is waiting for a reset, so
DUMPFLAGS
is sent
again – this time with a prepended reset (the
1
in the
OWOUT
command). At the end of this entire
sequence, the variable
flags
will contain either the error flag, which can be ANDed with one or more of
the error constants defined above to determine which error occurred, or zero, indicating that no error
occurred. The above sequence is included in the code template as the subroutine
GetError
.
Finally, is the
DUMPADR
command, which is used to read results from the driver’s memory. Its format
is:
DUMPADR, Address
DUMPADR
is a constant from the code template equal to
$DA
. Following it is an address byte, which
can range from
0
to
47
(
$2F
). Once these two bytes are sent, the firmware expects your program to
begin reading data using
OWIN
. It will continue sending data until a reset is received, at which point the
internal address pointer is reset to
RESULTS
(
$20
). Here’s an example for reading the average pixel
value from the last scan:
OWOUT owio, 0, [DUMPADR, AVGPIX]
OWIN owio, 2, [average]
Here,
AVGPIX
is a constant from the template, equal to
$24
, and
average
is a byte variable used to
hold the result.
Setting Exposure Time
The TSL1401R driver acquires all images using one-shot imaging, as described above in the “Interface
and Basic Operation”
section. It handles the exposure (integration) time details for you. All you have to
do is tell it how long you want each exposure to be. This is done with the Set Exposure command:
SETEXP, ExpTime
SETEXP
is a constant defined in the code template that follows, whose value is
$EE
(mnemonic for
“enter exposure”).
SETEXP
requires one argument,
ExpTime
, the actual exposure time, which can
range from
1
to
255
and represents a time span of 267µS to 68mS.
Note:
Because exposure timing is
based on the AVR’s internal RC clock, these times are approximate and can vary with temperature.
Here’s a statement that sets the exposure time to
30
(about 8mS):
OWOUT owio, 0, [SETEXP, 30]
Once the exposure time is set, it stays set until changed by another
SETEXP
. If you never set the
exposure time explicitly, it defaults to a value of
128
.
Setting Binary Acquisition Coefficients
When a binary image is acquired, each pixel is first read from the AVR’s A/D converter as a value
between 0 and 255. Then it’s converted to a
0
or a
1
, depending on the values of the three coefficients