PDA

View Full Version : Need a way that the BS2 always recognizes a button push to terminate a loop.



nellastev
05-01-2007, 01:55 AM
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

Chris Savage
05-01-2007, 02:08 AM
Hello,

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.


DO
...
LOOP WHILE IN0 = 0 ' Active High





DO
...
LOOP WHILE IN0 = 1 ' Active Low



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support

metron9
05-01-2007, 02:15 AM
You did not post your code but it is likley that is the problem.

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.




1 meg ohm

INPUT PIN--------/\/\/\------------GND
|
|
220 ohm resistor here
|
-------Capacitor------GND
|
|
---------/\/\/\-------___________-------+5V
220 ohm push button



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Think Inside the box first and if that doesn't work..
Re-arrange what's inside the box then...
Think outside the BOX!

TechnoRobbo
05-02-2007, 02:18 AM
Here's an alternate solution - a modified shcmitt trigger.· circuit holds button press until reset by bringing pin 1 low
(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

http://forums.parallax.com/attachment.php?attachmentid=46961

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Have Fun


TR

Post Edited (TechnoRobbo) : 5/1/2007 8:48:01 PM GMT

nellastev
05-04-2007, 03:54 AM
Hi Here is the code:

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

Mike Green
05-04-2007, 03:58 AM
The problem you're running into is that the Stamps are single threaded processors. They can only do one thing at a time. When they're executing a PAUSE or FREQOUT statement, they're doing nothing else until that statement is finished. That's why they can't see the change in pin #1 until the PAUSE and FREQOUT are finished.

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.

hitsware
05-04-2007, 04:33 AM
>That will show up as noise or interruptions in the sound output.

That's the understatement of the year :)

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

nellastev
05-04-2007, 10:36 AM
Thanks everyone this is very helpful. I tried everything but at least now I know it is inherent to the BS2 and I can deal with that!