Code problem
Bob Zickefoose
Posts: 3
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
' {$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