Fluctuating digital inputs


Closed Thread
Results 1 to 28 of 28
  1. #1
    Join Date
    Jun 2007
    Location
    Mansfield, UK
    Posts
    697

    Default Fluctuating digital inputs

    Hi, I have this weird problem where a PIC chip is seeing the input pins fluctuate randomly (between 1 and 10 times per second).

    The inputs are as simple as it gets. It's just a switch from the PIC to ground and a 10K pullup resistor to VDD 3.3V (also tried 100K).

    The problem only occurs when the switch is on the end of a 4M long wire. This would suggest some kind of EM interference but I can't see how such a minor current could cause a digital pin to change state.

    The problem happens regardless of whether the switch is open or closed. It happens more often when it's closed though.

    According to the datasheet all digital inputs have a Schmitt trigger that is enabled by default.

    I've tried it on multiple pins with no difference.

    I have disabled all analog inputs in code.

    I was about to connect my Oscope this morning but it seems that after the circuit being left on overnight it's fixed itself. It was also working fine yesterday evening then suddenly went weird. I don't know of anything in the house that could be interfereing.

    Can anyone think of anything that might cause this or any tests I can do? It's working now but I'm worried it will fail again when it really needs to be working.

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Maybe the switch is faulty?

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    There is a remote possibility that it's faulty and not making contact properly when closed but it definitely wouldn't be making contact when it's open.

    Just to be sure I'll try shorting the wires at the switch end the next time I see the problem. I'll also see if I can locate a backup switch.

  4. #4
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Come on now, What kind of design is that? An input pin to a CMOS device that is at least 12 feet long with nothing more than a pullup resistor of 10K? Well actually 24 feet long, I forgot the return path. If it is to be a robust design then allow some current to flow in the remote switch circuit by means of an led for an OPTOISOLATOR in series with the switch. Think about it? Even with a 10K pullup resistor and a schmitt trigger, with a 3.3 volt VCC the switching voltage threshold is at best 1 volt.
    Dave Purola,
    N8NTA
    EN82fn

  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'm not sure I understand. Surely anything in series with the switch would weaken the return voltage?

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,807


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Dave says that you should not connect such electric circuits directly to the CMOS inputs of the controller.

    Better is to use an optocoupler and your switch be in series with the source, limit R and the opto LED. The optocoupler output could then be connected to the PIC input, having an electric isolation from any external EMC source.

    Ioannis

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


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Ahh I see. I'll make sure to do it that way in the future. Thank you both for the tip/clarification.

    Unfortunately this particular circuit is already on a PCB and it's too late to redesign.

    I've been doing some reading about pull-ups. Someone mentioned that the weak internal pull-ups in the PIC24 family are about 50K and they could easily allow EMI on long traces (let alone external wires). I guess this means the 100K resistors are way out. Quite a few people use 10Ks but it seems that 5K is recommended so I'll give some of those a go later.

    The good news is that the circuit has now been running for over 7 hours and hasn't randomly triggered once. Maybe the interference is coming from something that's only on at night.

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


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Quote Originally Posted by The Master View Post

    The good news is that the circuit has now been running for over 7 hours and hasn't randomly triggered once. Maybe the interference is coming from something that's only on at night.
    Your switch wiring is very close to resonance to communications r/f frequencies either private or GOV If you are running X # of meters you could be resonant at 1/4 wave or 1/2 wave . . . perfect as an antenna. As indicated above a load so as to define the actual switch event, an opto solution, or if you can determine the source even a choke to block r/f.
    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.

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


    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.

  10. #10
    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   

  11. #11
    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.

  12. #12
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    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.

  13. #13
    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.

  14. #14
    Join Date
    Sep 2009
    Posts
    737


    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: 491
Size:  20.0 KB
    Also this circuit add little delay...
    And use twisted pair for wiring remote switch, it should improve situation.

  15. #15
    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.

  16. #16
    Join Date
    Sep 2009
    Posts
    737


    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.

  17. #17
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    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.

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


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    I will have to put the resistor inside the plug which is on the circuit end of the wire then. That's as close as I can get it without cutting through traces on the PCB. It still puts the resistor within 3 inches of the PIC though.

    The PIC I'm using is a PIC24FJ64GA002. I'm pretty sure the datasheet said VSS-0.2V is low and 0.8-VDD is high.

  19. #19
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    That is just print scr, from my schematic.
    My Vdd is 2.8V, so lower threshold is 0.56V. With 2K and 15K combination low level is 0.32V.
    That is almost half of threshold, it works fine for me.

  20. #20
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Bandaids,Bandaids,Bandaids, Just put an optoisolator and a couple of resistors on a small piece of Vectorboard and be done with it. If you are going to use the circuit in post #382 you might as well do it right with anh opto.
    Dave Purola,
    N8NTA
    EN82fn

  21. #21
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    If you referring to my post #14...
    My circuit use only 10uA with all inputs shorted to GND.
    Vdd for inputs is controlled by PIC. So just give me opto that uses less than 1uA and I'll be happy to use it.
    By the way device passed ESD and RF immunity test without false triggering or any damage
    Last edited by pedja089; - 7th October 2014 at 19:37.

  22. #22
    Join Date
    Sep 2009
    Posts
    737


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Double post. Bad internet connection...

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


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Current usage isn't really a problem for me so I'm happy to use optos. They will be in a V2 of the PCB for next year though.

    The existing PCB is running with a few minor modifications and debouce code and so far I've not had a single problem.

    Thanks everyone for your help. This thread will be invaluable when I'm designing V2 and other similar PCBs. I'll also be paying more attention to noise from now on.

  24. #24
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Good stuff. I'm in the planning stages on a residential alarm system and long runs of wire are a fact of life.

    I'm using 4 strand telephone twisted pairs, don't remember if shielded. But I'll be sure to keep an eye on interference.

    Robert

  25. #25
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    I have a nagging doubt that you are seeing a R-M-W port problem. A schematic diagram will help clarify the scene for me.

  26. #26
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Robert, An alarm system hey, When I worked for Westinghouse alarm company about 40 years ago we would use from 15 to 20 Ma. for our contact wetting current in loops. When using switches, you can't rely on anything less to break the oxidization of NO contacts. The system I designed for my home uses a cunstant current source for the NC loop as well as current source's the all NO switches inseries with the LED's powered by 12 volts. I have never had a problem with it. Using constant current allows for some loop resistance variation over time as switches and wiring connections age. No false alarms...... Also you DON'T have to worry about shielding the wiring due to electrical noise.
    Dave Purola,
    N8NTA
    EN82fn

  27. #27
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    2,599


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    So you just have a resistor and LED on every line amd that's it?

    That could help diagnostics in case the keypad/display circuit acts up.

    Robert

  28. #28
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default Re: Fluctuating digital inputs

    Robert, I don't know what you mean by a resistor and led on each line. I am talking about all of the sensor loops, and individual sensors coming into the control board from some distance away. Having an additional led in series with each of the curcuits would also be an ideal way to visually diagnose the system externals though. What I was talking about was using something like a constant current diode or what I used is a LM317 in a TO-92 package and a resistor configured as a current regurator of 20 Ma. in each of the source circuits for the individual sensor circuits and the loop circuits. They were all powered by the 12 volt power supply.
    Dave Purola,
    N8NTA
    EN82fn

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 : 1

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