Shop OBEX P1 Docs P2 Docs Learn Events
Count Command skips counting intervals. — Parallax Forums

Count Command skips counting intervals.

SteveWoodroughSteveWoodrough Posts: 190
edited 2008-12-10 01:50 in BASIC Stamp
OK guys, I'm missing something easy here.·
I'm using a QTI sensor as an encoder input, counting·white sections on a black servo wheel.· The servo wheel is mounted to an RC electric motor shaft.· The motor is controlled separately via a servo exerciser and a separate power supply.·THERE IS NO connection from the motor to the the·STAMP.· ·I have a 10K resistor across the the red and white QTI leads and the QTI senses the white and black areas very wheel.

Here is the problem:· Using the COUNT command the STAMP and QTI will read several time intervals with amazing precsion.· There are 4 black and 4 white sections on the wheel and I was measuring over 1000 COUNTS in 1000 ms.··The trouble is every so often I get a COUNT value of 0 for the entire period.· NOT 1 COUNT.· Then all works fine for a few more periods (seconds) and I get another 0?· What am I missing?·

Here is meat of the "code",·all 4 lines....

DO
· INPUT 0
· QTI=IN0·············· 'Bit VAR QTI=Input into pin 0
··COUNT QTI,1000, Pulses········ 'Count QTI inputs over 1 sec and store as Pulses
· DEBUG DEC Pulses, CR
LOOP

Here is a "sample" of the out put in COUNTS per 1000 ms:

200
201
200
0
200
0
200
201
200
200
200
0
200
200
0
200

I get the same "random" type result at 50 COUNTS per second all the way up to past 1000 COUNTS per second.· Works great then 0 data, etc.


Thanks...
Steve Woodrough

·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-09 05:16
    Read the description of the COUNT statement. For some reason, the COUNT is timing out. It's not seeing any pulses during the measurement period.
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-12-09 05:28
    I went back and RTFM'd the Syntax Manual. I changed the COUNT line to look like this:

    COUNT QTI,(1000 */ $100), Pulses

    Same result as before.....
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-12-09 07:02
    I believe the trouble is in the statement

    QTI = IN0

    This reads the STATE of input pin 0. This will be either 0 or 1 as pin 0 is low or high.

    When you execute this statement at the start of your loop, and pin 0 happens to be low, then QTI is set to 0 and your COUNT statement counts pin 0 as you intend.

    When you execute this statement at the start of your loop, and pin 0 happens to be high, then QTI is set to 1 and your COUNT statement counts pin 1, which is not what you intend. Then you get a zero count.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2008-12-09 16:30
    Carl is right about QTI=in0 returning either 0 or 1 as a pin number. If you always want it to be pin 0 then use the statement,
    QTI PIN 0

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-12-09 16:49
    Also, I'd take that INPUT statement out of the loop.· No need to redo that every time through the loop.

    So your program could be thus, and run more efficiently·-- and incidentally you'd save the byte of variable space you now use for QTI.

    QTI··· PIN·· · 0
    ········ INPUT 0·· ' Actually this is superfluous in any case, unless you earlier used pin 0 for output

    ········ DO
    ············ COUNT QTI,1000, Pulses········ 'Count QTI inputs over 1 sec and store as Pulses
    ············ DEBUG DEC Pulses, CR
    ········ LOOP

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i@arrl.net
  • SteveWoodroughSteveWoodrough Posts: 190
    edited 2008-12-10 01:50
    Works Great! When I grow up I hope I'm half as samrt as yuo guys.
    COUNT is an amazing command. I had the motor at FULL boogie, 30,000 RPM, and got a 2005 COUNTS per second for as long as I dared. The "encoder" is a servo wheel with a drilled out RC airplane wheel collar pressed into the spline. The QTI is reading 4 white painted sections on a black wheel. Way cool. Thanks again guys!
Sign In or Register to comment.