Model Train 3-Light Signal - Page 1
Forum section: electronics / projects

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 06, 2016, 10:44:18 pm
content: I'm working on a project as something to do over the summer, and I'm at the point where I need someone more experienced than me to help put the finishing touches on the design!I'm working with a Basys 3 FPGA dev board (which I needed for a class last semester), as I really enjoy working with Verilog - as such, this circuit is intended to run at 3.3V because that's what the interfaces between the board and the outside world (what Digilent calls 'PMOD' connectors) run at. My goal is basically to achieve automatic control of signals for a train layout through the use of light sensors - but that's not the focus of this thread.Currently, my design looks something like this:http://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.pdf.The idea is that I take a two-bit signal from my controller, and send it through the 74HC139 (which is perfectly fine with running at 3.3V unlike the 74LS139) decoder chip in order to select one of three outputs - active low, in this case. Since the chip can't deal with the current from running the LEDs I've chosen, there's a common collector transistor setup on each LED in order to provide enough current to the LED. In the schematic, I'd connect three LEDs to each 1x6 connector, running wires up to the signal itself while hiding the controller somewhere under the layout.I only have one signal breadboarded out right now, but each decoder chip actually has two decoder units inside it.The nice thing about this breadboard power regulator is that I can switch between 5V and 3.3V at will - currently I have an Arduino Uno hooked up so that I could play with blinkenlights, so it's all running at 5V. I'll have to tweak each resistor value since the voltage drop is different across each LED and I'm actually overdriving the red one slightly, but for now the lights actually turn on and off properly! Except for one... this is where the problems show up.The Arduino loops through the four possible configurations of the input pins in order to test all four outputs. The red LED is both A0 and A1 low, yellow LED is A0 high and A1 low, green LED is A0 low and A1 high... and the last output, selected by A0 and A1 high, isn't actually connected to anything. That'll be my default 'safe' state when initializing the controller and such. However, switching to that output doesn't actually do anything - whatever LED was lit up last stays on for the duration of that block of code, and then the pattern continues as normal. As such, I can't actually turn off all LEDs at once!That's the big problem right now, but I was hoping to get some feedback on the decoupling capacitors, as well as some pullup resistors. The last resistors I had were 100k ohm resistors connected to VCC and attached to A0 and A1; at that point, I was driving the signal by hand by manually plugging those wires into the + and - rail on the breadboard. When I left them connected to the negative rail (leaving the red LED on), I burned myself on them because they were so hot.The weirdest thing is that selecting the 'off' output for the signal circuit worked just fine when I was plugging the wires by hand, but it doesn't work when doing it with the Arduino.EDIT: Before I forget, part numbers and such:74HC139: Texas Instruments SN74HC139NTransistors: Fairchild Semiconductors BC32725TA

author: ZeroStatic
author_rank: Contributor
timestamp: July 06, 2016, 11:21:09 pm
content: Check your resistors, they're almost certainly not 100K if they're getting hot.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 06, 2016, 11:45:47 pm
content: Quote from: ZeroStatic on July 06, 2016, 11:21:09 pmThey were 100k resistors. Maybe I was getting a shock off some of the pins on the power supply? Regardless, they're not there now since I don't really need pull-up resistors for testing.

author: MarkF
author_rank: Super Contributor
timestamp: July 07, 2016, 12:34:22 am
content: For open collector outputs from your Arduino, you want something that looks like this:For the SN74HC139N decoder, you should be able to drive a LED directly since it can sink 25mA. Just connect the LED through the appropriate resistor to Vcc to limit the LED current.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 08, 2016, 09:19:24 pm
content: Quote from: MarkF on July 07, 2016, 12:34:22 amI gave this a try, and it seems to work perfectly!However, I'm getting conflicting information - somebody I've been going back and forth with on this project is telling me I should stick to the transistor setup... They say that because the 25mA current rating is an absolute maximum, there's no guarantee that the chip will work properly unless I stay within the "+/- 4mA driving current at 5V" noted on the first page of the datasheet (http://www.ti.com/lit/ds/symlink/sn54hc139.pdf). I don't actually have the knowledge necessary to determine whether or not this is a good conclusion to make.Also, I'm still not sure how to set up my pullup/pulldown resistors for this circuit, or how to determine the value of my decoupling capacitors...I did see on various schematics that commonly, one connects both a .1uF and a 10uF capacitor across VCC and GND, and that seems to be suitable for most applications. I'm not entirely sure if I even need those in my circuit because there's no ouput back to the controller, only an input from it - hence, any split-second (microsecond?) glitches that occur won't even be noticeable by the human eye on the LEDs.

author: MarkF
author_rank: Super Contributor
timestamp: July 08, 2016, 10:35:32 pm
content: I assumed you're not driving the LEDs a the maximum current the 74hc139 can provide. I would think 15-20mA would be more than enough and you are only turning on one LED at a time. Running the 74hc139 at maximum will shorten the life of the part. If it doesn't get hot to the touch, I wouldn't worry about it.However, the circuit I posted should work also. Since the 74hc139 does NOT have open collector outputs, you can delete the 10k resistor and connect the Vcc to same voltage you're driving the 74hc139. If the LEDs don't turn completely off, put a diode in series with the transistor base to raise the base voltage.Note. On second thought, you can put the LED on the emitter and leave the current limit resistor on the collector so you wouldn't need the diode on the base.Note 2. I'm building a computer interface to my HO railroad.For me, I would use 0=All off, 1=green, 2=yellow and 3=red. I like to set zero everywhere as my default/reset state.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 09, 2016, 12:00:07 am
content: Quote from: MarkF on July 08, 2016, 10:35:32 pmI've actually got resistors set up that should limit the current to ~15mA or thereabouts. According to my vendor, the three colors I got have maximum current limits of 20mA, and forward voltages of 2.0, 2.1, and 2.2 volts (red, yellow, green). If anything, I actually want a bigger value of resistor on the green LED because it appears much brighter than the other two!I guess what you're saying is that it doesn't really matter which way I do it, so long as it's not over what the chip is rated for. Since it's not getting hot to the touch, or even noticeably warm, I'll stick with the simple way to do it - I will have to rig up some sort of long-term test to see if things will get hot if left running for days at a time, though.Another question: right now, everything is running at 3.3V because that's what the Basys 3 board's inputs and outputs operate at. I can always make use of a level translator for the logic signals, so would it be beneficial to bump my system up to a 5V supply?

author: MarkF
author_rank: Super Contributor
timestamp: July 09, 2016, 12:26:35 am
content: If it's working the way you want, I don't see any reason to add more complexity. I would only change the voltage to 5V if you want to drive it with something else besides the Arduino and the new MCU operates at 5V or you have a long cable length and the voltage drop is too big. Do you have a reason to change to 5V?

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 09, 2016, 03:40:44 am
content: Quote from: MarkF on July 09, 2016, 12:26:35 amI'll be running longish cables to reach the various points around the layout, so the voltage drop may be of concern. I should probably be sticking to copper-core ribbon cable, but that seems to be difficult to come by!

author: MarkF
author_rank: Super Contributor
timestamp: July 09, 2016, 05:11:30 am
content: I'm planning on using 22/4 4 conductor cable from Home DepotSecurity Cable. Try something like it for your longest run and see if the voltage drop is an issue. You're not drawing much current that would cause a large voltage drop.If you need more conductors, just use Cat-5 network cable.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 10, 2016, 02:38:25 am
content: I've already got some of the generic 24AWG 10-wire ribbon cable to use for connections, and some of the .1 crimp headers and a crimping tool to crimp them with.I think I'm ready to get going on designing a PCB! Given the space requirements I'm stuck with, I'd prefer to stick to SMD components where possible (even the headers I'll use for the connections). From what I can tell, for someone getting started in SMD soldering, SOIC chips and 1206-size components are the best to start with since they're relatively large.Problem is, I'm trying not to put out more money on tools, and a toaster oven hacked into a reflow oven is out of the question as a result. I actually do have one of those generic hot-air soldering rework stations - is this something I can use to do SMD parts? If so, what do I need to successfully solder SMD?

author: MarkF
author_rank: Super Contributor
timestamp: July 10, 2016, 04:35:34 am
content: I use a Hakko FX-888D soldering station with either a T18-C4 or T18-K tip. You can go to the Hakko web site and watch demonstration videos of using both tips for soldering SMD parts. At 60 my hands aren't as steady as they use to be and I end up with too much solder and just wick it off. Also, I use DipTrace to layout my PCBs.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 17, 2016, 04:36:31 am
content: I have some small-diameter solder and a flux pen on hand now, as well as one of those basic learn-to-solder-SMD kits - right now it's a matter of finding the time in order to tackle that project.It occurred to me just yesterday that if I end up producing the boards for the train signal for other people as well as myself, I may want to add in some sort of protection in order to prevent damage if the power supply is plugged in backwards. The current design I have does not have any sort of protection for reverse voltage, and given that the power connector is integrated with the control signals onto a 1x6 header, there's a good chance that even I could blow up a few boards by accident. As such, I'd like to add some diodes onto the VCC and GND connections in order to prevent a reverse voltage scenario. However, I need some clarification on how to go about choosing diodes for this application!From the bit of reading I've done on the subject, the specific application I'm describing here is 'polarity protection' - which doesn't seem to require any sort of special diode.As for the circuit, the operating voltage for any connection should reach a maximum of 3.3V, assuming the power system is attached to a surge protector of some sort, and the absolute maximum current that the circuit will draw is likely ~85mA***.From the various specifications I can choose from, it looks like I only really need to worry about the forward voltage (Vf), peak reverse voltage, as well as my max surge current and peak reverse current. I'm not terribly worried about the operating temperature range as the whole setup is designed for indoor use and shouldn't encounter a large temperature swing.As such, I'm thinking I should choose a diode where the Vf is fairly low (certainly lower than my supply voltage by a good amount), with a peak reverse voltage well above my supply voltage, and a surge current well above my maximum current draw. I'm not sure if I should worry about the reverse current at all.I'm thinking something with a typical .7 Vf, reverse voltage somewhere around 20V, and a surge current of 150mA max (to avoid running near the peak surge current under any circumstance). For those with more experience, does this result sound about right?***In my testing, floating inputs to the decoder would often result in two of the three LEDs being left on - this number is derived from the maximum current rating of the LEDs, times four for the worst-case scenario of floating inputs to both decoder units, with a 5mA current draw attributed to the decoder IC itself (overrated significantly from the ~80uA specified on the datasheet, but may as well be safe).

author: alsetalokin4017
author_rank: Super Contributor
timestamp: July 17, 2016, 06:05:25 am
content: I'm sorry if this is out of line... but I just have to ask.Why make a simple project more complicated than it has to be? Why not just use the Arduino for everything? It's already built, all you have to do is provide it with a power supply and write the simple code. It can handle the optical sensing and control all six LEDs for both signals, with minimal extra circuitry. It's easy to change programming when that becomes necessary. Most of the problems you have talked about would be eliminated. If you are trying for minimal cost, use a 3-dollar Chinese Arduino clone Pro-Mini or Nano.Yes, just use a Schottky diode for your reverse voltage protection.

author: Fungus
author_rank: Super Contributor
timestamp: July 17, 2016, 06:13:32 am
content: Quote from: Phoxtane on July 06, 2016, 10:44:18 pmWait... you're using an Arduino to produce test signals for a massively over-complicated way of lighting up 3 LEDs.Why not just use an Arduino? An Arduino pin can provide enough current for a LED. You can get tiny Arduinos for $2 each.

author: MarkF
author_rank: Super Contributor
timestamp: July 17, 2016, 12:11:31 pm
content: I believe you're missing the big picture. The 3 LEDs would be for one of many signals around a model railroad layout. My layout has the capability for 30 lights and that does NOT include turnout switching and locomotive power.Here's a PCB I just had made for the Tortoise Slow Motion switch machine for turnouts.

author: TomS_
author_rank: Frequent Contributor
timestamp: July 17, 2016, 06:39:46 pm
content: Quote from: MarkF on July 08, 2016, 10:35:32 pmI would probably go for a more realistic kind of "fail safe" scheme and use 0 = red. If for some reason the control inputs are broken, the signal will change to red as it would be unable to determine what else it should be displaying. But thats just me.But then a blank aspect should also be considered danger and shouldnt be passed. So six/half a dozen I guess.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 17, 2016, 09:41:49 pm
content: Quote from: Fungus on July 17, 2016, 06:13:32 amQuote from: alsetalokin4017 on July 17, 2016, 06:05:25 amFunny that both of you mention this - I actually bought a five-pack of clone Arduino Nanos as disposable units for test rigs and smaller projects. I could easily use an Arduino or five to control the project, but for the number of signals I intend to build, I'd have to gang multiple Arduinos together. This board I'm designing will control two three light (aspect?) signals, which will be facing in opposite directions down the track. Each board controls the signalling for only one 'block' at a time, and as my layout expands, I'll be wanting more and more of them. MarkF has the right idea in that the scale of the project is too big for a single Arduino to handle.The nice thing about this board is that it reduces the number of connections required for each set of signals by 33% (from six connections to four). Even with the Basys 3's numerous pins, I may eventually want more connections... but this will help me cram more functionality into a single controller!I'm also treating this as a learning project; I'm hoping it helps prepare me for classes in the future - and if anything it'll help keep my Verilog skills sharp.

author: MarkF
author_rank: Super Contributor
timestamp: July 17, 2016, 11:34:41 pm
content: Quote from: Phoxtane on July 17, 2016, 09:41:49 pmMy HO railroad design consists of one DLP-2232PB-G USB module with a pic16f877a MCU from DLP Designs (i.e. your Arduino). The DLP module interfaces with additional MCUs to produce modified PWM power to 30 track blocks, 45 digital/relay/LED drivers and 45 digital/sensor inputs. In total, that is 7 5"x5" PCBs. That's to control a 8'x8' HO layout.

author: rrinker
author_rank: Super Contributor
timestamp: July 18, 2016, 11:23:41 pm
content: Stay tuned as I get started on my railroad projects. My design so far will have multiple Arduinos (mostly Nanos) for each 'control point' on the layout communicating to a central computer via an RS-485 bus. Each node will handle the detection and turnout motors (I'm using RC servers - WAY cheaper than Tortoises, and since I am using Arduinos and they can do PWM servo drive....) as well as signals. Perhaps some local processing, so the central computer (for now - one of these days I hope to build a 'real' CTC panel) will only have to tell each control point which direction the dispatcher has cleared a train, and it can set up the signals and points as needed. For complex locations I can either use a Megas, or make the code more complex and use some shift registers to multiply the available outputs. For my relatively modest (about 20x20 working area (in feet), eventually double deck design, I calculated about 30-35 control points, but I don't even have a track plan finalized yet. Finally got rid of an old car so I now have room in the garage to move all the basement junk out and start working on getting the walls and floor all redone.

author: MarkF
author_rank: Super Contributor
timestamp: July 19, 2016, 12:36:37 am
content: I'm designing RF hand controllers to select predefined track blocks and control speed and direction. The RF is being done with the nRF24L01 modules which would allow up to 5 operators on the layout. Each controller has a nRF24L01, pic18f2550, 1.27" OLED display and a rotary encoder with switch.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 19, 2016, 11:29:28 pm
content: I've routed the board successfully:However, before I commit to this design... did I do a decent job? I figured that I should lay out the connectors first, then the IC, and then the various passives that sit between them. I'm also aiming for a very specific board size here, so I can't really change that too much.Also, the DRC check comes up clear, but I want to make doubly sure that this board follows the specifications laid out by OSH Park in their 2-layer prototyping service:http://docs.oshpark.com/services/two-layer/If anyone would like to take a closer look at the design, I'll link in the various KiCad files (.kicad_pcb, .ses, .net - do I need more?) below for inspection and critique.http://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.kicad_pcbhttp://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.nethttp://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.sesThanks for the help, folks!

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2016, 01:31:54 am
content: You need to check your top silk layer. Half of the labels run off the board.The layout seems awful tight. You may have a hard time mounting all the parts.I just ordered several different boards fromSilver Circuits. It took 2 weeks to get the boards. Also, the order was for their minimum of 4 boards. They actually sent me 5 of each. Also, they accept directly from some PCB layout program. Diptrace being one they accept. I didn't need to fool around with creating Gerber files. The boards look good and I'm waiting on some parts now.I use Diptrace. So, I can't really go deeper into your design layout.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 20, 2016, 03:23:02 am
content: Since my last post I've added in some mounting holes and rounded off the corners as well. From what I've read since then, it looks like silkscreen labels off the edge of the board don't actually matter - however, I've made some of the labels invisible and have sent an email to OSH Park to see if it actually does matter.I also keep going back and re-working the traces to avoid any right-angle corners if possible - I even managed to eliminate a few vias as well!

author: steaky1212
author_rank: Regular Contributor
timestamp: July 20, 2016, 03:10:44 pm
content: Quote from: Phoxtane on July 19, 2016, 11:29:28 pmMake the tracks thicker. They may not need higher current capability but it makes it easier to add bodge wires and it makes is easier to etch.Remove all acute (less than 90deg) angles as these cause acid traps.

author: MarkF
author_rank: Super Contributor
timestamp: July 20, 2016, 03:34:45 pm
content: Quote from: Phoxtane on July 20, 2016, 03:23:02 amWhat's the point of putting labels on the silk layer if they're just going to be cut off? Don't you want to be able to read the text you went to all the trouble to put them on the PCB? It just looks unprofessional to me.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 20, 2016, 07:22:42 pm
content: Quote from: MarkF on July 20, 2016, 03:34:45 pmMost of the large labels you can see are on the 'F.Fab' layer, which isn't used by OSH Park. The only labels that will get cut off are the ones for the 1x6 headers, but I'm not entirely sure how to go about editing the label so this doesn't happen - however, I'm okay with them getting cut off as it was very helpful making sure everything was aligned properly.I think I'm ready to generate gerber files and send them off for fabrication! The rectangular board size is 24x32mm, which ends up being about 1.19 square inches - which, at the rate of $5/square inch I'm getting should be $5.95, or just under $2 per PCB. Not bad at all!Quote from: steaky1212 on July 20, 2016, 03:10:44 pmI'm going to leave the trace width as-is for now. Future me can deal with bodge wires if necessaryEverything in gray here is on the F.Fab layer that's currently unused.And again without the silkscreen layers but with copper fills!

author: steaky1212
author_rank: Regular Contributor
timestamp: July 21, 2016, 09:05:14 am
content: I don't know if the mounting holes are going to be big enough, but then I don't know how you're mounting it.I really like this resource -https://blogs.mentor.com/tom-hausherr/blog/2011/03/18/pcb-design-perfection-starts-in-the-cad-library-part-13/- and I use it whenever I put mounting holes on a PCB.

author: Phoxtane
author_rank: Regular Contributor
timestamp: July 22, 2016, 05:49:47 am
content: I went ahead and increased the board size somewhat to a 32 by 32mm square; this gave me room to add some much-needed labels, as well as a slightly less cramped layout that should be easier to solder.I've also put the feelers out to see if people are interested in buying this little gadget. I suppose it's time to show off the part of my layout I have completed!I'm doing the whole thing in Lego - I'm a huge nerd. It can split apart into pieces for easier transport. There's an empty space under the track that I'm planning to use as a conduit for running the cables for the signals and other sensors that will help run the layout.

author: Phoxtane
author_rank: Regular Contributor
timestamp: August 03, 2016, 02:45:43 am
content: I came home from work yesterday to discover that the first version of the PCBs for this project had arrived!I can't actually use these boards for testing purposes, as when I assigned footprints to each component in KiCad, I assigned the wide version of the SOIC-16 (~8mm) footprint as opposed to the normal SOIC-16 (~4mm) footprint. As such, it's far too wide for me to actually solder the chips I have on hand to, and I'm not about to attempt bodge wires either...I also did a high-resolution scan of the PCBs on our scanner, just so I could inspect them properly. I'll link in the high-resolution image, as well as embed a forum-friendly preview.http://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/EPSON001.JPGAs you can see, there's not much in the way of labels - if I didn't have the schematic on hand, I'd have a very difficult time figuring out what wire connects to what pin. Thankfully, board version 2 solves these problems, and board version 2.1 improves upon board version 2. Correcting the footprint issue freed up some space for better label placement, and I made use of the empty back side of the board to add some design information and a graphic.I've also made the decision to run this board off of 5V exclusively; it's more common and will make it much easier to interface with the devices I'm using.I haven't done the cost calculations yet, but I suspect the board will actually remain at around the same price as before, even with its larger size, since now it only uses one value of resistor throughout the design due to increasing the supply voltage.

author: rstofer
author_rank: Super Contributor
timestamp: August 03, 2016, 02:56:12 pm
content: Quote from: MarkF on July 09, 2016, 05:11:30 am22 AWG solid wire has a resistance of 16 Ohms per THOUSAND feet. The LED already has a 200 Ohm resistor (depending on operating voltage) so how much difference would 16 Ohms make if you used 500 feet one way? In fact, the wire resistance is lost in the tolerance of the resistor. This assumes that the controller is on one end of the wire and the LEDs on the other.http://www.okonite.com/engineering/dc-resistance.html

author: steaky1212
author_rank: Regular Contributor
timestamp: August 25, 2016, 08:51:01 am
content: I'd still be concerned that you are going to chew through a track as it looks very close to the mounting hole (LED3 to R3) - screw heads and washers are bigger than you think.Nylon/fiber washers and countersunk screws will "help", but really this should be designed out.

author: Phoxtane
author_rank: Regular Contributor
timestamp: August 25, 2016, 04:05:55 pm
content: Quote from: steaky1212 on August 25, 2016, 08:51:01 amFair point. I'll probably be doing yet another board respin since it turns out the SMD diodes I have are a right pain to solder by hand - probably to a through-hole part.One last question - since the voltage drop through a generic Schottky diode is ~.7V, that means the voltage presented to the rest of the circuit is 4.3V - which is the 'source' voltage I should use when calculating the resistor value for the LEDs, rather than 5V, correct?