How far away can my switch be?!

Discussion in 'Embedded Systems and Microcontrollers' started by geoffers, Mar 10, 2014.

  1. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Hi all,
    Am almost ashamed to post this, maybe of help to others so here it is;
    I've a nice simple project on the go at the moment for which I'm going to use a 16f819 (just because I have a stack of them and they fit the bill!)

    All I need to do is wire 6 switches to the pic to in turn switch 6 darlington transistors which in turn will work 6 soleniod valves.

    I remember in a previous project I had long wire attached to led's this messed with my poor pic I think as I asked here and removed them and all was well.

    My switches need to be at least 3m apart, (in pairs, phew!) but I can see the wires to the switches ending up around 4-5m at the longest! Will this give me problems? There is other wiring quite near (240v ac) I've got some shrouded cable but are there any other dodges I need to use?

    Thanks in advance, Geoff
     
  2. MaxHeadRoom

    Expert

    Jul 18, 2013
    10,547
    2,371
    A full schematic would be nice, but if I were you I would tend to use the service ground conductor which I assume you have access to unless this is a purely DC sourced project (Battery etc).
    To this service ground I would connect the DC power supply commons, assuming they are at present galvanically isolated from the supply.
    Also use shielded conductors to the switches, the shield of which would be connected to the earth ground point.
    Max.
     
    geoffers likes this.
  3. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    There is no straight answer. It depends on the application and situation.
    Try it and see what happens.
    What is the value of the pull-up or pull-down resistors you are using?
    You can also try putting capacitors at the input pins to ground to filter out any noise.
     
  4. John P

    AAC Fanatic!

    Oct 14, 2008
    1,634
    224
    I would say capacitors to ground, and resistors in series with the lines coming from the switches. In other words, make the connections to the processor pins through an RC filter circuit, and make sure the pins have a Schmitt-trigger characteristic. And in the software, put in a consistency check to be sure that a minor glitch on the input doesn't cause any change in the output.
     
    geoffers likes this.
  5. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    John_P has given great advice and is the way I would do it too.

    If I can add to that it would be to suggest using a good debouncing routine. Like testing the switch input pins every 1mS and ensuring there are >=100 readings of the same pin value before you log the new switch states.

    That means the switch must be stable for 100mS minimum, before being recognised as the new state.

    So you will have good hardware filtering taking out HF noise, and some heavy-handed software filtering taking care of anything else.
     
  6. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Thanks Guys,
    Great advice so quick! The only question I have now is, portb on the 16f819 has weak internal pull ups, but from a quick read through of the data sheet it would seem although they can be schmitt trigger for I2C and other modules, they are ttl for general i/o, porta has some schmitt trigger inputs but only four of them! Is a ttl buffer good enough to use as John P suggested?

    Hopefully all of this some debouncing and grounded shrouded cable should see me ok?!
    Thanks again Geoff
     
  7. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    If this is for an industrial installation in an industrial environment I would be concerned and I would take extra precaution. I would be concerned not only with erroneous switch status but also with the risk of blowing out your PIC from high ESD and EMI.

    I would choose to install line receivers of some kind with the following ideas in mind:

    1) consider using shielded twisted pair cabling

    2) consider using RS-232 or RS-422 line receivers

    3) consider using current loop instead of voltage sensing

    4) consider using optical isolators

    My thoughts.
     
    geoffers and mcgyvr like this.
  8. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    The PIC "TTL" inputs still have pretty good HI/LO transition points, with hysteresis.

    So they function much like schmidt trigger inputs anyway, with the main difference being different voltages they trigger HI/LO at, compared to the ST inputs. The datasheet shows the HI/LO voltages in the "electrical characteristics" chapter.

    So for most apps you will be fine. Just make sure there is a cap from the pin to ground (0.1uF is ok), and a series resistor going out to the switch (270 ohm is ok). The PORTB internal pullups should be ok with that.
     
    geoffers likes this.
  9. alfacliff

    Well-Known Member

    Dec 13, 2013
    2,449
    428
    one caution when using lc filtering of inputs. one video game company put a filter board on all inputs to reduce radiated noise probably, and the pi lc filter, shunt c, series l, shunt c, stretched static pulses to the point that they were seen as inputs.
     
  10. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    I agree, inductors can be a bad thing in input filters. They can cause a resonance (LC) so with certain pulse widths you actually get a larger noise pulse.

    Noise filters in signal paths are better using energy absorbtion, ie RC filters.

    L should only be used when you need good energy transfer efficiency (ie power lines).
     
  11. geoffers

    Thread Starter Active Member

    Oct 25, 2010
    239
    6
    Thanks guys,
    I think I will go with the advice of rc filtering, a sheilded cable and see how I get on, nothing really terrible will happen if it goes wrong! Its for use in a milking parlour so hopefully shouldn't be to noisey! If I have a problem I think opto isolators could be the next step.
    Cheers Geoff
     
  12. #12

    Expert

    Nov 30, 2010
    16,294
    6,804
    True. Cows don't radiate much RFI. More likely would be fluorescent lights or electric motors. :D
     
Loading...