Fluctuating digital inputs


Closed Thread
Results 1 to 28 of 28

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Yeah, connecting long flying wires directly to the inputs of the PIC usually isn't the best design practice for anything that's going to see some use in the real world. I am surprised though that it's picking up enough crap to drive the input high even with the switch pulling it hard to GND - that sounds a bit strange.

    Provided that the switch is really switching "hard" to Vss I'd start with a simple cap (10-100nF) across the input. Then perhaps a little series resistance on the input (outside of the cap) but Watch out for the voltage divider effect with the pull-up. An inductor in series with the input lead (again on the outside of the cap) and/or a couple of turns on a ferrite core.

    /Henrik.

  2. #2
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    The circuit has been working fine all day but again about 8PM it started acting up. Nothing in the house changed at that time so it must be something external interfering (neighbour's TV or something).

    I've managed to get my Oscope connected at the circuit end and the results are actually quite surprising. The line stays almost completely flat with very minor fluctuations just like you'd expect for an input being held to ground by 8M total of wire. The strange part is that every few seconds I see a huge spike that varies from 0.4V to over 2V. This is definitely enough to cause the problem (I believe anything over 0.8V is classed as high).

    I've attached 2 screenshots to show the kind of spikes I'm seeing. One with the switch closed (grounded) and one with the switch open (pulled up). Long wire or not I don't think I should be seeing spikes like this.

    I have some triac optoisolators laying around. Would I be able to use those to isolate the switch? I'm thinking to MacGyver something onto the back of the box and use a 5V supply to drive the opto's LED through the switch. Would these fluctuations still cause a problem though?

    For the cap/resistor. Should the 10-100nF cap be at the circuit end and by "outside of the cap" do you mean anywhere along the wire but not between the cap and the PIC?
    Attached Images Attached Images   

  3. #3
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Thinking to myself . . . have you tried shielding the wires? Maybe a schotkey diode to catch the spikes? Do you live near a Radar unit? Neon Sign? Tennis Court with vapor lamps? Someone have an electric fence? Electric blankets and aquarium heaters make lots of noise here in the states, I am thinking in the UK your mains are 240 v & I'm thinking spikes might have more amplitude from common appliances due to the higher operating voltages there . . . What goes on electrically near you at that time of day?
    Last edited by Archangel; - 7th October 2014 at 00:21.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  4. #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Hi,
    I have some triac optoisolators laying around. Would I be able to use those to isolate the switch? I'm thinking to MacGyver something onto the back of the box and use a 5V supply to drive the opto's LED through the switch. Would these fluctuations still cause a problem though?
    It's all about energy. Whatever is causing the spike is coupling energy into the wires. Your CMOS input is high impendence so it doesn't take much current to pull the voltage one way or another. The LED in a opto isolator needs a fair bit of current and it's unlikely you'll get enough energy coupled into your wires to turn the LED on. An opto isolator with triac output most likely won't work though.

    For the cap/resistor. Should the 10-100nF cap be at the circuit end and by "outside of the cap" do you mean anywhere along the wire but not between the cap and the PIC?
    Where the wires enters the board, alternatively right at the input pin of the PIC. And yes, by "outside" of the cap I mean between the switch and the cap. The resistor and the cap will then form a low pass filter but again, you need to select the value taking the pullup resistor into account.

    Maybe a schotkey diode to catch the spikes?
    I don't see how that should work. A diode could be used to clamp the spike so it doesn't go much above or below Vdd/Vss (to protect the input from damage due to over/under voltage) but if you clamp it so that the input does no longer see it it won't work under normal conditions either.

    Using shielded wires is a good idea and easy to try.

    /Henrik.

  5. #5
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    I honestly can't think of anything. It only seems to happen in the kitchen but that side of the house isn't joined to a neighbour. I've tried unplugging the fridge as that's the only electrical thing near it but that didn't help.

    I've got some UV fluorescent tubes near the wire and turning these lights on or off does affect it but once they are on they don't seem to be making it any worse. I've been testing with them off though just to be sure. There's no neon signs or anything near here. We do live very close to the sub station and generally get over 250V to the house but I designed the circuit to cope with that.

    I had another circuit running in previous years that had a longer wire to the same switch. It also used 10K resistors but it was a PIC18 that ran at 5V and I never had a problem. Not sure if it's due to 5V being less susceptible to the spikes or if they just weren't there before.

    I've just checked the Oscope again and it looks like the spikes are still there this morning. It must have been a fluke that it worked fine yesterday.

    I'm starting to think that a software solution might work. Now I've seen the spikes on the Oscope I can see they don't last very long. I could program a routine that starts counting every time an input changes state. The counter must reach a certain value before the input is classed as changed and if the state changes back then the counter is reset. Thankfully this circuit does almost nothing other than monitor the inputs so I've got plenty of clock cycles to waste.

  6. #6
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    That spikes can easily kill pic. Not single spike, but repeated...
    This is simplest circuit that will protect pic, and give you good immunity to spikes.
    Name:  PIC Input.png
Views: 604
Size:  20.0 KB
    Also this circuit add little delay...
    And use twisted pair for wiring remote switch, it should improve situation.

  7. #7
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    A very small delay isn't really a problem. The chip is currently sampling each input at over 300,000 times per second but it wouldn't really matter if it were only 100 times per second. I can't imagine the cap would add a delay much longer than that.

    I might be able to solder the capacitors under the PCB and the 2K-R12 resistor would have to be on the wire but since that's in series it's position shouldn't matter.

    I don't think any of the spikes go high enough to cause a problem with the PIC. I've never seen one get up to 3.3V. The negative ones may be a problem though.

    Thanks for your help. I'll try the extra cap/resistor as it looks to be a simple mod and see what the Oscope looks like.

  8. #8
    Join Date
    Sep 2009
    Posts
    755


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    R12 should be on PCB side of cable. Because long wire have a capacitance to ground.
    Spikes are clamped to -0,7V and +4V by pic internal diodes.
    Negative voltage on input pin can latch new pic.

  9. #9
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Hi,
    Thanks for doing the schematic pedja089 - that's exactly what I'm talking about. The 15k, 2k will give a low level of 0.39V. I looked at a 18F2420 datasheet and it states max voltage for a logic low on a schmitt trigger input to be 0.2Vdd or 0.66V with a 3.3V supply so you're below that by some margin - but not much. Definitely worth a try. Double check against correct datasheet!

    but since that's in series it's position shouldn't matter.
    Yes, I'd say it matters. You want the cap close to the PIC and the resistor close to the cap - not at the switch.
    If you're trying to filter noise generated from the switch itself bouncing etc then it wouldn't matter but in this case you're trying to filter out noise being coupled into the wires. If you put the resistor far away from the capacitor (which you want close the actual input pin) the noise can be coupled into the part of the wire between the resistor and capacitor basically negating the resistor.

    A simple software based low pass filter will most likely work as well but a little bit of hardware filtering is "the right way" and will provide some protection for the input.

    /Henrik.

Similar Threads

  1. How to Measure 2 or more digital inputs a the same time
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 29th April 2013, 02:23
  2. PIC 18f4680 DIGITAL INPUTS
    By MegaADY in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 30th July 2008, 07:34
  3. Digital inputs are some pin NOT working (PIC18F458)
    By san6302 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th July 2008, 06:50
  4. Setting up digital inputs
    By quester in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd March 2008, 22:14
  5. Digital inputs
    By Christopher4187 in forum General
    Replies: 5
    Last Post: - 1st August 2007, 23:14

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts