background image

© Bueno Systems, Inc.  •   TSL1401-DB (2009.10.01) 

Page 5 of 52

 

 

Operation with the BASIC Stamp 

This  section  explains  how  to  use  the  TSL1401-DB  directly  with  a  BASIC  Stamp.  If  you  have  the 
MoBoStamp-pe  BASIC  Stamp  2pe  motherboard,  you  can  skip  this  section  and  proceed  to  the  section 
titled “Operation with the MoBoStamp-pe”. 

Connection 

The  following  illustration  shows  how  to  connect  the  TSL1401-DB  to  a  BASIC  Stamp,  using  Parallax’s 
Board of Education and a DB-Expander board: 
 

Vdd

Vin

Vss

P15
P14
P13
P12
P11
P10
P9
P8
P7
P6
P5
P4
P3
P2
P1
P0

 

 

The signal pinouts and port usage shown above are consistent with the examples to follow in this section. 
You can also use the DB-Extension Cable (p/n 500-28301) to separate the TSL1401-DB from the DB-
Expander board if you need to. 

Image Acquisition 

The  output  of  the  TSL1401R  is  an  analog  signal,  but  the  BASIC  Stamp  does  not  have  analog  input 
capability (except via RCTIME, which isn’t fast enough to read 128 pixels). How, then, is it possible to use 
this  device  with  a  BASIC  Stamp?  We  do  it  by  connecting  the 

AO

  signal  directly  to  one  of  the  Stamp’s 

digital inputs. When done this way, the BASIC Stamp will threshold the analog input. Anything over about 
2  volts  will  read  as  a 

1

;  anything  under,  as  a 

0

. By treating the signal this way, it’s possible to input a 

string  of 

1

s  and 

0

s  that  represent  light  and  dark  portions  of  the  “scene”  being  recorded.  A  complete 

scan,  then,  would  require  128  bits  of  data  (i.e.  16  bytes,  or  8  words),  which  the  BASIC  Stamp  can 
accommodate handily. 
 
Once these bits have been read in, it’s possible to analyze “features” of the scene by looking for groups 
of light and dark pixels. For example, if you wanted to measure the width of a light object against a dark 
background, you could read in the image, then count the number of “1” bits in the data. Likewise, if you 
wanted sense the edge of a “web” (e.g. paper in a paper mill) to keep the web on track, you would look 
for the first occurrence of a light or dark pixel in each scan. 
 

Содержание TSL1401-DB

Страница 1: ...subject or the sensor in a direction perpendicular to the sensor axis Features Provides vision in one dimension with 128 pixel resolution Three line serial interface with analog intensity output for e...

Страница 2: ...rm images on the sensor array What results is somewhat like peering through the narrow crack of a partially opened door to see a thin slice of what lies behind it The illustration below helps to expla...

Страница 3: ...without external strobing or syncing there are only three signals that need to be considered SI digital output to the sensor begins a scan exposure CLK digital output to the sensor latches SI and clo...

Страница 4: ...tegrate Scan n 1 In one shot imaging the TSL1401R is left idle until it s time to snap a picture Then SI clocked in and 128 pixels are rapidly clocked out and discarded Then you simply wait until the...

Страница 5: ...ty except via RCTIME which isn t fast enough to read 128 pixels How then is it possible to use this device with a BASIC Stamp We do it by connecting the AO signal directly to one of the Stamp s digita...

Страница 6: ...on 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...

Страница 7: ...ls needed to be read in LSB first Here s how the word and bit arrays are declared pdata VAR Word 8 pixels VAR pdata BIT0 Counting light or dark pixels within a given range is simple Here s the code th...

Страница 8: ...s with a dark pixel then transisitions to a light one The FindPix routine can be used to find edges too by looking for the first pixel opposite of the edge you re seeking then the next pixel after tha...

Страница 9: ...es seeking DRK or BRT pixels edges dir VAR Bit Indicates direction of search FWD or BKWD found VAR Bit Indicates pixels found 1 or not found 0 Program Code NOTE This code assumes that DEBUG will wrap...

Страница 10: ...16 pdata 5 16 pdata 6 16 pdata 7 16 RETURN DispHdr Display a header to aid in identifying pixel positions DispHdr FOR i 0 TO 12 Display tens digits DEBUG DEC i DIG 0 IF i 12 THEN DEBUG ELSE DEBUG CR N...

Страница 11: ...are thresholded and converted to single bits it s still possible to obtain a picture of each pixel s analog value at least for static subjects that don t move The voltage output from any given pixel i...

Страница 12: ...EXT Continue with next lower intensity level END Here s what the output looks like when viewing a bagel lighted from the front You can see where the hole is as well as the outside edges However this a...

Страница 13: ...time It s called TSL1401_monitor exe and it can be downloaded for free from the Parallax website Just copy it to the directory of your choice With the MoBoStamp pe TSL1401 DB the camera connected to y...

Страница 14: ...be received Acquisition Control You can start and stop scanning with these controls or obtain scans one at a time Exposure Controls These set the exposure type and time Exposure times can be either f...

Страница 15: ...xel as a gray level The next slice up shows which pixels register as light pixels after thresholding The top slice is used to show image analysis results in yellow when those results include location...

Страница 16: ...have a cosine shaped brightness contour when imaged with the camera Image from Backlight Only Showing the Cosine Effect Different ways of dealing with this effect are discussed later in the section I...

Страница 17: ...ansition from light to dark a pixel s level must sink below the lower threshold Excursions into and out of the hysteresis band without crossing it completely will not result in a dark to light or ligh...

Страница 18: ...ising edges are detected in this case as indicated by the green area in the narrow strip below the scope window In fact one of the most important applications of floating thresholds is edge detection...

Страница 19: ...to zero and the hysteresis to a level consistent with how much texture we want to call good Also we ll use window comparison so that rising and falling pixel values get treated equally Here is an exam...

Страница 20: ...ch the conditions Extreme Dark Pixel Least bright pixel Extreme Light Pixel Brightest pixel Average Mean value of the feature s matching the conditions Dark Edge Light to dark transition reading from...

Страница 21: ...ed earlier There are multiple possible ways of correcting for this effect These include Storing a brightness contour and dividing each captured pixel level by its contour value not possible with the A...

Страница 22: ...09 10 01 Page 22 of 52 In the next pair of images you can see the difference between a full bottle and one that s not so full To find the liquid level we use the First Dark Object Location measurement...

Страница 23: ...TSL1401 DB 2009 10 01 Page 23 of 52 In the next pair of images you can see the difference between a bottle that s capped and one that s not Here we use the Last Dark Object Area measurement Capped Bot...

Страница 24: ...ent 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...

Страница 25: ...mmand sequence saved there must be reloaded each time it is used Resetting the Driver PBASIC s OWOUT and OWIN commands include a provision for sending a reset pulse to the AVR The TSL1401R driver will...

Страница 26: ...7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 BADCMD CANTBUF CMDOVF DATOVF 0 0 0 0 The four most significant bits are the error flags A flag bit is set to 1 if its associated error has occurred since th...

Страница 27: ...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 u...

Страница 28: ...te 0 or 1 After that each pixel is compared with either Threshold Hysteresis if the last comparison yielded a 0 or Threshold Hysteresis if the last comparison yeilded a 1 Both Threshold and Hysteresis...

Страница 29: ...rightness of the LED flashes as shown here The basic format for this command is SETLED Amount Where SETLED is a constant equal to EB mnemonic enter brightness and Amount has the following format Bit 7...

Страница 30: ...ght between pairs of scans ACQXORNOT A7 Acquire a binary image XORing the binary pixels with the NOT of the previous image This can be used in successive pairs to see which pixels remain the same betw...

Страница 31: ...access to the gray level pixel values as it reads them out from the TSL1401R Since there isn t enough memory in the AVR to store all these values they have to be sent to the BASIC Stamp on the fly For...

Страница 32: ...esulting from even illumination and a fast readout The little blips at the ends are due to a lensing effect from the edge of the clear chip package They do not appear when an imaging lens is in place...

Страница 33: ...ion commands Name Addr Description PIXELS 00 to 1F Binary subpixel data Pixels are packed LSB first Since there are only 255 pixels the last pixel MSB of location 1F is always 0 MINPIX 20 Intensity 0...

Страница 34: ...an be used with i e ORed to CNTNEW or CNTNXT are Name Value Description DRKPIX 00 Count dark pixels BRTPIX 02 Count bright pixels DRKEDG 03 Count dark high to low edges BRTEDG 01 Count bright low to h...

Страница 35: ...0 CNTNEW DRKPIX 32 64 GOSUB Ready OWOUT owio 0 CNTNXT DRKEDG GOSUB Ready OWOUT owio 0 DUMPADR RESULTS 5 OWIN owio 2 dark_count edge_count Note that because these commands are executed immediately we...

Страница 36: ...ect which end to start the search from Searching forward starts from the Left limit and scans towards the right until either the desired feature is found or the Right limit is reached Searching backwa...

Страница 37: ...e has to be a dark pixel first followed by a light one So given the same image as above we find our edge at location 48 as highlighted 0000111000 11111111000000001111110000111111 1111100000 31 32 64 6...

Страница 38: ...bright hole What we re after here is the diameter of the bagel we don t care about the hole This is where a backward search comes into play First we locate the first bright to dark edge scanning forw...

Страница 39: ...hen is encountered when executing from the buffer the internal results pointer is reset to RESULTS 20 That means further results will be appended to the buffer beginning at that point Do not buffer th...

Страница 40: ...l see it at least once Finally we assume that the conveyor spans the entire field of view and that there are no crumbs on it to confuse the camera In real life we would have to question every one of t...

Страница 41: ...dges 14 If we found the right edge the left edge is there too 15 The current diameter is rgt_edge lft_edge 1 If that s greater than the maximum diameter seen so far on this bagel make it the maximum d...

Страница 42: ...Then comes the call to Ready because right then we want to read some new data which we do on lines 19 and 20 Now when we loop back we can prime the next exposure right away and then get on with our ar...

Страница 43: ...DG FNDNXT BKWD DRKEDG OWOUT owio 0 FNDNXT BKWD BRTEDG GOSUB Ready OWOUT owio 0 DUMPADR PIXELS DEBUG CLS FOR i 0 TO 31 OWIN owio 0 pix DEBUG BIN8 pix REV 8 IF i 7 7 THEN DEBUG CR NEXT OWOUT owio 1 DUMP...

Страница 44: ...7 Wait for everything that s been cued up to finish 18 Start dumping the binary pixels 19 24 Display the binary pixels in four lines beginning two lines down from the previous output 25 Start dumping...

Страница 45: ...tes the rule in action It uses the LEDs on the MoBoStamp pe to indicate the current light level Red is too high green is too low yellow red and green together is just right red PIN 13 Pin for red LED...

Страница 46: ...above You can also download it from the Parallax website to use with these examples and with your own programs File tsl1401_template bpe Purpose Code template for the TSL1401 DB driver firmware Autho...

Страница 47: ...DNXT NXT CON 00 Continue from where last CNT or FND left off BKWD CON 04 Search backward FWD CON 00 Search forward DRKPIX CON 00 Target is a dark pixel BRTPIX CON 02 Target is a bright pixel DRKEDG CO...

Страница 48: ...ot busy Ready DO OWIN owio 4 busy Read busy bit LOOP WHILE busy Keep checking until it goes low RETURN GetError Read the error flags from the driver GetError OWOUT owio 0 DUMPFLAGS Read the error flag...

Страница 49: ...imits Begin End CNTNXT C0 Count pixels edges between current limits None FNDNEW F8 Find pixels edges between new limits Begin End FNDNXT F0 Find pixels edges between current limits Yes Yes FWD 00 6 BK...

Страница 50: ...et that cover this important topic A few of the better ones can be found at these URLs Melles Griot http www mellesgriot com products machinevision lif_1 htm Advanced Illumination http advill com uplo...

Страница 51: ...nd edges 33 D DATOVF 26 47 DB Expander 1 3 5 Driver firmware 13 DRKEDG 34 35 36 37 38 39 43 47 49 DRKPIX 34 35 36 47 49 DUMPADR 25 26 27 31 34 35 37 38 39 40 42 43 45 47 49 DUMPFLAGS 26 27 39 47 48 49...

Страница 52: ...1 44 47 48 49 RESULTS 25 27 34 35 37 38 39 40 41 42 43 47 S Schematic 50 SETBIN 28 29 31 37 38 39 40 42 43 46 49 SETEXP 27 31 37 38 39 40 42 43 45 47 49 SETLED 29 SI 3 4 6 9 10 StrobeLED DBM 14 29 T T...

Страница 53: ...Mouser Electronics Authorized Distributor Click to View Pricing Inventory Delivery Lifecycle Information Parallax 28317...

Отзывы: