Shop OBEX P1 Docs P2 Docs Learn Events
Code problem — Parallax Forums

Code problem

Bob ZickefooseBob Zickefoose Posts: 3
edited 2009-05-05 13:32 in BASIC Stamp
I am using a BS-2 as a speed controller and most everything is working fine.· I used the example from StampWorks to display frequency.· I am using the Melexis sensor and a 30 tooth bicycle chain sprocket to give the signal.·· Pin 0 is the count pin, and pins 1,2 are hooked to relays which turn lights on and off.· The program starts up fine, and goes from start to run mode when it senses any rpm.· This run mode sets pin 1 high and its light comes on.· Then as speed increases to 150 rpm pin 2 gos high, or low if less than 150 rpm.· This works fine.· If speed is over 250 rpm it goes to quit and pauses.· The problem is that when speed goes to zero in run mode, I expect program to go to quit and pause.· What really happens is that pin one goes low, but if I turn the sprocket again pin 1 immediately goes high.· I think it should go to quit and pause and can't figure out why it won't.· Any help would be appreciated.·

' {$STAMP BS2}
' {$PBASIC 2.5}
FreqIn· PIN 0
OneSec· CON 1000
cycles· VAR Word
Start:
· LOW 2
· LOW 1
· DO
··· COUNT FreqIn, OneSec, cycles
··· DEBUG HOME,
······· "Frequency: ", DEC cycles*60/30,··· "·· RPM "
··· IF cycles*60/30 > 250 THEN GOTO Quit
··· IF cycles*60/30 > 1 THEN GOTO Run
· LOOP
Run:
· LOW 2
· HIGH 1
· DO
··· COUNT FreqIn, OneSec, cycles
··· DEBUG HOME,
······· "Frequency: ", DEC cycles*60/30,··· "·· RPM "
··· IF cycles*60/30 < 1 THEN GOTO Quit
··· IF cycles*60/30 > 250 THEN GOTO Quit
··· IF cycles*60/30 < 150 THEN LOW 2
··· IF cycles*60/30 > 150 THEN HIGH 2
· LOOP
Quit:
· LOW 1
· LOW 2
· PAUSE 60000
· COUNT FreqIn, OneSec, cycles
· DEBUG HOME,
······· "Frequency: ", DEC cycles*60/30,··· "·· RPM "
· GOTO Start

Comments

  • TinkersALotTinkersALot Posts: 535
    edited 2009-05-04 20:49
    Just a guess here, but could be an over-range problem with the math you are doing on cycles? Alos, why not just *2 instead of *60/30 ?
  • Bob ZickefooseBob Zickefoose Posts: 3
    edited 2009-05-04 20:59
    I will give it a try. I am using the 60/30 because I have varied the number of teeth (the 30) in the past. Thanks I will try it as soon as I get home.
  • Bob ZickefooseBob Zickefoose Posts: 3
    edited 2009-05-05 13:32
    Well, changing 60/30 to 2 didn't work. I tried all kinds of things this morning and can't seem to get it to work. Even changed the run statement in the program to something else, thinking that might be confusing. I am wondering if using four if statements in a row is confusing things
Sign In or Register to comment.