TSL230R Program Help
Tom P
Posts: 97
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
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
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.
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
·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
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.
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