Shop OBEX P1 Docs P2 Docs Learn Events
Help With POLLIN Code - falsely triggered — Parallax Forums

Help With POLLIN Code - falsely triggered

Leo.KLeo.K Posts: 21
edited 2008-05-20 04:22 in BASIC Stamp
Hi there,

Please could somebody help me with my code (attached)

I am trying to use the POLL commands to test for pin 3 going low and when it does, run the next EEPROM. It seems to work correctly maybe one in 20-30 times but the vast majority of the time it triggers on the first iteration of my loop.

Currently the system is on breadboard with pin 3 connected to a toggle switch and then to ground. Even with nothing connected to pin 3 at all, the problem is the same sad.gif

Pins 0-2 have LED's connected. pins 4-7 arent connected.

Any·advice would be much appreciated, Please let me know if I can explain anything better. If it helps, the code is running a GPS device and a three axis accelerometer.

Thank you

Leo
GPS.bs2 12.4K

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-05-06 02:18
    You probably need pull up resistors on your inputs. Try 4.7 to 10 K

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-05-06 16:58
    I agree about the pullup resistor. The pin has to be pulle high definitely until the switch pulls it low.

    With regard to the code, the lines you have would indeed enable running slot 1 when pin p3 goes low:

    POLLIN 3,0
    ''POLLRUN 1:GOSUB Get_Time:PUT 0, Word eeprom - 1:PUT 2, i:POLLMODE 3 <-- you had this commented out?

    You do realize though that the POLLRUN effect can happen at any time in the program, right in the middle of any process. Maybe that is okay. If you would rather have it happen at a predetermined point in the main program loop, it can be better to start in POLLMODE 10 (which is also in your program initialization), and then check at one point if the switch has been been pressed.

    If it is to be a human activated switch, it might not be necessary to use the POLLing instructions at all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Leo.KLeo.K Posts: 21
    edited 2008-05-19 21:57
    Hi Chaps,

    Sorry for my late reply. The pull-up resistor solved the problem·perfectly. Thank you.

    Hi Tracey, the commented out code was because it would carry out the commands following POLLRUN 1 even if the poll hadnt been triggered. Thats why I put it in the if statement. I did also use POLLMODE 10 taking your advice from a previous thread :-)

    It is a human activated switch. What could I use instead of poll commands?

    Thank you very much again

    Leo
  • Tracy AllenTracy Allen Posts: 6,666
    edited 2008-05-20 04:22
    Well, the old-fashioned way to do it would be with polling, small letters, not POLLing. Each time around the loop, check if the pin is low, and if it is, take the required action. It may require a little debouncing to be sure the button is released before taking the action again.

    The advantage of POLLMODE 10 is that it checks the button more often and remembers if it has been pressed until your program gets around to it. That is important if the program loop is long and might otherwise miss the button press. Another way to get around that is to put a capacitor in parallel with the button and with a higher ohms pullup resistor, so the button press discharges the capacitor and the capacitor "remembers" the event, in hardware!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.