Need a way that the BS2 always recognizes a button push to terminate a loop.
nellastev
Posts: 10
Hi - I am trying to use a pin being pulled low or high (I am pulling high) to terminate a loop.· What I have found is that his doesn't always work, sometimes I have to push the button numerous times before the loop terminates.· Does anyone know what might be the issue?· Just have a simple divider on a push button switch. Thanks
Comments
Without a diagram and your code the only thing I can note to you is that you don’t want a voltage divider if that is what you have. The schematics for both active high and active low push button circuits can be found in the Help File or in the BASIC Stamp Manual under the BUTTON command. That said, you can exit the loop using one of the following two routines. Take care.
[/code][/size]
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
If you check to see if a pin is low when a button is pressed but you check the pin just before and just after the button is pressed it doesnt see the button.
Three solutions. 1. An interrupt, 2.Polling the pin faster than the button can be pressed. 3.Creating a latching circuit.
Since you are using the BS2 , solutions 1 and 2 wont work.
Use the circuit below and a HIGH signal will be the button press. After you receive the button press as a high signal, take the pin LOW output and discharge the capacitor, loop the program until the signal stays low (the button must be unpressed) to reset the latch.
Depending on the speed you need between button presses, other circuits may be a better choice. this will take care of most situations.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!
(Reposted BS2 program - had a typo):
HIGH 1
INPUT 2
buttoncount VAR Byte
waitcount·· VAR Word
DO
· DO WHILE IN2=0
··· PAUSE 10 'delay for testing - not necessary
··· DEBUG HOME,?buttoncount,?waitcount
··· waitcount=waitcount+1
· LOOP
· buttoncount=buttoncount+1
· DEBUG HOME,?buttoncount
· PAUSE 500
· PULSOUT 1,10 'reset latch
LOOP
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun
TR
Post Edited (TechnoRobbo) : 5/1/2007 8:48:01 PM GMT
PushBtn········ PIN···· 3·············· ' pushbutton on P0
Spkr··········· PIN···· 7············· ' output pin for FREQOUT
Main:
· OUTH = %00000000
DIRH = %11111111
· DO
· DEBUG "Low E", CR
· OUTH= %00000110·········· 'E
···· PAUSE 3000
···· FREQOUT Spkr, 3000, 82
LOOP WHILE IN3 = 1·· ' Active Low
DO
· DEBUG "A", CR
· OUTH = %00001000········· 'A
···· PAUSE 3000
···· FREQOUT Spkr, 3000, 110
LOOP WHILE IN3 = 1·· ' Active Low
Continues on... for 4 more loops·· - I checked the signal and indeed it is pulled low.· I can hold the button down low for seconds before the BS2 recogizes the pin is low - is this a code issue?· thanks
For long pauses, you can get around this by using shorter pauses (like 100ms) in a loop that checks for the change in pin #1. You can't really fix this for the FREQOUT statements since there's a few milliseconds before a check of pin #1 can be done and the FREQOUT restarted. That will show up as noise or interruptions in the sound output.
That's the understatement of the year [noparse]:)[/noparse]
Even if no other instructions are involved (simply updating the frequency)
produces a big pop.
This (I think) is a result of the pin going active low at the end of the duration.
To go back into operation it must jump (dc wise) the 2.5 V necessary to
center the PWM sinewave.
No amount of LP filter will bypass that big of glitch
(without also bypassing the desired signal)..)
Perhaps if the pin went to input (open)
after the duration it would help....· ?????????
Post Edited (hitsware) : 5/4/2007 12:34:32 AM GMT