<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:black;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor=white lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Brian, here is my summary of the situation.  Anyone can correct me as needed </span><span style='font-size:11.0pt;font-family:Wingdings;color:#1F497D'>J</span><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Your train switch is two 12V solenoids that are alternately pulsed to change the direction of the track.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The two solenoids have their “grounds” connected.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>You have a working circuit using an N MOSFET on the low side that acts as a switch to connect the<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>common ground terminal to ground.  So, if you connect 12V to either the Straight or Turn connection<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>the Arduino can move the switch.  If you connect 12V to both straight and turn, when the MOSFET<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>closes, both solenoids activate (which is not what you want).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>One option is to use a P MOSFET on the high side to control application of 12V to Straight or Turn and have the Ground terminal connected directly to ground.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The problem with this is that your port expander can only provide 5V to the gate of the MOSFET, which is not sufficient to turn it off (needs to be around 10V).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Pulling the gate up with a resistor will turn the MOSFET off, but will send 12V into your port expander pin (not good).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Now, you need some other device between the port expander pin and the gate to switch 12V.  This could be a transistor or an N MOSFET.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So, now you need two MOSFETs on each side.  I use something similar to this on my Nautilus Gear sculpture to control the power to the ATtiny.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I found a nice small package with both an N and a P MOSFET:  <a href="http://www.digikey.com/product-detail/en/IRF7105PBF/IRF7105PBF-ND/856574">http://www.digikey.com/product-detail/en/IRF7105PBF/IRF7105PBF-ND/856574</a><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Another approach is to disconnect the two ground wires of the two solenoids.  You essentially want to make your three terminal train switch into a four terminal device.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Straight, Gnd, Turn, Gnd.  You then use an N MOSFET on each Gnd terminal to energize that solenoid.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I am sure that you know that these solenoids are not designed to be turned on for long periods of time.  You just want to energize them long enough to switch the track.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>So, the software driving them should provide a pulse for half a second or so.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>---> Paul<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> TriEmbed [mailto:triembed-bounces@triembed.org] <b>On Behalf Of </b>Rick<br><b>Sent:</b> Thursday, June 26, 2014 7:57 PM<br><b>To:</b> triembed@triembed.org<br><b>Subject:</b> Re: [TriEmbed] MOSFETs or Relays<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'>Good catch Rodney,<br><br>Brian, unless you tie the solenoid ground (negative supply terminal) and the I/O port expander ground (again, negative supply terminal) together, you will have no reliable gate-source current path. As such, you won't be controlling the Mosfet.<br><br>If you absolutely need isolation between the two, you will need to provide  an optoisolator driven from the I/O port expander, PLUS a 5 volt isolated power supply to turn the Mosfet gate on.<br><br>If you measure the voltage between the gate and source of the Mosfet, you'll see a voltage, which will explain why the Mosfet is turning on.<br><br>Is there any reason you don't want to connect the two negative supply terminals together?<br><br>Regards,<br><br>Rick<br><br><br><br><o:p></o:p></p><div><p class=MsoNormal>On 6/26/2014 7:20 PM, Glen Smith wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p>Is the 12v supply ground and the pi ground tied together? If not you can see some wacky results with 2 power supplies floating relative to each other. <o:p></o:p></p><p>- Thumbed one letter at a time on a 2.25 x 1.25 inch Galaxy smartphone keyboard, please forgive any errors.<o:p></o:p></p><div><p class=MsoNormal>On Jun 26, 2014 5:12 PM, "Grawburg" <<a href="mailto:grawburg@myglnc.com">grawburg@myglnc.com</a>> wrote:<o:p></o:p></p><div><div><p class=MsoNormal>Rodney asked for more detail;<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><p class=MsoNormal>Attached is the single n-MOSFET circuit (it's from the project manual I'm creating).   <o:p></o:p></p><div><p class=MsoNormal>The MCP23017 is an I/O port expander between the devices and the Raspberry Pi. <o:p></o:p></p><div><p class=MsoNormal>Each MOSFET connects to a different output port.<o:p></o:p></p></div><div><p class=MsoNormal>The ground is the ground for the 12VDC, not the Pi.<o:p></o:p></p></div><div><p class=MsoNormal>I have not checked the output voltage from the chip; I will try putting a resistor in-line as suggested.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>Brian <o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal><a href="https://en.wikipedia.org/wiki/Arthur_Schopenhauer#cite_note-55" target="_blank"><br></a><o:p></o:p></p></div></div></div></div><p class=MsoNormal style='margin-bottom:12.0pt'><br>_______________________________________________<br>Triangle, NC Embedded Computing mailing list<br><a href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><br><a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org" target="_blank">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><br>TriEmbed web site: <a href="http://TriEmbed.org" target="_blank">http://TriEmbed.org</a><o:p></o:p></p></div><p class=MsoNormal><br><br><br><o:p></o:p></p><pre>_______________________________________________<o:p></o:p></pre><pre>Triangle, NC Embedded Computing mailing list<o:p></o:p></pre><pre><a href="mailto:TriEmbed@triembed.org">TriEmbed@triembed.org</a><o:p></o:p></pre><pre><a href="http://mail.triembed.org/mailman/listinfo/triembed_triembed.org">http://mail.triembed.org/mailman/listinfo/triembed_triembed.org</a><o:p></o:p></pre><pre>TriEmbed web site: <a href="http://TriEmbed.org">http://TriEmbed.org</a><o:p></o:p></pre></blockquote><p class=MsoNormal><o:p> </o:p></p></div></body></html>