Skip to main content

Hello,

===================

Abstract of this post

===================

In this post we share some useful FPGA utilities for capturing the DCS signal off tracks for all kinds of projects. There are some interesting things you can do with this, like make non-train things respond to train commands or have parts of the layout react on certain conditions (like something only happens if the train is a certain speed when it passes by... or only happens if the train's lights are on) or other creative stuff.  The .v code in this example simply flashes out what was captured, but you can certainly modify it to do all kinds of great stuff with a few simple comparison statements.

if (captured_packet == some_train_condition)

{

 (do something cool)

}

Also, if you're more ambitious, this would be the first step to spoofing the DCS (what I'm working on this month). Step 1 is to capture all the commands needed with this tool. Then step 2 is to have the FPGA just play them back whenever you need (simple modification to this code**). Then you can have the train react to the layout (sensors and blocks and such), like have it auto slow down at stations, auto ring the bell in the yard, auto blow the horn at level crossings... use your imagination!  For me I want an auto-slow down function at tight curves because sometimes I get distracted and loose track of my train. This post is just equipping everyone with a framework for completing the capture process. This is not a finished product. The idea is you can build on what's here to get you started.

**DISCLAIMER: Well the code is a simple modification, but you need an output driver circuit. That's coming soon - I have it built but not tested yet. I prefer to test before I post so I don't steer anyone wrong!

============================================================

Interfacing DCS with other Hobby (and non-hobby) electronics

============================================================

Step 1 of anything you'd want to do is to take the DCS format which is a weird ~10V polar signalling format... and superimposed on the track power, and turn it back into normal, circuit readable TTL or LVCMOS signal (5V or 3.3V and not negative!). Here's a cheap handy circuit to accomplish that:

DCS_schematic

This brings it into a signal format that will work with basically anything... arduino, pic (go microchip go?), or for more hardcore digital designers... FPGAs and even ASICs (yay chip?).

Relatively straight forward, a 4-th order HPF up front strips the DCS packet off the AC 60 Hz voltage, then we divide by 2 with the two resistors to get the voltage scaling in the right range.

For the EE students it will be:

1/[(S+A)(S+A)(S+A)(S+A)]   so 4 poles and 80dB per decade, maximal flat pass band.

Anyways, we then use a CMOS logic chip (I used the 7404 hex inverter, but you can use whatever you want 7400, 7432... as long as the logic function is propagating transitions) to do some thresholding. It's always better to use a CMOS series (HCT, HC, CD, ..) and avoid the LS bipolar stuff when doing comparator work. FETs don't impose a voltage on their gate the same way BJTs force the base voltage to be [vt]ln(Ic) so they are better at uncoupling input and output. In this case we're actually giving the CMOS gate a below-the-rail voltage, but since these old 74xx things have the DNW on the input devices in the chip, it won't latch up so you can get away with that. Anyways the result is a happy 5V or 3.3V squarewave that can go directly into whatever digital part you want.

 

 

============================================================

microcontroller vs FPGA?

============================================================

I had thoughts about doing this on a microcontroller, but eventually ended up going with a cheap FPGA. (actually inside the TIU it's an FPGA... a xilinx spartan). The challenging part about doing this type of capture on a microcontroller is that most of them are not fast enough. Most low-cost available ones are under 25 MHz clocking.

Think about it:

Simply capturing the packet means reading a bit, storing it in an array captured_data[ctr], then increment the index  ctr=ctr+1; (ctr++ for c folks). That's best case 4 clock cycles (write the ASM out and think about it!), but you need 7.5 MHz so you're already toast. You probably need to put timeout and exit conditions in your loop too, so that gives the user a shortage of many cycles when all added up (Yes, I'm quoting tron... (c) Disney 1982... please don't sue me?).

Faster ARM cores can do it, but now it's expensive, needs 10W of power, and you need to worry about thread scheduling to make sure you're taking realtime (evenly spaced) samples.

Given this long list of concerns, I vote to give up and just go with the FPGA. I have a nice Kintex-7 at work, but that's not necessary, the Artix-7 is perfectly fine, 64K slices of logic at up to 100 MHz, (we need 7.5 MHz). Also its only like $100 and comes with vivado HL for free. It has some limitations but hey... you've only got 64K gates anyways so who cares?

 

So once you got the handy format converter you can just plunk the FPGA there like so:

Setup

I'm lazy and don't like soldering, so I bread-boarded it. The only tricky part is you need a precision clock, you can either go with a signal generator/synthesizer like me, or you can go with a crystal. A good trimmed crystal at 7.5 MHz will cost you about $30 these days (unless you order 10000), while this signal generator I bought for home was $90 with shipping, and not restricted to only 7.5 MHz. Actually it goes up to 24 MHz, and seems 10-20 PPM good ( I checked it on an E8565). Here's a link if anyone is in the market for a good cheap sig-gen [sig gen]. 

=============

RTL Code

=============

Right so last step is the RTL code.

Its brain dead. Basically you reset your counters, wait for the first 1 to show up and stream everything into the shift register after that. In my sample code I stream out the values to an LED with a return-to-zero (RZ) format so you can see the breaks between repeating values. The stream out just has a clock divider in my case so the LEDs aren't blinking at 1/7.5 MHz  (133ns).

 

Okay so I attached the RTL code for the FPGA to the post becasue it's too long to put inline. Also attached is the XDC constraints for vivado HL for synthesis/implementation. The specific board I'm using for the Artix-7 is the digilent ARTY one. It's pretty typical... $100.... has a prom (so it can keep it's programming after you turn it off) and it's got a JTAG-to-USB on the board so you don't have to get reamed on buying a programmer. Here it is [ARTY]. I'd recommend this for anyone who has digital circuit hobbies. Anyways, the XDC file has the pinouts already mapped so you can just change it to whatever FPGA you'd want to use it with.

 

=============

DEMO

=============

Finally here is a demo video showing the demo program. If you are trying to use the code/setup, I strongly recommend you duplicate this exact behavior first, and then modify after (since the existing setup is known good).

 

Happy DCS capturing!

 

~Adrian JT

Attachments

Images (2)
  • DCS_schematic
  • Setup
Videos (1)
DCS_capture
Files (2)
Last edited by Adrian!
Original Post

Replies sorted oldest to newest

gunrunnerjohn posted:

I have that same signal generator on my bench, so far, so good.

When you pick it up it's so light compared to other bench instruments... it feels like an empty box almost. The knobs are a bit soft and overall it's got a real mickey mouse feeling to it.

However, the signal coming out is actually pretty good though, and that's all I care.. so no complaints here either, not for $90...

Last edited by Adrian!
Adrian! posted:

...

Also, if you're more ambitious, this would be the first step to spoofing the DCS (what I'm working on this month). Step 1 is to capture all the commands needed with this tool. Then step 2 is to have the FPGA just play them back whenever you need (simple modification to this code**). Then you can have the train react to the layout (sensors and blocks and such), like have it auto slow down at stations, auto ring the bell in the yard, auto blow the horn at level crossings... use your imagination!  For me I want an auto-slow down function at tight curves because sometimes I get distracted and loose track of my train. This post is just equipping everyone with a framework for completing the capture process. This is not a finished product. The idea is you can build on what's here to get you started.

...

Happy DCS capturing!

~Adrian JT

Adrian,

Wow, Thanks for sharing this "Step 1".  Great stuff !

I agree that "Step 2" will be fuel for imagination...

Congratulations for the work completed to date.

Daniel

Add Reply

Post
The DCS Forum is sponsored by
×
×
×
×
Link copied to your clipboard.
×
×