Electrical Issue: PIC input false triggering, Signal Noise suspected.


+ Reply to Thread
Results 1 to 36 of 36
  1. #1
    Join Date
    Jun 2015
    Posts
    18

    Default Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I have just completed and tested a controller system of my design to automate trips between two stations and a yard siding on my model (HO scale) trolley line.

    I have used a PIC 16F722 to take advantage of the generous quantity of I/O pins. When tested on the workbench everything functions superbly. When I connect it to the model table it is a different story.

    My current design has 3 reed switches in the track between the rails attached to 3 pins on the PIC with pullup resistors in parallel. These detect the trolley as it passes overhead (with a magnet attached below it.) The reed switch closes and pulls the pin voltage low and the trolley stops at the station, etc. This design works flawlessly on the bench with relatively short leads to the PIC.

    On the model table when everything is connected and tested, the location sensors(reed switches) are triggering falsely. The trolley doesn’t get anywhere near the reed switches and while it is running, the PIC jumps to the next event in the program. I remedy this by disconnecting the switches/wires thus taking them out of the test. I then run the system by shorting the corresponding PIC pins to GND wherein the system works correctly again.

    I anticipated this problem and to prevent noise on the wires false triggering the PIC, I used a twisted pair to each switch. I view the track as a long antenna which runs roughly parallel to the sensor wires. In addition, the trolley motor is likely a significant source of stray EMF. I have been reading up on Signal to Noise Ratio but the subject is a bit intimidating for one without a scope and test equipment. Since I am self-taught my approach is largely trial and error.

    My next plan is to test using a sensor wire consisting of a twisted pair with metallic sheath and ground it on both ends.

    For those of you who have your feet grounded in the real world of control system design, I would gratefully appreciate some practical advice if not too technically challenging.

    Thanks.

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,414


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    How much current can the reed switch sink (datasheet link?) and what value do you have on the pullup resistor?
    It might suffice to simply put in a stronger pullup.

    Another thing to think thru is to what the various signals are referenced and how the signal currents flow, do the signal current share paths with any high current signals etc.

    A cheap, easy and good way to interface stuff to the "real world" is to use opto-isolators. That way the controller is isolated from the "real world" and the reed-switch (in this case) would be driving a LED which takes quite a bit of current, not likely that noise is going to turn it on.

    I'd try with a stiff pullup to begin with.

    /Henrik.

  3. #3
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    197


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I'm not a professional; I'm a hobbyist. My only qualification is a lack of expertise that has lead to many similar issues - odd, inconsistent behavior that seemingly comes from nowhere. For me, it seems always to be a power issue - sagging voltage, poor connection somewhere, two wires touching... I'm careful, I worked twenty years soldering under a microscope, but somehow...

    So, I'd first say, "I feel your pain!" For me, better it doesn't work at all - those kinds of problems I can isolate.

    I'd first try isolating your power - run it from batteries or a second supply to be sure your power is good. Be sure you have a healthy smattering of filter caps around your inputs. Henrik's idea is good, good solid power at decisive levels!

    Presuming you're "light" on equipment as I am, maybe you could hook up your inputs (reed switch lines) to ADC and take a look at voltage that way... see what kind of jitter you've got...

    The other thing is, perhaps you've got some debounce issues - comes to mind as you say, "The PIC jumps to the next event."

    It's hard to say anything for sure as I cannot see the program, track, or wiring. Just some ideas and moral support...

    Let us know how it works out (and I think it would be ok to post a picture of the layout - I know I'd like to see it).

  4. #4
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    A flash comes to my mind: what about static electricity buildup on the trolley itself?

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    abecker,

    are you using the same reed switches on the test bench that you have installed under the track?
    if not, is it possible that the switches you have under the track are flakey? defective?

    I assume you have considered vibration causing the reed switches to falsely trip.
    Have you considered switching to a Hall Effect switch to detect the train passing.

    As others have stated... I would put plenty of bypass capacitors, even one on the actual input line itself.

    Another thought is to have your code check multiple times for positive closure of the reed switch.

    something like... [caution: untested code to follow!!]

    Code:
    IF TrainIN = 1 THEN
       PAUSEUS 100  'note this time delay should be somewhat shorter than when the train really is passing by but longer than a false trip
       IF TrainIN = 1 THEN
           GOTO TrainDetected
       ENDIF
    ENDIF
    in other words determine how long the reed switch is closed when the train passes (an oscilloscope would help here) and make sure that your code requires the input to be true for longer than what a false trip would be

    In developing code and testing interface circuits I find that an oscilloscope is one of the most valuable tools on my bench.

    good luck
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Like the guys said, a stiff pullup and a cap. I would also add an inductor to keep the noise spikes out.
    You can probably get by without L2 in this diagram but added it in just in case.

    Name:  Filtered input.JPG
Views: 737
Size:  60.8 KB
    Louie

  7. #7
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Henrik,

    I don't have a spec sheet for the reed switch so I can't verify the current capacity but it is rather small (~5mm l. reeds) in glass tube. The pullups are 47k ohm and on the control board about 8mm away from the pic Ports C4-C6 and connect with a ground trace which incidentally shares the same trace with Vss two pins away. I have the usual bypass cap (100nf) soldered across the Vss & Vdd pins directly below the PIC.

    I understand what you suggest about too weak a pullup, I had wondered about that myself, but I am unsure of how high a pullup current the pin should see, in other words how "stiff" the pullup should be. The spec sheet says the source current max on any port pin is 25mA. My gut tells me the reed switch should be able to handle that at 5vDC but I would hope that it would not be necessary to max out the current to mask the noise.

    Any thoughts?

  8. #8
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Amoque,

    Thanks for your thoughts and empathy from a fellow "enthusiast."

    I have read some related posts that the forum software provided presumably due to the tags I defined. There were also some good insights though most of the users there had sensors which were much more sophisticated devices than my lowly reed switches. One person recommended double sampling and rejecting the highs to short to be legitimate by delaying some micro seconds between the samples. I had thought that perhaps using the "Button" command in PBP3 would help de-bounce the input.

    I will try running with battery power. Presently I have a 5vDC wall type supply with no ground. I am also going to heavily shield the wires from the reed switches and attempt to use best practices in grounding the shields. I also read elsewhere on the net that I might have to reference my main control board ground plane to the same "earth" ground if I am going to shield/ground all devices.

    I have the project fully drawn and documented but I thought due to its size, I would submit that as a last resort.

  9. #9
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I don't know about static buildup because I never have experienced that. It did get me to thinking that since the trolley takes power from an overhead wire and completes the current path to the track rails, I have noticed quite a bit of arcing as the catenary moves along the wire. Talk about dirty transmission conditions and potential for all sorts of electrical stuff going on. I have a way to switch the trolley pickup to just the rails and eliminate some of that arcing. I should try that as a test.

    One thing I can say is that the motor current path is run through relay contacts which do not share any current paths with the control circuitry, although they are in close proximity on the control board. Boy I sure hope the problem doesn't come down to isolating the relays in a grounded case since I just re-etched and re-built this version of the board from an earlier version where they were apart.

  10. #10
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Heckler,

    The reed switches are different ones but I have rigorously tested the ones under the track including the lead wire to the location of the new controller. This was easily done by rolling the trolley with magnet over the switch and checking the continuity. All 3 worked well.

    Vibration seems to be unlikely but I would have to devise a test to confirm that.

    I have worked with hall sensors before and considered it in concept but the most distant of the 3 track sensors is about 7 feet away from the controller. The advantage of the reed switch is that it does not require the additional complexity of getting 5vDC power to each sensor location and in the end, the the signal is still traveling along an antenna-like lead wire parallel to all this noisy DC motor operation and an arcing power connection (the trolley catenary.)

    Bypass caps as you suggest are a recurring theme in all the posts I have read. I assume you mean putting them on the control board trace at the node where the the input pin and pullup intersect? That would make it parallel with the pullup to ground?

    As I mentioned in a previous reply, I had read about dual sampling and think the idea has merit. I understand the concept in the code you provided, thanks. I will try this if external shielding fails to solve the problem. It is a bit of a hassle getting back into the control enclosure to get things ready for ICSP (some dis-assembly required.)

    I have a clunky old Tektronix scope with a CRT output and one channel fried but I could always make a project out of dusting it off and remembering how to use it again!

  11. #11
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Posts
    67


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I've found that: Basic Electrical Parameters of Reed Switch (PDF).

    You'll see on page 3 they bounce a lot for a few miliseconds. I suggest you lower the pullup to 1k to improve noise immunity. If you're going to use LinkMTech's circuits think about using a Schmitt Trigger input your PIC.

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


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I understand what you suggest about too weak a pullup, I had wondered about that myself, but I am unsure of how high a pullup current the pin should see, in other words how "stiff" the pullup should be. The spec sheet says the source current max on any port pin is 25mA. My gut tells me the reed switch should be able to handle that at 5vDC but I would hope that it would not be necessary to max out the current to mask the noise.

    Any thoughts?
    The 25mA source/sink current doesn't apply here. That's what the pin can source or sink when it's configured as an output - that's not what you're doing. When the pin is configured as an input you can, in this case, pretty much ignore the current flowing into it (it's about 100nA on the 16F722).

    Your pin is held high, at 5V (?), by the 47k pullup. The only current that's flowing is the 100nA (max) into pin and any leakage current thru the switch. The reed-switch, when activated, pulls the pin to GND, ~100uA is flowing down thru the pullup resistor causing a voltage drop of ~5V across the resistor, the input is now low. All is well, on the drawing board - and in your testup.....

    Que long leads, aka antennas. With such a weak pullup as 47k it doesn't take much noise on the long wires to start "yanking" on that logik level '1' provided by the 47k resistor.

    Although there are reed-switches available (I quickly browsed Digikey) that can only handle around 100uA, some 1mA most of them are capable of 100mA or more. If I were you I'd lower that pullup by an oder of magnitute (or two even) and add a small cap as per previous suggestion - then try again. Even a 470ohm resistor will still only give ~10mA thru the switch.

    /Henrik.

  13. #13
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    LinkM,

    Thanks for the great circuit sketch! I don't have any inductors on hand but if this works well, I would consider making a module of it for future uses of the reed switch as a sensor.

    I have an application question and to help explain it I have attached a schematic of my board. My traces on the etched board follow the lines on the schematic literally. You will observe that at PIC pins C4-C6 my three sensors are pulled up with 4.7k resistors to 5vDC. At the same connector I have a ground pin which further down the line combines the 3 grounds from the switches.

    My question is: Would it be good or bad practice to place the inductors further away outside the controller enclosure say under the table? This would necessitate for each of the 3 signal wires a length of lead wire maybe 6-12 inches away from the board itself (am I just creating another albeit shorter antenna?) The control enclosure is already pretty filled with stuff but maybe I could still fasten a daughter-board to take care of this function. I would really hate to redesign and rebuild my present main board yet again to integrate the inductors.

    Lastly since I am new to working with inductors could you spec or describe what I would be looking for number-wise from say the Digi-Key online catalog?

    Thanks.
    Attached Images Attached Images  

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


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I'm not sure about the current required for the "run/stop, direction and turnout relays" but I notice you are sourcing the current instead of sinking it thru the PIC. That's bad design to me as most mosfet's even in the case of internal fet's in the PIC can sink more current than source. I would ideally use a NPN transistor for the relay drive circuits and feed them as a separate supply connection to the board where the power enters. I would also place a 10uF cap at the PIC pin's 19 & 20 along with the 100nF cap you already have. I also notice you have NO cap's for the display power circuits. I agree with Henrick that the ideal interface method is for optoIsolators on the inputs from the reed switches. If the wiring is run along side the track and the engine is running there is quite a bit of coupled energy into the inputs of the PIC as the engine is probably driven by a DC Brushed motor as well as the wheels making and breaking the circuit.
    Dave Purola,
    N8NTA
    EN82fn

  15. #15
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Michel,

    At present I'm not so concerned about reed switch bounce (although that may become a later issue) since the jumping to the next set of operations in the PIC program behavior occurs without switch activation, before the magnet gets anywhere near it. That is why I suspect some sort of EMF is being picked up by the switch leads which run the length of the track above.

    I am aware however that there may be several things acting here so I am willing to give all theories consideration.

  16. #16
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Henrik,

    I over thought the issue and had a "brain-fault" when I got to thinking of the output parameters instead of the pin configured as imput. I appreciate your pointing that out and following it up with a very comprehensible explanation and calcs. I follow how the noise might be more influential on the signal if the pullup is not adequate.

    Thanks for the clear explanation and for pointing out my error in thinking about the pullup currents.

  17. #17
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Dave,

    As a novice I don't get exposure to best practices so this advice is very welcome. I will copy the info down and study it carefully. It will certainly be implemented in future designs that I explore. In my previous version of this control board I used relay driver IC's with single coil latching relays. They shared the same +5 and gnd traces with the PIC however. As far as sourcing current at the pin, since these relays are dual coil latching I only pulse them and no two relays are pulsed at the same time so I felt safe that I was not exceeding any pin source capability.

    I appreciate your suggestion that I should have caps for the display power. I will do further research on how to accomplish this.

    I think your last remark is on the money. As I mentioned in another reply, I run the trolleys off the overhead wire at times (I can switch between rail only & rail with overhead wire.) When running off the overhead, the trolley caenary arcs plenty. Talk about a "dirty" operating environment!

    I appreciate your comments.

  18. #18
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    abecker,

    I think your getting some excellent advice here. As I have said before there are world class programmers here (and also those knowledgeable in electronics design) and all are willing to help.

    For all this good advice I think you might owe us some pictures of your train setup and all that
    Having a train that actually has an catenary that actually works sounds pretty awesome!
    What a fun world to live in, down at the miniature level.
    And merging micro controllers and PIC BASIC... what could be better.

    You might consider wiring up a length of 6 conductor ribbon cable to the ICSP header then solder it up to a 6 pos header to plug your pickit into.
    that way you can easily impliment code changes without having to tear things apart.

    Nothing better than to be able to make code changes and test ideas out and see almost instant results.

    great stuff!!

    now if you have a few minutes check out this...
    http://hackaday.com/2016/01/17/the-s...ur-wunderland/
    It is awesome to go to google earth and get down in minature and roam around this model setup.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  19. #19
    Join Date
    Nov 2007
    Location
    West Covina, CA
    Posts
    219


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Quote Originally Posted by abecker View Post
    I would really hate to redesign and rebuild my present main board yet again to integrate the inductors.

    Lastly since I am new to working with inductors could you spec or describe what I would be looking for number-wise from say the Digi-Key online catalog?
    Hi abecker,
    The inductors should be in your controller circuit because just as your intuition suggests, you will end up with a short antenna at the input of your box.
    If you have room at the reed switch connector, these inductors can be installed at the molex connector you have there by soldering each one inline with the wire going to the switch and the other side crimped to the connector pin. Be sure to shrink tube each one to keep from shorting to its neighbor.
    And it looks like you can put your filter caps at each (R1 pullup resistor and PIC input) to the nearest GND.
    Louie

  20. #20
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    another way is to filter the input with a software routine

    Code:
    reeds var byte
    reeds_flg var byte
    reed_1_active var reeds_flg.0            
    reed_2_active var reeds_flg.1
    reed_3_active var reeds_flg.2
    reed_cnt var byte[3]
    reed var byte
    define reed_threshold 64
    
    chk_reeds:
    reeds=portc & $70  ;c4 c5 c6  active low
    if reeds < 112 then
    reeds=reeds >> 4
    for reed = 0 to 2
    if ! reeds.0 then
            reed_cnt[reed]=reed_cnt[reed]+1 
            if reed_cnt[reed]> reed_threshold then reeds_flg.0[reed]=1
    else
            reed_cnt[reed]=0
    endif
    
    reeds=reeds>>1
    next
    endif
    return
    if you call the chk_reeds subroutine regularly (must be regular) say in this case 100 times per second, then if a reed input is consistently low for 64 (counts in a row the reed_threshold) then the reed_x_active flag will be set.
    Last edited by richard; - 12th February 2016 at 11:26. Reason: correction

  21. #21
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    LinkM,

    I appreciate your idea to inline the inductors and naturally shrink-tube saves the day for so many inline solutions like this.

    I did strike upon the idea of soldering the caps to the traces under the board because the board is on standoffs anyway.

    By the way in my searching the net for use of inductors and caps for noise filtering, I discovered some LC filter arrays in a single IC type package with 4 per chip, by TDK (series MEA) but it looked like they were narrowly designed and spec'd. for telecom use. Not understanding enough about LC filters I didn't know if the product series could have helped my situation. It was a very slick idea though having 4 filters on the chip. If that worked, it would be nice to put that on the main board in any new design I might come up with in the future.

    Thanks for all your help.

  22. #22
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Thanks Richard.

    This has great potential in my code because as you commented, once I set close the realys to the trolley power all I have to do is loop through the routine that checks for a low sensor. To make it easier, the trolley dbeing on a track can only go in on direction at a time so in each stage of travel I know exactly which sensor to poll. Not like I would need an interrupt to see which of the three sensors went low. The time the magnet is over the reed switch is eon's compared to the rate at which the pic can poll the sensor line.

    As I mentioned to one other reply, the pic advances to the next logical set of events just when the trolley gets moving and is several feet away from any sensor. This is what leads me to think some DC motor noise or even arcing of the pickup on the overhead wire is being picked up at the sensor pins and causing a false signal.

    I will study your code and possibly with it and many of the other outstanding suggestions here, find a solution which I will gladly report on.

  23. #23
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Heckler,

    I first discovered this thread by looking at a print ready version of the tree.

    My trolley system is at the beginning stages but all the track and overhead is assembled and in good working order when run manually.

    I am not at home now but I will send some photos of the table and the controller.

    I agree the advice has been very generous and I received more feedback than I expected. I would hope this thread is of use to others in the future with similar designs.

  24. #24
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Voila! Photos as promised.

    I have yet to provide the scenery work but first things first- get it operating. Manual operation works as designed.

    The power (0-17vDC) from the speed control can be routed for overhead supply or to the tracks only by a manual switch. The yard turnout can be operated manually or via the PIC logic.

    Controller has an LCD and three buttons to program number of trips, seconds at east and west (future) stations or yard termination. Prompts for setting automation are displayed on LCD.

    I made the enclosure out of acrylic sheet so I could custom size it and intended to paint it gray but since it looks pretty cool as a transparent case I think I'll leave it that way.
    Attached Images Attached Images       

  25. #25
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    197


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    No offense, but I hope you are forced back here regularly as this build progresses. I would love to feel (in some small FREE way) that I had helped to make it come together. I've seen many genius level projects here, but my favorites are always those where knowledge is applied to passion.

  26. #26
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    No offense taken.

    Nobody has ever accused ME of being a genius but my tenacity has lead me to many learning opportunities.

    I will try several of the strategies offered by the contributors and hopefully if the problem gets resolved soon, I will report back.

  27. #27
    Join Date
    May 2013
    Location
    australia
    Posts
    2,090


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I discovered this curious method of debounce/noise filtering on the arduino forum this week . the idea translated to pbp easily and makes my worst cheap and nasty tactile switches perform as smooth as silk.
    here is a little demo (might add there is no cap used at all on the switch )

    Code:
    '****************************************************************
    '*  Name    : debounce.BAS                                      *
    '*  Author  : richard                   *
    '*  Date    : 2/17/2016                                         *
    '*  Version : 1.0                                               *
    '*  Notes   :  pic16f1825                                       *
    '*          :   switch debounce                                 *
    '****************************************************************
    #CONFIG
                 __config        _CONFIG1,    _FOSC_INTOSC & _CP_OFF & _WDTE_ON  &  _PWRTE_ON  &  _MCLRE_OFF  & _CLKOUTEN_OFF
                  __config      _CONFIG2, _PLLEN_ON & _LVP_OFF            
    #ENDCONFIG
     
    OSCCON=$70 
    DEFINE OSC 32
    ANSELA=0
    ANSELC=0
    TRISA = %011010
    TRISC = 0 
     
     
    led1 var lata.5    ;  lit when  sw operated
    led2 var lata.2    ; toggle when sw   operated
    sw var porta.3     ;  the switch (active low ie has pull up resistor)
    old_sw_state var bit
    sw_state var bit
    sw_buff  var byte
    clear
    
    main :
        gosub ck_sw
        if  sw_state != old_sw_state then   ; the sw has changed either on or off
            led2 = !led2
            if !sw_state then led1 = !led1      ; if state is changed to on
            old_sw_state=sw_state            ;remember state
        endif
    goto main
    
    ck_sw:
        sw_buff= (sw_buff<<1) | sw
        if (sw_buff=$7f ) and sw then
           sw_state=1
        elseif  (sw_buff=$80 )and !sw  then
                sw_state=0
        endif
    return
    Last edited by richard; - 17th February 2016 at 02:33. Reason: no capacitor used

  28. #28
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Hi Richard,

    This a very interesting strategy and I have added it to my collection of code snippets.

    On this project my approach is to try the hardware methods first since they (like ground shielding the signal line, etc.) are just good practice anyway. If that doesn't do the trick I will try some of the software solutions. I hope this method will be a way to somewhat isolate the cause of the false triggering or at least give an idea what might be going on.

    This project has even forced me to get out my really old and clunky oscilloscope and get some new probes for it. Now I just have to figure out how to set it up to check for noise on the signal line. I'm a bit rusty on using the scope for diagnostics. It's been quite a while since my last class in EE.

    Thanks for your thoughts,
    Allan

  29. #29


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    There are a lot of good suggestions here. One possible cause could be a magnetic field being set up by current passing through the rails.
    This could be causing the reed switches to randomly close. Or magnetic coupling into the long leads. Google "Right Hand Rule"

    It would be easy to test. Leave everything connected as is, but move the reed switches a few inches away from the tracks.

    Hope you figure it out

  30. #30
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    @mark_s
    I would add that moving the reed switches a few inches away but leaving all the wiring as is would likely cause the reed switches to stop functioning but that is OK as it would allow you to determine if mark_s's theory holds true.

    If you still have false trigering then it was because of either the magnetic coupling or possibly vibration.

    At least that is what it seems you were getting at with your suggestion (or am I missing your point Mark?)

    @richard

    Here is how I devised a software debounce that would not block the rest of my main code loop
    Code:
    Main:
    if swflag = 1 and sw1=open then swflg = 0  '(sw debounce) clear swflg only when switch released
       
    if swflag = 0 and sw1=closed then   'sw1 button detected and valid
            swflag = 1      'set flag that switch has been closed
            (code goes here that you wanted the switch to do)
    endif
    
    (more main code loop goes here)
    GOTO Main
    it requires the swflag = 0 before it will acknowledge the sw1 is pressed. Other wise the switch will be ignored.
    the only way for swflag to return to 0 is for you to release sw1
    Last edited by Heckler; - 21st February 2016 at 01:54.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  31. #31


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Quote Originally Posted by Heckler View Post
    @mark_s
    I would add that moving the reed switches a few inches away but leaving all the wiring as is would likely cause the reed switches to stop functioning but that is OK as it would allow you to determine if mark_s's theory holds true.

    If you still have false trigering then it was because of either the magnetic coupling or possibly vibration.

    At least that is what it seems you were getting at with your suggestion (or am I missing your point Mark?)
    Dwight,

    Yes, just move the reeds temporary to see if they are triggering. If that is causing the problem, maybe just by rotating the reeds 90 degrees would solve the problem? Abecker made two statements that are key - "It worked superbly on the bench" and installed with the reeds disconnected, it quit triggering. So it's probably interference entering the cable or the reeds closing?

    Abecker should take note when it is triggering. On acceleration the motor will be drawing the most current. On deceleration it could be generating inductive spikes back into the power supply. Does it false when the train is not moving?

    Brings back memories, my dad had a large H0 gauge train table when I was a kid. We couldn't wait for him to get home from work
    so we could run it.

  32. #32
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Hello Mark,

    I have invested some time in running the long signal leads in shielded cable and grounding it and everything I can think of to the earth ground of my 110vAC power cord. The main control board being in a plastic enclosure also now has a ground strap to the same ground. If I don't get positive results from this and other remedies offered here my last recourse is to fabricate a steel enclosure and ground it as well.

    There is one construction hitch to moving the reed switches (although I agree it would be a sensible test) in that the two lead wires run down through holes in the table. I would have to fasten some type of disconnect there to make them removable. I soldered the leads to the grounded cable with the shortest possible length to reduce the chance for EMI pickup. I try to avoid many connectors for I feel each one is a potential weak point.

    Later today I will have everything wired and ready to test except the adding of inductors since they are still on their way from Mouser.

  33. #33
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Mark,

    I'll address the second remark in this reply. The first time I discovered the problem (and it did occur consistently) I would have to say there is no acceleration or deceleration possible because the speed control is set and remains at a preset DC voltage (I have no means of attenuating the speed control, electrically or mechanically.) Knowing this I suppose it is safe to conclude that there is a considerable inrush of current when the control relay closes.

    As I recall from the first real run the PIC firmware closed the "Run" relay contacts and the trolley moved a few inches in the correct direction. Then operation jumped to the next logical state which was sensing the trolley position and stopping at the station. The only problem being, it was not near enough to the reed switch to activate it using the magnet below the car.

    You ask a very good diagnostic question which I have not tried yet. I should test for false triggering without the trolley (dc motor) running but voltage applied to the track and overhead wire. This should rule out any influence of those objects. Lately I have been asking myself the uncomfortable question as to whether I have been wrongly suspecting DC motor EMI of causing the problem. This test would help eliminate the transmission sources from the cause.

    I hope my work later today will shed more light. Thanks for your insights.

  34. #34
    Join Date
    Jun 2015
    Posts
    18


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    I am posting this reply to my first inquiry for those in the future who are merely browsing may want to know the results without going down through the many threads in detail. Having said that I would encourage any person who needs to solve a similar problem to dig down through (the threads of) this exchange of great ideas and suggestions.

    I am happy to report that my false triggering problem has been solved no doubt to a combination of systems suggested here. I will summarize what I did for others to consider.

    - I added bypass caps to all power supply traces across the +5 & Gnd.
    - I installed a common ground bus connected to the house power earth ground.
    - Since I am using a wall-type 5vDC power supply without a ground and a plastic enclosure, I grounded my main control board to the bus.
    - I used a shielded cable between the reed switches and the control enclosure and connected the shield to the ground bus(see attached schematic.)
    - I added bypass caps to each of the 3 reed switch signal lines.
    - I decreased my pull-up resistor values on the signal lines from 4700ohms to 47ohms
    - I have not yet received my inductors but have etched a small carrier board (no room left on the main board) to connect them as shown.

    Name:  Schematic.jpg
Views: 561
Size:  49.6 KB

    I have not needed to put in place the software-based solutions but they are very interesting and may find their way into future work.

    Once again I thank all who contributed to this discussion. There are many new details for me to apply to the next project.

  35. #35
    Join Date
    Sep 2010
    Location
    Las Vegas, NV
    Posts
    305


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    It would be interesting if you could do one of the above solutions at a time and narrow it down to which one or combination of the several solved it.

    The 100uH coil going to ground isn't doing anything and could be deleted. I'd suggest only having one ground for the reed switch and shield preferably as close to the PIC as possible.

    Did you choose the cap and the coil values for any particular reason? I'm assuming you're using a PWM controller and wonder if you could tune them closer to your PWM frequency to reduce spurious noise further. Usually I have many caps laying around and only a few coils so reducing your cap size would be the easiest.

    Love the train.

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


    Did you find this post helpful? Yes | No

    Default Re: Electrical Issue: PIC input false triggering, Signal Noise suspected.

    Wow, Twisted/shielded cable, Inductors, 47 Ohm resistors, and capacitors.... Why not just use some opto isolators at the PIC side and run some current, say 10 mills or so thru the reed switches with 20 gage unshielded wire and call it a day. I can't beleive this topic is still doing.
    Dave Purola,
    N8NTA
    EN82fn

Similar Threads

  1. Intermittent reset of 16C6440 - possible noise issue
    By Christopher4187 in forum General
    Replies: 4
    Last Post: - 16th May 2012, 12:43
  2. Noise on input signal
    By fanman in forum mel PIC BASIC Pro
    Replies: 17
    Last Post: - 28th February 2012, 02:55
  3. Electrical noise problem with PIC 16f84
    By Snap in forum General
    Replies: 11
    Last Post: - 26th September 2007, 09:36
  4. Input Noise
    By PJALM in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 28th February 2006, 19:26
  5. False Triggering I/O
    By pdegior in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th July 2005, 09:02

Tags for this Thread

Posting Permissions

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