background image

© 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 

Summary of Contents for TSL1401-DB

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 53: ...Mouser Electronics Authorized Distributor Click to View Pricing Inventory Delivery Lifecycle Information Parallax 28317...

Reviews: