Download Print this page

Parallax TSL1401-DB Instructions Manual page 24

Linescan camera module

Advertisement

By setting allowable ranges for these two measurements, we can tell if any bottle presented to the
camera "passes" inspection. In the next section, we will see how to write a PBASIC program to perform
the various measurements required by applications similar to this one.
Programming with the TSL1401R Driver using PBASIC
Programs written in PBASIC for the MoBoStamp-pe can interact directly with the AVR coprocessor, which
handles all the TSL1401R interface details. This interaction consists of sending commands to the AVR and
waiting for results, which can then be read out to the user's PBASIC program for further action. There are
commands for setting parameters, acquiring images, counting and finding pixels, and dumping results.
Nearly all of the binary pixels processing can be done in the AVR itself at machine language speed, so it's
seldom necessary to read the actual binary pixels into your PBASIC program. But they're available
anyway if you need to examine them.
Immediate and Buffered Modes
Commands are handled by the AVR in two modes: immediate mode and buffered (deferred) mode. In
immediate mode, you send the AVR a command and it is executed right away. In buffered mode, you can
send as many as eleven bytes of commands, but they are not executed until the end-of-buffer command
is received. This makes it possible to queue up commands to acquire and analyze an image ahead of time
and then execute them all in rapid sequence when the proper moment arrives. Not all commands can be
buffered, however. The ones that cannot are the ones that send data directly to the PBASIC program as
they execute.
Sending Commands
Commands are sent to the AVR using PBASIC's OWOUT statement. For example, to begin acquisition of
a simple binary image, you would write:
OWOUT owio, 0, [ACQBIN]
The pin designator, owio, is either 6 for socket B (preferred) or 10 for socket A. The designator,
ACQBIN, is simply a constant defined in the code template at the end of this chapter. It's value is $A4.
In all the examples that follow, we shall use these predefined constants, instead of their numerical
equivalents, just to keep things as readable as possible. You will also want to use the code template
(downloadable from Parallax's TSL1401-DB product page) to make writing – and reading – your programs
easier.
Ready/Busy Polling
Some commands, such as the ACQBIN command mentioned above, require a finite amount of time to
execute before their results can be read out or another command is sent. When these commands
execute, the AVR needs to be polled until the "not busy" condition is detected. This applies only to
immediate mode, though. In buffered mode, the "not busy" bit is sent only when all the commands in the
buffer have finished executing. And it does this regardless of whether any of the commands would
require it in immediate mode. Here's a snippet of PBASIC code that does the read/busy polling:
DO
OWIN owio, 4, [busy]
LOOP WHILE busy
This reads a single bit variable, busy, and loops until it reads as a zero. It is most convenient to perform
the busy checking in its own subroutine, since it may be required more than once in your program. The
code template provides such a subroutine, named Ready.
© Bueno Systems, Inc. • TSL1401-DB (2009.10.01)
Page 24 of 52

Advertisement

loading