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