Connect with us

Trouble with PIC and Relay controlled model train point motors

Discussion in 'Microcontrollers, Programming and IoT' started by AimSkyward, Jan 28, 2013.

Scroll to continue with content
  1. AimSkyward

    AimSkyward

    4
    0
    Jan 28, 2013
    Hi All,

    I would be very grateful of some help with the following problem.
    To cut a long story short I am trying to switch several model railway points motors using relays (5V coil) to supply a 14V voltage. I have momentary toggle switches (SPDT) linked to an MCP23017 port expander (and the coil of the relay) with PORTS A and B connected to both throws of the toggle switch (each toggle switch takes up two pins - one for each throw). When toggling the switch the COMMON pin on the switch passes a 5V HIGH to the Port Expander pins and sets off an interrupt to the dspic so I can identify which switch has been switched. I then use this data to send a string to another MCP23017 which lights relevant LEDs to identify which points are live (One green and One red LED for each point motor). All of this is done with I2C and seems to work fine.
    The problem is that I am using a 14V power plugpack which goes straight to the relay (to supply the point motor when the 5V coil is switched) and then on to a voltage regulator to step the voltage down to 5V for the dspic etc..., however, when I switch the toggle switch the relay triggers, the point motor operates and the LEDs light very briefly but the dspic resets and it all goes horribly wrong from there :confused:.
    I suspect it is either current related or to do with the linked Grounds (everything is on the same Ground). I am no Electronics expert so it might be obvious to someone who knows their stuff. To be clear the plugpack provides the 14V needed for the relay/points motors as well as the supply to the v.reg for the step down to 5V.
    Any help would be much appreciated.
    Thanks in advance.
     
  2. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    Do you have a flyback diode across the relay coil?

    Bob
     
  3. AimSkyward

    AimSkyward

    4
    0
    Jan 28, 2013
    Hi Bob,

    No I don't, that's bad right?
     
  4. BobK

    BobK

    7,682
    1,688
    Jan 5, 2010
    Yep, it is probably the cause of your problem. When you remove voltage from a coil it tries to keep the current flowing and the voltage can rise to a very high level before it can find a way for the current to flow.

    You need to place a diode wired in reverse (i.e. cathode to the positive side, anode to the negative side) directly across the coil of your relay. This allows a path for the voltage spike (since it is voltage is reversed when the field in the coil is collapsing). And this takes all of your other electronics out of the path.

    Bob
     
  5. AimSkyward

    AimSkyward

    4
    0
    Jan 28, 2013
    Thanks for your help Bob, that makes sense. I will give that a go and hopefully it will solve my problem. :)
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-