Recent

Author Topic: NMRA DCC train control project.  (Read 20200 times)

MrJohn

  • New Member
  • *
  • Posts: 23
NMRA DCC train control project.
« on: April 26, 2014, 11:21:38 pm »
Hi,  'Search' did not find anything on NMRA (National Model Railroad Assocation (?)) DCC (Digital command and control (?)) for model railroads.  This is a protocol for controlling multiple trains on the one track/layout by encoding control signals on to the track power.

The protocol involves a fairly tight requirement for 58 micro second length pulses and a much more relaxed requirement for longer pulses.

I want to develop for  i386 type computers with a motherboard or ISA board serial port.  I will use EpicTimer for the critical timings.

My question is will Ubuntu/Free Pascal/Lazarus allow me to directly manipulate the UART registers using the inline assembler?

Thanks.
« Last Edit: April 26, 2014, 11:30:25 pm by MrJohn »

Rails

  • Guest
Re: NMRA DCC train control project.
« Reply #1 on: April 26, 2014, 11:43:08 pm »
OK, you are proposing to use a serial port UART to encode a DCC signal, then do what with it? I'm not being a smart ass here. I am genuinely curious as to how you intend to modulate the track power.

Since fpc/laz has serial port programs out there, I would assume peeking at their source code should be helpful.

 

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: NMRA DCC train control project.
« Reply #2 on: April 27, 2014, 02:06:42 am »
You are describing "pwm" or pulse width modulation. The best all around solution is to program a micro controller (Arduino etc) to handle all the switching/sensing/pulsing. Set it up as a UDP receiver/sender and you can easily create whatever client side control apps you want .The only issue , it seems, is that you have to boost the 5v pulse signal of the PWM to 12v for the DCC. This way you don't need a dedicated machine. Plus add in an old wifi router and you can even write an interface for Android etc.


http://www.oscale.net/en/simpledcc

Check out PascalScada too. It is for industrial controls which just might be the actual protocol used by modern day train systems.

MrJohn

  • New Member
  • *
  • Posts: 23
Re: NMRA DCC train control project.
« Reply #3 on: April 27, 2014, 02:13:01 am »
Rails,  one H-bridge chip driven by the +/- 12V from the modem control lines is what I have in mind.  Perhaps you are familiar with DCC? 

Of course that is one h-bridge plus a DC supply to provide the necessary grunt as obviously the 10mA from the RS232 port cannot drive a train, what the DCC people call a 'power station'.

BTW, I have experimented with encoding the DCC data into .wav files then  wave shaping the output of a sound card to drive the H-bridge  which does actually work but not 100%, for various reasons.

The fpc and Lazarus source I have seen does not directly access the com port registers which I would like to do as 58micro seconds is a rather short period of time.
« Last Edit: April 27, 2014, 02:22:18 am by MrJohn »

MrJohn

  • New Member
  • *
  • Posts: 23
Re: NMRA DCC train control project.
« Reply #4 on: April 27, 2014, 02:17:17 am »
CaptBill, no not pwm.  This is binary data encoding the track supply to control multiple addressable trains.

Yes, Arduino et al is a valid way to go but I want to be able to offer software that requires the minimum hardware to run the train layout.

Of course going to the model railroad shop and spending $$$ on a fully featured DCC controller and 'power station' is another valid way to go.

MrJohn

  • New Member
  • *
  • Posts: 23
Re: NMRA DCC train control project.
« Reply #5 on: April 27, 2014, 02:31:31 am »
I think I may have found my answer in IOPerm but now I need to buy a uart card for my development PC!

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: NMRA DCC train control project.
« Reply #6 on: April 27, 2014, 08:40:39 am »
CaptBill, no not pwm.  This is binary data encoding the track supply to control multiple addressable trains.

Yes, Arduino et al is a valid way to go but I want to be able to offer software that requires the minimum hardware to run the train layout.

Of course going to the model railroad shop and spending $$$ on a fully featured DCC controller and 'power station' is another valid way to go.

I am clueless about model trains btw. Haha. Just find the automation neat.Looking a little closer I see what you mean. It is sending a timed signal embedded into a PWM signal? Either way, a micro controller is gonna be the cheapest and the most powerful system. Look at the fancy 'DCC USB' setups. Open the hood and you have a micro controller based solution going on.

Is it an authenticity thing that it needs to control trains with this approach? Also seems like you can only move one train at a time this way. Seems like controlling the trains over a wifi connection would be the way to go. Pull the main power off the track, control the throttle/direction/brakes from a small on board micro controller and wireless transceiver.

This right here looks to be just that, a router + and a micro controller programmed with the DCC protocol and a udp network based front end side.
http://www.ebay.com/itm/Roco-Fleischmann-New-Wi-Fi-Digital-DCC-Controller-Set-z21-HO-00-N-/181390005103?pt=UK_Trains_Railway_Models&hash=item2a3bafd36f

MrJohn

  • New Member
  • *
  • Posts: 23
Re: NMRA DCC train control project.
« Reply #7 on: April 27, 2014, 09:12:13 am »
CaptBill, the beauty of DCC is that the trains (plural) take their power and their control instructions from the track.

The tracks carry AC at some low voltage,  may 9 to 20 volts depending on what the trains require.

But the AC is not plain AC, it is frequency shift modulated to carry the data and every train has a decoder chip that responds to the data packets that carry the address of that train.

A simple DCC decoder chip will control motor speed and direction, lighting and other functions such as whistle/bell/horn and other audio sound effects.

Multiple trains can run on the same track and under individual control.  Reverse means reverse and forward means forward no matter which way the locomotive is facing on the tracks.

Track power can also drive layout devices such as level crossing bells and arms and track switches/points.

Train decoder chips are, moderately, cheap and I certainly do not contemplate developing hardware for inclusion in each train.

Yes, there are many and varied nice toys I can buy for control of my DCC layout but this is a hobby which for me is more than just buying stuff.  I would rather spend the money on a holiday with my wife.
« Last Edit: April 27, 2014, 09:19:56 am by MrJohn »

CaptBill

  • Sr. Member
  • ****
  • Posts: 435
Re: NMRA DCC train control project.
« Reply #8 on: April 27, 2014, 10:30:12 am »
Neat stuff. I see there is a strong support for the DCC support to remain. Either way, a micro controller is good at handling real-time serial data. Much easier to do the timing critical stuff involved with serial programming on small micros.  You want to avoid having to set up a real-time kernel if at all necessary. Save yourself a lot of hassle. Stuff like this should be fun.

Of coarse, ideally you want to program the micro in Pascal, of coarse.

Laksen

  • Hero Member
  • *****
  • Posts: 802
    • J-Software
Re: NMRA DCC train control project.
« Reply #9 on: April 27, 2014, 10:33:33 am »
Rule of thumb is that you can't get anything below 1 millisecond precision on a modern operating system not running some realtime scheduler. Doesn't matter what language you do it in. You'll need very low level access or to write a DOS/embedded implementation

MrJohn

  • New Member
  • *
  • Posts: 23
Re: NMRA DCC train control project.
« Reply #10 on: April 27, 2014, 11:54:24 am »
Laksen, the plan is to use EpikTimer and write directly to the modem control line register in the UART if the operating system allows it.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12715
  • FPC developer.
Re: NMRA DCC train control project.
« Reply #11 on: April 27, 2014, 12:40:27 pm »
Laksen, the plan is to use EpikTimer and write directly to the modem control line register in the UART if the operating system allows it.

Epiktimer still lives by the grace of the scheduler. Even if you manage it, it won't be software that is easy to deploy, specially since hardware serial ports are getting rare too.

Rails

  • Guest
Re: NMRA DCC train control project.
« Reply #12 on: April 27, 2014, 03:41:49 pm »


Epiktimer still lives by the grace of the scheduler. Even if you manage it, it won't be software that is easy to deploy, specially since hardware serial ports are getting rare too.

What does "grace of the scheduler" mean. I know I should know that, but my head keeps coming up empty. <wife nods knowingly>  ::)

The last couple of motherboards I bought had serial ports. No appearances on the back panel, but there were pins on the board that could be brought out. I was pleasantly surprised to find them still there.

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: NMRA DCC train control project.
« Reply #13 on: April 27, 2014, 04:19:22 pm »
I'm not a Linux user, so be warned.

While everyone tried to convince you that it is not possible and not cost effective without a micro controller, which might be true, I have the opposite "feeling". You mentioned Ubuntu in your first post, maybe you should take a look at this. Might not be that easy though.

Rails

  • Guest
Re: NMRA DCC train control project.
« Reply #14 on: April 27, 2014, 04:50:39 pm »

 

TinyPortal © 2005-2018