Shop OBEX P1 Docs P2 Docs Learn Events
TSL230 output help.... — Parallax Forums

TSL230 output help....

Technic-R-CTechnic-R-C Posts: 117
edited 2008-06-29 02:50 in BASIC Stamp
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.

' {$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

  • FranklinFranklin Posts: 4,747
    edited 2008-06-28 04:15
    ' 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
    

    Have you tried this one yet?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 04:37
    Technic,

    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 11:50
    Dave-W

    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
  • FranklinFranklin Posts: 4,747
    edited 2008-06-28 13:50
    I would try the test that came with the manual wired the way the manual says to. You need to see if it works at all first before you change things that's why Parallax prints this stuff.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 14:31
    The test that came with the product from Parallax worked however I'd like to simpliify it a bit (if possible) Therefore I wanted to use the code in my first post to just recieve the light data in a decimal number without all the extra stuff. (puslin, debug statements case-select)·

    I should be able to receive data with these statements, but it is not working.

    ... more code is above
    

    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
    

    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
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 16:45
    Technic,

    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
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 16:57
    Technic,
    I assume you have Port 5 of the stamp, pin 10, connected to pin 6 of the sensor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    D. A. Wreski
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 17:10
    Dave-W said...
    Technic,
    I assume you have Port 5 of the stamp, pin 10, connected to pin 6 of the sensor.

    Pin 6 of the sensor is connected to pin 5 of the BasicStamp.· As stated in the pdf file.· What do you mean by Port 5 and pin 10?

    Technic-R-C
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 18:07
    ok...· At the moment I believe I am more confused than I was at the beginning so lets start from scratch.· If you guys don't mind can I have a couple of things that I would like to clear up about the TSL230 and the code that Parallax gave with the product.· To start off...

    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?

      'display multiplication factor, multiply this by the value to obtain a measurement valid over entire range
      SELECT scale
        CASE %01
          DEBUG " x 100", CR
        CASE %10
          DEBUG " x 10", CR
        CASE %11
          DEBUG CR
      ENDSELECT
    

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

    COUNT IN, 100, cnt                             'COUNT on pin 3 FOR 100 ms, store value in cnt    
    

    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
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 18:39
    Technic,
    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 19:06
    I am still having a problem, the only·value·I am receiving is·0.· Maybe this will help you.

    This is my code and wiring schematic.· Thanks for the·help.

    ' {$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 500
    DEBUG "start", CR
    

    LOW   S0                              'Sets status of TSL230 pins
    HIGH  S1
    HIGH  S2
    LOW   S3
    HIGH  4                               'TOGGLE state TO enable/disable chip
    

    '-----Main program LOOP-----&#8216;
    

    FOR x = 1 TO 5000
      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
    



    ································ ·············
    383 x 268 - 10K
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 19:53
    Very odd...

    I get a reading from the sensor in random places once in a while when i changed the count statement to...

    COUNT 5, 100, cnt                     'COUNT ON PIN 5 FOR 100 ms, STORE value in cnt
    

    Changed 1 ms to 100 ms.

    Any ideas?

    Technic-R-C
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 20:21
    Technic,
    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 20:31
    P4 must be low, connected to pin 3 of the sensor to enable it.
    Dave-W

    It works perfectly know.· The only change I made was the toggle between LOW and HIGH 4 and it works.
    Why did you not hard wire it first as per previouts post to elimilate any program problems?
    Sorry but I don't know what this means at the moment (still new to electronics)?· Does this mean make a schematic?
    Yes, use at least a 100ms sample rate.
    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
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 20:36
    Technic,
    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 20:41
    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.
    But if I connect some of the sensor pins to the +5 or ground wouldn't that ruin the Basic Stamp or sensor?

    ALSO...
    Yes, use at least a 100ms sample rate.
    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

    ·
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 20:51
    Technic,
    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 20:55
    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
    Oh I see, good explanation.
    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 )
    ···· How about the pins that are specifically designated VDD or VSS?

    ··· Technic-R-C
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 21:11
    Technic,

    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-28 21:50
    Question kind of off topic, but here it goes.

    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
  • Dave-WDave-W Posts: 94
    edited 2008-06-28 22:24
    Technic,
    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
  • Technic-R-CTechnic-R-C Posts: 117
    edited 2008-06-29 00:14
    NO, NO, NO!
    You are allowed 40ma per Stamp, all pins total. You will exceed that with the bar LED alone
    Whew.... was about to connect the 10 segment board right now.· I guess I'll have to settle with either an outside power source or turning on one LED at a time.

    Once again, thanks for all the help.· I appreciate it.

    Technic-R-C
  • Dave-WDave-W Posts: 94
    edited 2008-06-29 02:50
    Technic,
    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
Sign In or Register to comment.