TSL1401-DB

Hello!

I have a TSL1401-DB mounted to BS2pe_MOBO board. I'm using the monitor program to see the output of the sensor. Basic operation is working. I attempted to make use of the Triggered acquisition without success.

I'm driving the ST pin on the 6 pin header of the daughter board. A high here causes a low on jumper J2 (jumper is installed). J2 connects to the MoBo board through the 12 pin header to P3 of the BS2pe processor. According to the documentation a high to low transition should initiate an acquisition. I don’t see evidence of the acquisition as the scope window on the monitor program doesn’t update. Interesting to note is that I can get Gated acquisitions to work: scope window updates continue while P3 is low.

Any ideas?

Thx,
Rob

Comments

  • 18 Comments sorted by Date Added Votes
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,350
    edited November 2016 Vote Up0Vote Down
    Hey Rob,

    I'm the designer of the BS2pe_MOBO and the TSL1401-DB, and I'm the author of the monitor software. 'Sorry you're having trouble with the triggered mode. In ten years, you're probably the first person to try it! So ... I'll have to take a look at the AVR firmware to see what's going on.

    BTW, do you have another daughterboard plugged into the other socket? The reason I ask is that P2 and P3 are shared between both sockets.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Hi Phil,

    No, socket A is unused. The daughter board uses socket B.

    Rob
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,350
    edited November 2016 Vote Up0Vote Down
    No solution yet, but I do have a workaround. In the monitor program, if you enable Ext. Sync, triggering seems to work. The reason is that, in this mode, triggering is handled by software in the BS2pe program, not by the AVR firmware.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • So enable Triggered with Ext. Sync also enabled?
  • Yes.
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • That worked. Thx.

    By the way, is there any way to get the raw sensor data out to a file? Do you use the ATTiny's ADC to convert the sensor's output?

    Thx,
    Rob
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,350
    edited November 2016 Vote Up0Vote Down
    Yes, I do use the ATTiny's ADC to read the sensor's analog output.

    Here's a program that will dump pixel values to the debug screen in CSV form. From there you can copy and paste into a file, if you like:
    ' =========================================================================
    '
    '   File...... tsl1401_dump_gray.bpe
    '   Purpose... Dump pixel values from the TSL1401-DB using the MoBoStamp-pe.
    '   Author.... Phil Pilgrim
    '   E-mail.... propeller@phipi.com
    '   Started... 22 Dec 2010
    '   Updated...
    '
    '   {$STAMP BS2pe}
    '   {$PBASIC 2.5}
    '
    ' =========================================================================
    
    
    ' -----[ Program Description ]---------------------------------------------
    
    ' This program dumps analog pixel values from the TSL1401-DB via the
    ' TSL1401.hex firmware for the MoBo's AVR coprocessor.
    
    ' -----[ I/O Definitions ]-------------------------------------------------
    
    owio            PIN     6     'Pin for OWIN and OWOUT to AVR coprocessor.
    
    ' -----[ Constants ]-------------------------------------------------------
    
    ' Commands
    
    SETLED          CON     $EB   'Set LED strobe and brightness/time from next byte.
    
      'Flag to OR to brightness/time (0 - 127) value.
    
      TIME          CON     $80   'Set strobe: value (0 - 127) is 0 - 3.4mS at 100% on.
      INTEN         CON     $00   'Set intensity: value (0 - 127) is 0 - 49.6% on.
    
    SETBIN          CON     $EC   'Set threshold, hysteresis, and filter (3 bytes).
    
      'Filter flags.
    
      FLOAT         CON     $80   'Threshold is floating per filter value (0 - 7).
      FIXED         CON     $00   'Threshold is fixed.
      WINDOW        CON     $40   'Threshold is a window (outside of hysteresis band).
      LEVEL         CON     $00   'Threshold is a level with hysteresis.
    
    SETEXP          CON     $EE   'Set exposure to byte (1 - 255) following: 0.27 - 68mS.
    
    ACQGRAY         CON     $A0   'Acquire and dump a grayscale image.
    ACQBIN          CON     $A4   'Acquire a binary image.
    ACQAND          CON     $A1   'Acquire binary image ANDed w/ previous.
    ACQOR           CON     $A2   'Acquire binary image ORed w/ previous.
    ACQXOR          CON     $A3   'Acquire binary image XORed w/ previous.
    ACQANDNOT       CON     $A5   'Acquire binary image ANDed w/ NOT prev.
    ACQORNOT        CON     $A6   'Acquire binary image ORed w/ NOT prev.
    ACQXORNOT       CON     $A7   'Acquire binary image XORed w/ NOT prev.
    
    ACQDIFF         CON     $A3   'Idiom for ACQXOR.
    ACQSAME         CON     $A7   'Idiom for ACQXORNOT.
    
      XTRIG         CON     $08   'External trigger flag, ORed to ACQ commands.
    
    CNTNEW          CON     $C8   'Count pixels/edges between new bounds.
    CNTNXT          CON     $C0   'Count pixels/edges between current bounds.
    FNDNEW          CON     $F8   'Find first pixel/edge between new bounds.
    FNDNXT          CON     $F0   'Find first pixel/edge between current bounds.
    
      'Modifiers, ORed to CNTNEW, CNTNXT, FNDNEW, and FNDNXT.
    
      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        CON     $03   'Target is a bright-to-dark edge.
      BRTEDG        CON     $01   'Target is a dark-to-bright edge.
    
    DUMPADR         CON     $DA   'Dump data, beginning at addr, and until reset.
    
      'Address constants for single byte arg following DUMPADR.
    
      PIXELS        CON     $00   'Beginning of binary pixel buffer (32 bytes).
      RESULTS       CON     $20   'Beginning of results buffer.
      MINPIX        CON     $20   'Value of darkest pixel (0 - 255).
      MINLOC        CON     $21   'Location of darkest pixel (0 - 127).
      MAXPIX        CON     $22   'Value of brightest pixel (0 - 255).
      MAXLOC        CON     $23   'Location of brightest pixel (0 - 127).
      AVGPIX        CON     $24   'Average pixel value (0 - 255).
    
    DUMPID          CON     $DD   'Dump the firmware ID (returns 3 bytes).
    
    DUMPFLAGS       CON     $DF   'Dump error flags (returns 1 byte).
    
      'Bit positions in returned byte.
    
      BADCMD        CON     $80   'Unrecognized command.
      CANTBUF       CON     $40   'Attempt to buffer unbufferable command.
      CMDOVF        CON     $20   'Command buffer overflow.
      DATOVF        CON     $10   'Result data buffer overflow.
    
    ' -----[ Variables ]-------------------------------------------------------
    
    flags           VAR     Byte
    busy            VAR     Bit
    
    ' -----[ Initialization ]--------------------------------------------------
    
    PAUSE 10                      'Wait for AVR to finish reset.
    
    ' -----[ Program Code ]----------------------------------------------------
    
    EXPTIME        CON       60
    i              VAR       Byte
    j              VAR       Byte
    char           VAR       Byte(16)
    
    DO
      OWOUT owio, 1, [SETEXP, EXPTIME, ACQGRAY]
      GOSUB Ready
      FOR i = 0 TO 7
        OWIN owio, 8, [STR char\16]
        FOR j = 0 TO 15
          PUT i << 4 + j, char(j)
        NEXT
      NEXT
      FOR i = 0 TO 127
        GET i, char
        IF (i = 127) THEN
          DEBUG DEC char(15), 13, 13
        ELSE
          DEBUG DEC char, ","
        ENDIF
      NEXT
    LOOP
    END
    
    ' -----[ Subroutines ]-----------------------------------------------------
    
    ' -----[ Ready ]-----------------------------------------------------------
    ' Wait for the driver to become not 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 flags.
      OWIN owio, 0, [flags]
      IF (flags = $FF) THEN        'If $FF, driver is waiting for a reset.
        OWOUT owio, 1, [DUMPFLAGS] 'So reset and try again.
        OWIN owio, 0, [flags]
      ENDIF
      RETURN
    

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Finally got back up to speed on triggering. Triggering and gating use two different pins. To cause a trigger, momentarily ground pin P2 on the MoboStamp's A receptacle, then release it. The rising edge will trigger a scan when triggering is enabled. BTW, P2 has a pull-up to Vdd, so you do not need to drive it high. An open-collector driver works just fine.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • So the documentation is incorrect???

    From the documentation: seems to say triggering and gating use the same pin

    Trigger/Sync Control: Scans can be free-running, triggered, or gated. Triggering and gating
    are controlled by Pin 3, which is a BS2pe port common to both daughterboards. When triggering
    is set, a high-to-low edge on Pin 3 will cause a single scan to be acquired. When gating is set,
    scans will be obtained continuously while Pin 3 is low

    In another place the documentation states:indicating P3 of the STAMP processor is used for triggering

    Although the acquire commands do not take an argument, there is one optional modifier that can be
    ORed to it. This is the external trigger constant, XTRIG, which has a value of $08. When XTRIG is
    ORed to any acquire command, the command, when executed, will wait for a falling edge on BASIC
    Stamp pin P3, then begin its exposure. Since P3 is common to both daughterboard sockets, this same
    pin triggers the TSL1401-DB in either one. This enables exposures to be synchronized precisely with an
    external event, such as an encoder pulse or optosensor output.
  • You say to use P2 of the STAMP processor which appears to go to pin3 on both of the Interface A and B connectors.

    Based on the daughter board schematic that appears to connect to the sensors clock net. I'm confused.

    I've attached the schematics I'm using.

    Rob
    754 x 670 - 73K
    541 x 408 - 109K
  • I'm using the monitor program to setup the triggering. How can I use your code snippet to collect the sensor data? I was hoping the monitor program had a way to extract this data. It must use it to display the output to in the scope window.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,350
    edited November 2016 Vote Up0Vote Down
    I can well understand your confusion! There are a couple ways to do triggering:

    1. Use P3 (or any other non-committed pin) and let the BASIC Stamp program wait for the edge there before issuing an Acquire command.

    2. Issue an Acquire command to the AVR firmware with the trigger modifier to wait for an edge on P2.

    In case #2, the AVR firmware accepts the command, tristates the TSL1401 CLK line, waits for an edge via the TSL1401-DB's Schmitt-trigger inverter, then reasserts CLK and proceeds to acquire a scan.

    Obviously, #2 obtains the scan in closer proximity to the edge than does #1. For this reason, it's the method used by the monitor program except when Sync is enabled. In the case of Sync, it waits for an edge on P3 (the trigger, in this case), then it waits for a pulse on P0, which is connected to the 6-pin block on the TSL1401-DB. If it times out waiting for the pulse, it just goes ahead and issues the Acquire command anyway. The disadvantage of doing it this way without a synchronizer attached, is that there will be a delay of 123.6 ms after the trigger before the Acquire is issued.

    The synchronizer was meant to be a small board with an optical sensor used to detect 50 or 60 Hz flicker and send pulses in synchrony with that flicker. I made one prototype, and it worked, but it never went into production due to lack of demand.

    Any discrepancies in the docs from my description above are my fault, and I apologize for whatever confusion they might have caused.
    _____________

    Regarding the data capture: unfortunately, the monitor program has no way at present to save captured data to a file. This would definitely be a nice feature and is something I'm considering for a future version.

    You can use the code snippet I posted to do what you want, as I indicated. But you will have to include code for setting the exposure time and either wait for the trigger edge in that program or set the Trig bit in the Acquire command to wait for an edge on P2. My snippet and the monitor program cannot both be used at the same time.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • OK! Got it. Thx for all the help. I'm good on all fronts!
  • Hello, I have this project,TSL1401CL with PIC18F2520 for finding lines on sheet metal,having difficult on shiny material , any body has similar experience? Thanks!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 21,350
    edited August 23 Vote Up0Vote Down
    wawawa,

    Welcome to the Parallax forum!

    You might think that an illuminated shiny surface will always show up as "white", but that is not necessarily the case. What the camera sees is whatever the shiny surface is reflecting. The best way to examine such a surface for dark-colored marks, scratches, etc., is to position a matte-white card so that the camera sees it reflected in the shiny subject. Then illuminate the card, not the subject.

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Thanks Phil, I have 12 infra red led around the camera, I will adjust the brightness depend on the object,and diffuser, What seems the problem now is, only in the center is too dark , is not supposed to be? other article online said, it needs polarized filter?Thanks! I wish I could explained better,
  • I would ditch the IREDs around the lens. They're not in the optimum position for viewing a shiny surface. How close is the camera to the sheet metal, BTW?

    -Phil
    “Perfection is achieved not when there is nothing more to add, but when there is nothing left to take away. -Antoine de Saint-Exupery
  • Thanks Phil, it is about 3/4 " from camera to the sheet,where is the better position?
Sign In or Register to comment.