Shop OBEX P1 Docs P2 Docs Learn Events
tcs3200 with propeller — Parallax Forums

tcs3200 with propeller

j_roddyj_roddy Posts: 6
edited 2013-12-12 13:07 in Accessories
hello, i'm trying to use the tcs3200 with my propeller chip, but can't figure out how to count the pulses. i looked at the basic code, and it has a count function, which i think is comparable to the cntra registers on the propeller. right? i'm just looking to do simple pulse measuring for a specified time period, like the sample basic code does.

what counter mode do i need to use for measuring pulses with this sensor? what register holds the number of pulses in a time period? also, how do i set the duration of time to wait while counting pulses?

sorry for all the questions, but there are no good resources out there for this sensor with a propeller chip.

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-29 18:33
    The TSL230 also has a frequency output. There's a object with a demo in the Propeller Tool's library. Hopefully you can adapt it to use with the TCS3200.

    The TCS3200, looks pretty easy to use. You use the S2 and S3 pins to set which diode type you want to use and then read the frequency output like you would with the TSL230.
  • j_roddyj_roddy Posts: 6
    edited 2013-11-29 23:07
    well i'm no expert, but i already tried to and i don't think they're similar enough to me. i think i need to do a duty cycle count, but more importantly, i just wanna know how to count the number of pulses for a given period of time, for example 10 seconds, which i don't think the tsl230 code does.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-11-30 02:14
    The program "tsl230 simple DEMO" displays the number of pulses received in a tenth of a second. You could change to display the number of pulses in ten seconds by changing this line:
    waitcnt(80_000_000 / 10 + cnt)         'wait for 100ms
    

    To:
    waitcnt(80_000_000 * 10 + cnt)         'wait for 10s
    
    As part of my attempt to understand the different was of reading encoders, I wrote a small program to count pulses three different ways. Here's a link to the program.

    I also trimmed the program down to use just the counter method and I'm attaching the modified program to this post.

    As the program is currently setup, it will display the number of pulses received every quarter of a second. Again, the interval can be easily changed. To change this program to count pulses for ten seconds change these constants.
      COUNT_PULSE_FREQUENCY = 4
      COUNT_PULSE_SPEED_INTERVAL = CLK_FREQ / COUNT_PULSE_FREQUENCY
    

    To:
      COUNT_PULSE_SECONDS = 10  '' Do not use values larger than 53 or wait time may exceed 32-bits
      COUNT_PULSE_SPEED_INTERVAL = CLK_FREQ * COUNT_PULSE_SECONDS
    
    
    

    I doubt you'll want to count pulses longer than a second in this application.

    I haven't done a proper test of this program but I think it should work as expected.

    I usually cut and paste other people's code whenever I need to use the Propeller's counters. In this particular case I used the code examples of the Propeller Education Kit (PEK) as a guide. IIRC the example code was on page 150 of the PEK. A pdf of the PEK can be found in the Propeller Tool's help menu.

    BTW, Welcome to the forum. I have links to some other Propeller tutorials in post #3 of my index (see my signature).

    I hope you let us know how your project turns out.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2013-12-03 15:44
    Here are two SPIN programs that read pulses and display the frequency on the PST @ 115.2Kbps. These programs use P24 and P25 as the pulse inputs and I used them with our Light to Frequency chips as a test program. I hope these help. The second one also displays the delta on counter B since the last count.
  • j_roddyj_roddy Posts: 6
    edited 2013-12-10 21:17
    thanks for the help. I modified a code i found in the library to attempt what I want, it's below. I know it's really rough, but I think it's a start. one bug i can't figure out is that "red" comes back as 0 first, and then after that it's always about twice as high as clear, and about 4 times the value of blue and green. i can't figure out what the problem is. tried moving the phsa~ around, and the order of the colors, but can't seem to figure it out. would appreciate any thoughts.

    p.s. i dont know why it won't let me post [%]01010, but that's the setting in my actual code, without brackets.
    CON
      
      _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
      _xinfreq = 5_000_000
    
    OBJ
      
      pst : "Parallax Serial Terminal"           ' Use with Parallax Serial Terminal to
                                                 ' display values
      
    PUB Init
    
      'Start Parallax Serial Terminal; waits 1 s for you to click Enable button
    
      pst.Start(115_200)
    
      ' Configure counter module.
      
      main                                       ' Call the Main method
    
    PUB Main | clear, red, green, blue
    
      
      frqa := 1                                           ' Increment phsa by 1 for each clock tick
      ctra[30..26] := 010                      ' Set mode to "POS Edge detector"
      ctra[5..0] := 0                                   ' Set APIN to 0 (P0)
      
        repeat
    
         dira[0]~
         dira[1..2]~~                              
         outa[1..2]~
         phsa~
         waitcnt((clkfreq * 2) + cnt)   
         red := phsa
    
         outa[2]~~                                
         phsa~
         waitcnt((clkfreq * 2) + cnt)
         blue := phsa
         
                                          
         outa[1]~~
         phsa~
         waitcnt((clkfreq * 2) + cnt)   
         green := phsa               
    
                                          
         outa[2]~
         phsa~
         waitcnt((clkfreq * 2) + cnt)   
         clear := phsa
         
        
         ' Display Result                                 
    
         pst.Str(String(pst#NL, "clear = "))
         pst.Dec(clear)
         pst.Str(String(pst#NL, "red = "))
         pst.Dec(red)
         pst.Str(String(pst#NL, "green = "))
         pst.Dec(green)
         pst.Str(String(pst#NL, "blue = "))
         pst.Dec(blue)
         waitcnt(clkfreq/2 + cnt)
      
    
  • j_roddyj_roddy Posts: 6
    edited 2013-12-12 09:18
    been thinking about this more...maybe its a wiring problem. Ive got the sensor connected directly into my prop chip right now w/o resistors. could that be the problem? anyone know what resistors I should use for this sensor?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-12 09:37
    As long as you have 5V going to the +5V pin, and 3.3V going to the Vdd pin, you can connect the TCS3200's signal lines directly to the Prop pins without resistors. (BTW, the module already has a 330-ohm series resistor installed in the OUT pin circuit.)

    -Phil
  • j_roddyj_roddy Posts: 6
    edited 2013-12-12 09:54
    hmm, well then i still have no idea why "red" is so screwed up in the readings. yea i saw the 330 in the schematic, that's why i thought it was a resistor issue on the signal lines. i trust you of course, but for what its worth i was messing w/the set-up earlier and got different values when i added a 100K resistor to the signal lines...

    is something wrong with my code then? its above. I have a basic stamp mobo too, and ran the sample code from the product page for it on that to see if my sensor was busted...worked just fine though.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2013-12-12 12:04
    I'm not sure why your code did not work, unless you were using S0 and S1 instead of S2 and S3 to select your colors. Anyway, try this one and see if it works for you:
    CON
      
      _clkmode = xtal1 + pll16x                  ' System clock → 80 MHz
      _xinfreq = 5_000_000
    
      S2    = 4
      S3    = 5
      OUT   = 2
    
      RED   = 0
      GRN   = 1
      BLU   = 2
      CLR   = 3
    
    VAR
    
      long  rgbw[4]
    
    OBJ
      
      pst : "Parallax Serial Terminal"           ' Use with Parallax Serial Terminal to
                                                 ' display values
      
    PUB Start
    
      pst.Start(115_200)
      ctra := %01010 << 26 | OUT
      frqa := 1
      dira[S2]~~
      dira[S3]~~
      repeat
        get_rgbw(@rgbw, clkfreq)
        pst.Str(String(pst#NL, "clear = "))
        pst.Dec(rgbw[CLR])
        pst.Str(String(pst#NL, "red = "))
        pst.Dec(rgbw[RED])
        pst.Str(String(pst#NL, "green = "))
        pst.Dec(rgbw[GRN])
        pst.Str(String(pst#NL, "blue = "))
        pst.Dec(rgbw[BLU])
    
    PUB get_rgbw(rgbaddr, time) | phsap, count
    
      outa[S2]~
      outa[S3]~
      phsap := phsa
      waitcnt(time + cnt)
      count := phsa
      long[rgbaddr][RED] := phsa - phsap
    
      outa[S3]~~
      phsap := phsa
      waitcnt(time + cnt)
      count := phsa
      long[rgbaddr][BLU] := phsa - phsap
      
      outa[S2]~~
      phsap := phsa
      waitcnt(time + cnt)
      count := phsa
      long[rgbaddr][GRN] := phsa - phsap
      
      outa[S3]~
      phsap := phsa
      waitcnt(time + cnt)
      count := phsa
      long[rgbaddr][CLR] := phsa - phsap
    

    You will have to change the values of S2, S3, and OUT to correspond to your pinouts.

    -Phil
  • j_roddyj_roddy Posts: 6
    edited 2013-12-12 13:07
    that's certainly possible, I double checked when I first designated the pins but should probably triple check cuz the db expander always throws me off. Ill give yours a whirl too and see if it makes a difference. thanks for the help.
Sign In or Register to comment.