Shop OBEX P1 Docs P2 Docs Learn Events
TSL230R Program Help — Parallax Forums

TSL230R Program Help

Tom PTom P Posts: 97
edited 2008-04-16 01:40 in BASIC Stamp
I need some help with programming the TSL230R light sensor.
The code displayed below is demo to read the light counts for a single sensor.
I would like to monitor 3 light sensors sequentially and then keep reading the the three readings.
In the demo program the OE or output enable is tied to ground all the time. To scan three sensors would I have to activate each
OE in sequence? How would I perform the scan of three sensor reading each in a row?
thanks
tom
' TSL230R-Test.bs2
' Configures TSL230R for x10 sensitivity
' Displays output in Debug Terminal

' {$STAMP BS2}
' {$PBASIC 2.5}


'
Define variables, set status of pins

x VAR Word
cnt VAR Word

'
Constant declarations

S0 PIN 0 'Sensitivity selection pins
S1 PIN 1
IN PIN 2 'TSL230 output pin

'
Program Start

LOW S0 'Set sensitivity pins (S0,S1) to x10
HIGH S1

'
Main program loop

FOR x = 1 TO 2000
COUNT IN, 100, cnt 'COUNT on P2 FOR 100 ms, store value in cnt
DEBUG HOME, DEC5 cnt 'Display value of cnt, as a decimal
NEXT

END

Comments

  • Andy FoxAndy Fox Posts: 46
    edited 2008-03-28 02:53
    Yes, you would have to have a separate I/O pin for each TSL230R's OE line, but you can tie all of their output lines together. I've built circuits where the output pin is shared by another serial device (a DS1620 to be exact). If you're going to have them all set to the same sensitivity and scale you can tie those lines together too.

    To poll each one would require a separate COUNT statement... something like this maybe:

    OEPINS VAR OUTB ' Tie pins 4, 5, and 6 to the OE's of the three TSL230R's

    cnt1 VAR Word
    cnt2 VAR Word
    cnt3 VAR Word

    OEPINS = %1110 ' Active Low enable on TSL230R #1
    COUNT IN, 100, cnt1
    OEPINS = %1101 ' Active Low enable on TSL230R #2
    COUNT IN, 100, cnt2
    OEPINS = %1011 ' Active Low enable on TSL230R #3
    COUNT IN, 100, cnt3
    OEPINS = %1111 ' Turn them all off
    DEBUG HOME, DEC5 cnt1,' ', DEC5 cnt2,' ', DEC5 cnt3

    Something like that. I don't have a syntax checker in front of me but I think you get the idea.
  • Tom PTom P Posts: 97
    edited 2008-04-14 18:52
    Additional help Please!

    I don't understand OEPINS statement and %binary number- is it simple a binary number ascending?
    What is the (IN) after Count.
    I would like to expand upon the suggestion below to scan six TSL230 chips. and display via Debug.



    OEPINS VAR OUTB ' Tie pins 4, 5, and 6 to the OE's of the three TSL230R's

    cnt1 VAR Word
    cnt2 VAR Word
    cnt3 VAR Word

    OEPINS = %1110 ' Active Low enable on TSL230R #1
    COUNT IN, 100, cnt1
    OEPINS = %1101 ' Active Low enable on TSL230R #2
    COUNT IN, 100, cnt2
    OEPINS = %1011 ' Active Low enable on TSL230R #3
    COUNT IN, 100, cnt3
    OEPINS = %1111 ' Turn them all off
    DEBUG HOME, DEC5 cnt1,' ', DEC5 cnt2,' ', DEC5 cnt3
  • Tom PTom P Posts: 97
    edited 2008-04-15 23:54
    ·Help Please!
    ·Can someone help me to understand the
    OEPINS = %1110
    OEPINS = %1101
    OEPINS = %1011

    IF I wanted to step three more sensors what would the remaining OEPINS lines look like?
    thanks
    tom


    ·
    OEPINS VAR OUTB ' Tie pins 4, 5, and 6 to the OE's of the three TSL230R's

    cnt1 VAR Word
    cnt2 VAR Word
    cnt3 VAR Word

    OEPINS = %1110 ' Active Low enable on TSL230R #1
    COUNT IN, 100, cnt1
    OEPINS = %1101 ' Active Low enable on TSL230R #2
    COUNT IN, 100, cnt2
    OEPINS = %1011 ' Active Low enable on TSL230R #3
    COUNT IN, 100, cnt3
    OEPINS = %1111 ' Turn them all off
    DEBUG HOME, DEC5 cnt1,' ', DEC5 cnt2,' ', DEC5 cnt3
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-16 00:13
    Active Low Enable means that a zero on an output pin enables that TLS230R while a one on that output disables it.
    If you look at the values you've shown, you'll notice that all one bits turns all of the TLS230Rs off. The other values
    each have only one bit set to zero and all the rest are set to one. In the example you gave, pins 4 through 6 were
    used for the first 3 TLS230Rs. You could add 3 more enable lines to pins 7 through 9 which is a bit awkward since
    I/O pins are grouped in nibbles (4 bits) or bytes (8 bits) and pins 4 through 9 spans a boundary.

    For pins 4 through 9, you could turn off all of the TLS230Rs by doing "OUTS = OUTS | %1111110000". The first
    TLS230R is enabled with "OUTS = (OUTS | %1111110000) & !(1 << 4)". The next one is enabled with
    "OUTS = (OUTS | %1111110000) & !(1 << 5)". Increase the shift count as indicated for each successive TLS230R.
  • Tom PTom P Posts: 97
    edited 2008-04-16 01:19
    Mike,
    Thanks for the info, it helped me to understand the first paragraph but need more insight on the second.
    Help me to understnad the OUTS = (OUTS | %1111110000) & !(1 << 4)". Are the hightest bits to the left?
    I don't understand the & !(1<<4) after the binary number.
    =================================================================================
    How I define the Count IN at the beginning of the program?
    I want to read all 6 sensors then start the process all over again, how do I incorporate this into the program
    Ok, how does the program below look?

    cnt1 VAR Word
    cnt2 VAR Word
    cnt3 VAR Word
    cnt4 VAR Word
    cnt5 VAR Word
    cnt6 VAR Word

    OUTS = OUTS (OUTS |% 1111110000) & !(1<<4) ' Active Low enable on TSL230R #1
    COUNT IN, 100, cnt1
    OUTS = OUTS (OUTS |% 1111110000) & !(1<<5) ' Active Low enable on TSL230R #2
    COUNT IN, 100, cnt2
    OUTS = OUTS (OUTS |% 1111110000) & !(1<<6) ' Active Low enable on TSL230R #3
    COUNT IN, 100, cnt3
    OUTS = OUTS (OUTS |% 1111110000) & !(1<<7) ' Active Low enable on TSL230R #4
    COUNT IN, 100, cnt4
    OUTS = OUTS (OUTS |% 1111110000) & !(1<<8) ' Active Low enable on TSL230R #5
    COUNT IN, 100, cnt5
    OUTS = OUTS (OUTS |% 1111110000) & !(1<<9) ' Active Low enable on TSL230R #6
    COUNT IN, 100, cnt6
    OUTS = OUTS | %1111110000 'turn off all sensors
    DEBUG HOME, DEC5 cnt1,", DEC5 cnt2,", DEC5 cnt3,",DEC5 cnt4,",DEC5,",DEC6
  • Mike GreenMike Green Posts: 23,101
    edited 2008-04-16 01:40
    Please read the PBasic manual. It describes all the operators (like !, <<, &, and |) and the normal bit order which is determined by the power of two of the value. The manual also describes the various statements including those involved in setting up loops. Look at the chapter on the COUNT statement. You might download the "What's a Microcontroller?" tutorial if it didn't come with your Stamp board. It will lead you through various examples of how to write programs to do the sort of thing you want.
Sign In or Register to comment.