Maker Pro
Maker Pro

Trouble with PIC and Relay controlled model train point motors

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.
 
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
 
Top