Author Topic: Model Train 3-Light Signal  (Read 11747 times)

0 Members and 1 Guest are viewing this topic.

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Model Train 3-Light Signal
« on: July 06, 2016, 10:44:18 pm »
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 SN74HC139N

Transistors: Fairchild Semiconductors BC32725TA
« Last Edit: July 06, 2016, 10:49:40 pm by Phoxtane »
 

Offline ZeroStatic

  • Contributor
  • Posts: 29
Re: Model Train 3-Light Signal
« Reply #1 on: July 06, 2016, 11:21:09 pm »
Check your resistors, they're almost certainly not 100K if they're getting hot.
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #2 on: July 06, 2016, 11:45:47 pm »
Check your resistors, they're almost certainly not 100K if they're getting hot.

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

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #3 on: July 07, 2016, 12:34:22 am »
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.
« Last Edit: July 07, 2016, 12:50:56 am by MarkF »
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #4 on: July 08, 2016, 09:19:24 pm »
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.
I 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.
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #5 on: July 08, 2016, 10:35:32 pm »
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.
« Last Edit: July 08, 2016, 10:51:23 pm by MarkF »
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #6 on: July 09, 2016, 12:00:07 am »
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.

I'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?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #7 on: July 09, 2016, 12:26:35 am »
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?
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #8 on: July 09, 2016, 03:40:44 am »
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?

I'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!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #9 on: July 09, 2016, 05:11:30 am »
I'm planning on using 22/4 4 conductor cable from Home Depot Security 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.
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #10 on: July 10, 2016, 02:38:25 am »
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?
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #11 on: July 10, 2016, 04:35:34 am »
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.
« Last Edit: July 10, 2016, 04:38:29 am by MarkF »
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #12 on: July 17, 2016, 04:36:31 am »
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).
 

Offline alsetalokin4017

  • Super Contributor
  • ***
  • Posts: 2055
  • Country: us
Re: Model Train 3-Light Signal
« Reply #13 on: July 17, 2016, 06:05:25 am »
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.
The easiest person to fool is yourself. -- Richard Feynman
 

Offline Fungus

  • Super Contributor
  • ***
  • Posts: 16707
  • Country: 00
Re: Model Train 3-Light Signal
« Reply #14 on: July 17, 2016, 06:13:32 am »
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.

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


 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #15 on: July 17, 2016, 12:11:31 pm »
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.
 

Offline TomS_

  • Frequent Contributor
  • **
  • Posts: 835
  • Country: gb
Re: Model Train 3-Light Signal
« Reply #16 on: July 17, 2016, 06:39:46 pm »
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.

I 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.
« Last Edit: July 17, 2016, 06:41:40 pm by TomS_ »
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #17 on: July 17, 2016, 09:41:49 pm »
Wait...  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.

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.

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

 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #18 on: July 17, 2016, 11:34:41 pm »
Funny 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.

My 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.
« Last Edit: July 17, 2016, 11:50:44 pm by MarkF »
 

Offline rrinker

  • Super Contributor
  • ***
  • Posts: 2046
  • Country: us
Re: Model Train 3-Light Signal
« Reply #19 on: July 18, 2016, 11:23:41 pm »
 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.

 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #20 on: July 19, 2016, 12:36:37 am »
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.
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #21 on: July 19, 2016, 11:29:28 pm »
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_pcb
http://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.net
http://bricksafe.com/files/Phoxtane/automatic-lego-train-control-with-fpga/track_signal_board_v1.ses

Thanks for the help, folks!
 

Offline MarkF

  • Super Contributor
  • ***
  • Posts: 2551
  • Country: us
Re: Model Train 3-Light Signal
« Reply #22 on: July 20, 2016, 01:31:54 am »
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 from Silver 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.
« Last Edit: July 20, 2016, 01:33:52 am by MarkF »
 

Offline PhoxtaneTopic starter

  • Regular Contributor
  • *
  • Posts: 50
  • Country: us
Re: Model Train 3-Light Signal
« Reply #23 on: July 20, 2016, 03:23:02 am »
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!
 

Offline steaky1212

  • Regular Contributor
  • *
  • Posts: 95
  • Country: gb
    • Steaky - Sleep is overrated
Re: Model Train 3-Light Signal
« Reply #24 on: July 20, 2016, 03:10:44 pm »
However, before I commit to this design... did I do a decent job?

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


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf