Shop OBEX P1 Docs P2 Docs Learn Events
Help Request - Defeat random interferrence on pins? — Parallax Forums

Help Request - Defeat random interferrence on pins?

Kirk FraserKirk Fraser Posts: 364
edited 2005-01-25 20:10 in BASIC Stamp
How can I·defeat random interferrence on input pins?· I wrote a·radio directed·limit switch·toggle program to control·a hydraulic valve test,·which follows.· The input pins cause unexpected 1 answers which seem to be affected a little by the length of Pause statements in the Move loop.·

What can be done to clean up the interferrence?· I'm using long leads but there should be no induction on limit switch inputs.· In the following program the Start loop works ok with input from an attached Parallax radio keyfob device but the Move loop never works·right.· What·I want it for it to·toggle between forward and reverse·until it hits a limit switch then·switch direction (and stop on a radio command).· The radio commands work adequately but the·debug results show more than expected executions of the LUP and LDN routines.· Should I try to debounce the switches with Button or PulseIn·or put some electronic devices on the pins to reduce long-lead interferrence?

Thanks much,
Kirk Fraser

'{$STAMP BS1}
SYMBOL GOING = B0
START:
LOW 3········· 'Up Coil off
LOW 4········· 'Down Coil off
GOING = 0
IF PIN0 = 1 THEN MOVE·· 'R2 = Remote On· Pushed
PAUSE 5
QUIT:
DEBUG "LOOP "
GOTO START······ 'loop forever

MOVE:
IF GOING = 0 THEN LUP
PAUSE 5
IF PIN6 = 1 THEN LUP·· 'Limit SW UP on
PAUSE 5
IF PIN7 = 1 THEN LDN·· 'Limit SW DN on
PAUSE 5
IF PIN1 = 1 THEN QUIT· 'R4 = Remote Off Pushed
PAUSE 5
DEBUG "MOVE "
GOTO MOVE

LUP:············ 'Go Down
GOING = 1
HIGH 4
LOW 3
DEBUG "LUP "
GOTO MOVE

LDN:············ 'Go Up
GOING = 1
HIGH 3
LOW 4
DEBUG "LDN "
GOTO MOVE

Comments

  • BeanBean Posts: 8,129
    edited 2005-01-18 12:27
    From your code it looks like your limit switches have a resistor to ground and get pulled-up when they close.
    I would try lowering the value of that resistor. Try to draw between 10 to 20 milliamp when the switch is closed.
    That would be between 250 and 500 ohms.

    Terry
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-18 17:39
    Thanks, Terry. There is no resistor as yet, actually no switches yet either. There are wires attached to the pins which are several feet long. But I'll try adding low value resistors as you suggest and see if that works.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-01-18 17:57
    Kirk,

    ·· That sounds like your problem right there...Long lengths of wire can act like an antenna and pick up stray RF and cause all kinds of weird signals on inputs.· You should definately do as Bean suggested!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-01-18 18:28
    Yes, a long wire without any resistance tie-ing it to ground or VCC is an 'Antenna'. Picks up LOTS of stuff. The solution is VERY simple, which is to tie it to ground (or +5) through 10K to 22 Kohms of resistance or so.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-20 00:36
    I used Radio Shack's 470 ohm resistors and now the input lines work perfectly. I suppose 10K would work too. Thanks all for your advice.

    The next problem is my output pins which I have wired to Radio Shack's 5vdc relays. They apparently draw too much of the pinout current. The program controls the pins correctly but at the high pin there are under 2 volts with the relays attached. What I'm trying to do is cascade from these smaller relays upto automotive 12vdc relays which can then run most anything.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 00:37
    You can use a transister buffer circuit like the one attached.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
    345 x 456 - 8K
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-20 00:42
    Thank you! As I'm taking an electronics course this term, I recognize the transistor as an NPN variety but do you have a specific number to suggest?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-20 00:43
    2N3904 or 2N2222 will probbly work just fine. Any general-purpose NPN will do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-20 00:54
    Thank you Jon!
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-24 00:54
    Results - Transistors, Diodes, and Resistors installed as advised per diagram but it still doesn't work. More testing reveals the diode I used doesn't draw enough current so the relays switch either way. So I'll be replacing the original unspecified diodes for which I chose tiny 1N914's with larger 1N4001 diodes which work on my 12 V automotive relays.

    Next, I can't get the relays to activate by supplying 5 vdc to the base of my 2N2222's and connecting the negative side to the ground. So I suspect something is wrong in that area of the circuit also. But I'm not sure how to test it more thoroughly. Is it possible the Vdd 5v on Stamp supply isn't strong enough to trip the Radio Shack 5Vdc relays? What next steps does anyone suggest? Thanks.

    PS: The inputs from the limit switches and radio still work fine. So I just need to know how to get the output to work. I tested the relay cascade from 5 v to 12 V and it appears to work, just something between the output pins, transistor, and 5v relay seems to be not working.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-01-25 02:33
    Kirk,

    ·· Are you connecting 5V directly to the base of the transistor?· If so, you should put a 220 ohm - 1K resistor between the output pin and the base of the transistor...



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-25 03:21
    Chris,

    I used the 220 ohm resistor both in the real circuit and a breadboard version. Since I didn't get any reply to this until now, I reposted it in another thread where a person suggested a different transistor. My local Radio Shack is too small to stock it so I'm going to the next larger one tomorrow.

    I'm also going to have to ask my Digital Electronics teacher how to decide which components to choose when looking at a generic unlabled schematic like that. The teaching also has a generic treatment of transistors so far.

    Kirk
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-01-25 16:19
    Okay, well assuming your are at 5VDC, and the Relay is 5VDC, then the following transistors normally work for switching such a relay, 2N2222, 2N3904...Both available at most Radio Shack stores...As for the resistor...I use 1K on my projects...You only need enough voltage to the base of the transistor to bring it to saturation.· About the only other two things I can think of is make sure the diode is reverse-biased on the Relay (For that matter, try it without it once or twice).· Also make sure your output pin from the BS2 is actually going high.· I remember you said you connected the output directly to the base of the transistor at one point, and there's always the small possibility that the pin was damaged.· You could verify it's working properly by connecting an LED through·470 Ohm resistor to ground and see if it lights.· Also, are you sure you have the right pins on the transistor connected to the right places.· On 2N2222 & 2N3904 transistors, if you're looking at the device so that the pins are down and the flat side is toward you, the pins from left to right are Emitter, Base & Collector.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-25 18:05
    Chris,

    How do you figure out which transistor to use when you see an unlabeled circuit like that?

    Thanks much for your assistance.· I misunderstood the transistor pinout diagram on the back of the package·and your mention of the correct pinout helped find my mistake.· Reversing the emitter and collector leads·solved the switching problem on the breadboard so I'll try it on the Stamp circuit.

    This may be a bit bigger than a Stamp project but I'm also·wondering -- you know how Magnetic Resonance Imaging·shows the interior of a person -- what sensor system would show the spiritual effects of prayer?

    Kirk
    ·
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-01-25 19:27
    I suspected you might have the transistor reversed...I myself have given funny looks at the back of Radio Shack packages when they print them from the "Bottom View" of the chip, but don't specify.

    As for knowing what type of transistor to use, it's a matter of voltage and current requirements.· Switching a 5V Relay is one of those things that requires no more than a small-signal transistor or General Purpose Switching Transistor.· The 2 numbers you want to look at are (Looking at the back of a Radio Shack 2N2222 package) the Vce, which is the Collector-Emitter Voltage.· This is how much voltage the transistor can switch.

    Next thing you need to know is how much current your load (Relay) draws.· In your case it's probably less than 100mA, however the 2N2222 is rated at 800mA (MAX).· I myself would probably use a Power Transistor if I were drawing that much power though, since it's the MAX rating for the 2N2222.

    Basically just make sure that your load is within the ratings of the transistor.· The 2N2222 and 2N3904 are the more common NPN transistors for general hobbyist interfacing, such as switching Relays, Lamps (6-12V), High-Current LEDs or even larger capacity transistors.

    Usually if you have a project that requires something larger you might use the TIP31/TIP41, which can handle 60 Volts and 3A.

    Next up from there I think would be something like the 2N3055 which can do 60V and something like 4-10A depending on the package and heatsink.· Hope this helps you out.

    Also, while the schematic you had shows a 220 Ohm resistor, a 1K resistor usually is the better choice for the experimenter, since that value works on that transistor over a much wider range of control voltages.


    As for your last question, I don't have the answer...I'm not sure prayer is what's usually going through my mind when something won't work!· blush.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage

    Knight Designs
    324 West Main Street
    P.O. Box 97
    Montour Falls, NY 14865
    (607) 535-6777

    Business Page:·· http://www.knightdesigns.com
    Personal Page:··· http://www.lightlink.com/dream/chris
    Designs Page:··· http://www.lightlink.com/dream/designs
    ·
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-01-25 19:57
    Kirk -

    Emotional constructs are ofen viewed with the aid of P.E.T. scans. P.E.T. is positron emission tomography. The image of the barin lokks something like what you'd expect to see in a tehrmograph if you've ever seen one of those which shows temperature differentials within a body (human or otherwise).

    Regards,

    Bruce Bates
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-25 20:06
    Ok, thanks for the education. Maybe I should toss my relay cascade from 5v to 12v and use a larger transistor to drive the 12v relays or drive the hydraulic valve coils directly. This system "seems" a little safer because of isolating the 5v from the 12v mechanically.

    On prayer, the reason I asked is I've had lots of answers to prayer including earlier this month I had a "loop of Death" on my WinXP computer where it asks to boot in safe mode and every choice leads back to that screen. I put up with it for a while, trying to boot with the A: drive, etc. but I only had a DOS boot which can't read WinXP files. So I remembered how lots of things work by prayer and prayed for it as I walked away and when I came back it was fixed!!! I'm not strong enough at it to do everything that way but it's very interesting how God's kingdom works. So I guess if there were a display that would show a person when they are praying and it's effects on their bodies, that could help others do it or get better at it. I think I have a clue but not a full solution -- when I've inadvertently put my hand on 120VAC but been in prayer it didn't hurt but when out of prayer in myself it hurts a lot. Somehow I think that could lead to a sensing system if I were or knew a scientest. Oh well, I'd better get back to getting ready for my electronics class.
  • Kirk FraserKirk Fraser Posts: 364
    edited 2005-01-25 20:10
    Bruce,

    Thanks for the P.E.T. scan tip. I'll look into it.
Sign In or Register to comment.