TSL230 output help....
Hello
I recently obtained a TSL230 light to frequency converter chip and I am having some problems with it.· I am trying to use one of the online resources parallax listed (http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/tsl230.pdf), however I am having some problems with the code.· According to the document I am supposed to be receiving numerical data when I turn on the Basic Stamp and download the code provided (below).· However, the only value that I am receiving is a zero and I have no idea what to do.· I wired the TSL230 correctly but the code seems to be holding me back.· Here is the code I am using.
According to the document I am supposed to be receiving a wide range of values for 2 seconds.·The wiring is on page 1 of the link listed above.·Can anyone help?
Thanks
Technic-R-C
I recently obtained a TSL230 light to frequency converter chip and I am having some problems with it.· I am trying to use one of the online resources parallax listed (http://www.parallax.com/Portals/0/Downloads/docs/prod/compshop/tsl230.pdf), however I am having some problems with the code.· According to the document I am supposed to be receiving numerical data when I turn on the Basic Stamp and download the code provided (below).· However, the only value that I am receiving is a zero and I have no idea what to do.· I wired the TSL230 correctly but the code seems to be holding me back.· Here is the code I am using.
' {$STAMP BS2px} ' {$PBASIC 2.5} '-----Define variables, set status of pins----- x VAR Word cnt VAR Word S0 CON 0 S1 CON 1 S2 CON 2 S3 CON 3 PAUSE 2000 DEBUG "start" LOW S0 'Sets status of TSL230 pins HIGH S1 HIGH S2 LOW S3 HIGH 4 'TOGGLE state TO enable/disable chip '-----Main program LOOP-----‘ FOR x = 1 TO 2000 COUNT 5, 1, cnt 'COUNT ON PIN 5 FOR 1 ms, STORE value in cnt DEBUG DEC cnt, CR 'Send value of cnt, as a decimal TO the computer NEXT 'DO it all over again, 2000 times END
According to the document I am supposed to be receiving a wide range of values for 2 seconds.·The wiring is on page 1 of the link listed above.·Can anyone help?
Thanks
Technic-R-C
Comments
Have you tried this one yet?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Here is some code I modified to put the output to the Parallax 4 X 20 serial LCD.
Pins 7 and·8 are hardwired to -:- by 10
This will scroll through all three sensitivities· and dim the display if room light is low.
' {$STAMP BS2p}
' {$PBASIC 2.5}
' 06/21/2008 DAW
' Program Serial Light Display
' Program Listing 4.51 Program to use the TSL230R
' This program uses the Parallax TSL230R light to frequency conversion IC
' with the Parallax 4 X 20 Serial LCD ( LK204-25 )
'
' BS2 pins 0 and 1 control the sensitivity of the '230 through
' its "electronic aperture" feature. The higher the sensitivity,
' the higher the frequency output for a given light intensity,
' as shown below:
'··· bit1··· bit0··· Sensitivity
'··· ----··· ----···
'··· 0······· 0··· sensor OFF power down.
'··· 0······· 1··· x1
'··· 1······· 0··· x10
'··· 1······· 1··· x100
'
' The TSL230R pins 7 and 8 set the frequency divider. Set for -:- 10
' This BS2P program uses the COUNT instruction to count the number
' of TSL230 output cycles over a period of 1 second. This approach
' trades a relatively long measurement period for excellent
' resolution and accuracy.
' The program displays the readings on the 4 X 20 serial LCD module.
Sens··· VAR Byte··· ' Sensitivity counter.
Mult··· VAR Byte··· ' Multiplier for a given sensitivity.
Light·· VAR Word··· ' Light-intensity reading.
Cmd···· CON 254···· ' Instruction prefix for LCD.
'Speed· CON 32878·· ' Serial constant for 19,200 bps, default for the display as shipped.
Speed·· CON 33008·· ' Serial constant for 9600 bps, slower speed for slower processors.
CLCD····· CON 88··· ' Command to clear screen
DIRS = %00000011··· ' Make pins 0 and 1 outputs.
LP····· CON·· 7···· ' I/O Port 7 for the Serial LCD
BL····· VAR· Bit··· ' Back Light bright(1) or dim (0)
BL = 1············· ' Back Light is on bright
Start:
PAUSE 1000······································ ' wait for splash screen on power up
SEROUT LP, Speed, [noparse][[/noparse]Cmd,CLCD]····················· ' Clear Screen
PAUSE 100······································· ' Wait for screen to clear
SEROUT LP,Speed,[noparse][[/noparse]Cmd,153,254]···················· ' Set screen bright
SEROUT LP,Speed,[noparse][[/noparse]Cmd,68]························· ' Set line wrap off
················································ ' Now, Write unchanged data that does not change
SEROUT LP,Speed,[noparse][[/noparse]Cmd,71,1,1,"Multiplier X"]······ '· Show Multiplier on first line
SEROUT LP,Speed,[noparse][[/noparse]Cmd,71,1,3,"Light Amount"]······ '· Show measured Light on third line
SEROUT LP,Speed,[noparse][[/noparse]Cmd,104]························ ' Load horizontal bar characters
AGAIN:··············································· ' Main program loop.
FOR Sens = 1 TO 3···································· ' Step through sensitivity settings.
· OUTS = Sens········································ ' Write sensitivity setting to pins.
· LOOKUP Sens,[noparse][[/noparse]0,1,10,100],Mult······················ ' Get the sensitivity multiplier.
· COUNT 2,1000,Light································· ' Count pulses for 1 second.
····· IF ( Mult <10 ) THEN··························· ' Only check Light at X 1
······· IF (Light < 20) THEN························· ' Low Light if less than 20
··· SEROUT LP,Speed,[noparse][[/noparse]Cmd,153,20]····················· ' Low Light so dim display
··· BL = 0··········································· ' Set BL to zero to know display is dim
····· ENDIF
··· ENDIF
······· IF BL = 0 THEN······························· ' Check for dim display
········· IF ( Mult <10 ) THEN······················· ' Only check Light at X 1
············ IF (Light > 20) THEN···················· ' High Light if more than 100
··· SEROUT LP,Speed,[noparse][[/noparse]Cmd,153,245]···················· ' High Light so Bright display
··· BL = 1··········································· ' Set BL to zero to know display is bright
····· ENDIF
······· ENDIF
··· ENDIF
· SEROUT LP,Speed,[noparse][[/noparse]Cmd,71,14,1,DEC Mult,"· "]············ ' Display multiplier.
· SEROUT LP,Speed,[noparse][[/noparse]Cmd,71,14,3,DEC Light,"····· "]······· ' Display Light measurement
··· IF Mult = 1 THEN
··· SEROUT LP,Speed,[noparse][[/noparse]Cmd,71,1,4,"·················· "]··· ' Clear old bar graph
··· SEROUT LP,Speed,[noparse][[/noparse]Cmd,124,1,4,0,(ABS(Light)) ]········ ' Display new bar graph
··· ENDIF
· PAUSE 1000············································ ' Display for time to read
· NEXT·················································· ' Next Multiplier.
GOTO AGAIN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
I inputed the code into my program with a couple of modifications and it still did not work.· Assuming you used the wiring diagram on the first page·of this documents.· I'm still having trouble with the code.· In my original post I pasted the code given in the pfd file and I am confused about the output of the device. It tells me count on pin 5, however pin 5 is an input not an ouput so how could I possibly be getting data from it. (Hence, only 0's)??
Franklin
I have also tried changing to code to what you suggested but I've had no luck getting results.· What wiring were you thinking of?· The one that came with the product manual or the Mark Hughes document?
Technic-R-C
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
I should be able to receive data with these statements, but it is not working.
Can anyone that has tried or wants to try the steps on this guide·help me?· Wiring and complete code would help.
Thanks
Technic-R-C
Did you hardwire pins 1 and 2 for the sensitivity you want?
Pin 1 should be tied to ground.
Pin 2 should be tied to +5
Pin 8 should be tied to +5
Pin 7 should be tied to ground.
Put a .1 cap across pins 4 and 5.
Pins 3 and 4 should be tied to ground.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
I assume you have Port 5 of the stamp, pin 10, connected to pin 6 of the sensor.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
Technic-R-C
1.··Because of the limitation that the stamp has to how large a number can be made, does that explain why·the number given by the sensor has to be·multiplied by the value 10 or 100 to obtain a measurement valid over entire range?
2. Can the TSL230 be used like a regular photoresistor that can trace the strength of light only more accurately?· (Light following robot)
3.·Can i just use the following statement ( and variables, etc.)
to calculate the light strength without the rest of the long code included in the parallax·code provided.
Sorry for all the questions and thanks for the tolerance with my ignorance.
Thanks
Technic-R-C
Pin 5 of the stamp is I/O port 0.
So your code is not looking at the correct I/O port.
FOR x = 1 TO 5000
COUNT 5, 1, cnt 'COUNT ON PIN 5 FOR 1 ms, STORE value in cnt
DEBUG cnt, CR 'Send value of cnt, as a decimal TO the computer
NEXT 'DO it all over again, 2000 times
Should read:
Count 0, 1, cnt ' Count on I/O port 0 for 1 ms, store value in cnt.
This should look at I/O port 0 not port 5.
Pins 7 and 8 are frequency dividers. Divide by 10 or 100 will work well with the stamp. I would hardwire it to divide the frequency by 10 for a start.
Pins 1 and 2 set the sensitivity of the sensor. Multiply by 1, 10 or 100 to increase the sensitivity to light. I would start with harwired 10 first for your test.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
This is my code and wiring schematic.· Thanks for the·help.
································ ·············
I get a reading from the sensor in random places once in a while when i changed the count statement to...
Changed 1 ms to 100 ms.
Any ideas?
Technic-R-C
P4 must be low, connected to pin 3 of the sensor to enable it.
Why do you not hard wire it first as per previouts post to elimilate any program problems?
Yes, use at least a 100ms sample rate.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
It works perfectly know.· The only change I made was the toggle between LOW and HIGH 4 and it works.
Sorry but I don't know what this means at the moment (still new to electronics)?· Does this mean make a schematic?
I experimented with higher values such as 2000 and 1000 and I get higher data.· How do I know when my data is accurate when the data keeps changing due to the sample rate differences?
Thanks for all the help guys!!
Technic-R-C
Post Edited (Technic-R-C) : 6/28/2008 8:40:48 PM GMT
You said:
Sorry but I don't know what this means at the moment (still new to electronics)? Does this mean make a schematic?
Thanks for all the help guys!!
Technic-R-C
Hardwire means to connect the pins of the sensor to +5 or Ground as needed. Making them a high or a low. You do not have to connect all pins to the Stamp for test. Just wire it so you elimitate
any program problems first. Then connect a few pins of the sensor to the Stamp as needed for your project.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
ALSO... I experimented with higher values such as 2000 and 1000 and I get higher data.· How do I know when my data is accurate when the data keeps changing due to the sample rate differences?
Technic-R-C
·
The higher the sample time the more accurate the measurement is. However, you cannot go too far and expect a perfectly stable reading.
Nothing is perfect with the way the Stamp samples the frequency. Even with a frequency counter there would be some jitter from the sensor to
take into account.
If a pin needs a high or a low on the sensor, then there is no difference hooking it up to the Stamp that provides a HIGH ( +5 ) or a LOW ( Zero volts ) or hooking it
directly to the supply ( +5 ) or ground ( Zero volts )
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
···· How about the pins that are specifically designated VDD or VSS?
··· Technic-R-C
You said:
How about the pins that are specifically designated VDD or VSS?
No, you would not want to connect a external sensor or anything else that needs VDD or VSS to the Stamp. The Stamp can only provide
very low current needs and the external device ( sensor ) would need more than the Stamp could supply. Those pins are to go to a stable power
source only. ALSO, Using the Stamps internal regulator to supply an external device is not a good idea unless you know exactally what you are
doing and using care not to overload it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
Can I connect a 10 bar graph LED display along with the TSL230 or would the 10 bar LED + the TSL230 draw too much current? (20 mA per LED)· I don't think it is a problem, but I read somewhere that you can have a limit with the number of LED's with the Basic Stamp because itcan't provide enough current.· (Note:· ALL 15 I/O pins are in use)
Extra:· I am using·a 9V 300 mA power source
Technic-R-C
Post Edited (Technic-R-C) : 6/28/2008 10:11:40 PM GMT
You wrote:
Can I connect a 10 bar graph LED display along with the TSL230 or would the 10 bar LED + the TSL230 draw too much current? (20 mA per LED) I don't think it is a problem, but I read somewhere that you can have a limit with the number of LED's with the Basic Stamp because itcan't provide enough current. (Note: ALL 15 I/O pins are in use)
NO, NO, NO!
You are allowed 40ma per Stamp, all pins total. You will exceed that with the bar LED alone.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski
Once again, thanks for all the help.· I appreciate it.
Technic-R-C
You will have to use a driver and a powersupply for this heavy load. The ULN2803A will drive 8 LEDs or 8 heavy current devices.
Look at the Nuts & Volts application notes found on the Parallax site for them.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
D. A. Wreski