Maarten M
Posts: 4
Joined: Mon Apr 06, 2015 9:05 pm

Gertbot as DCC Programmer?

Mon Apr 06, 2015 9:39 pm

I am trying to use the DCC mode and a sequence of commands to create a DCC programmer. I have not had any success so far. I can use the Gertbot as DCC controller without any problems.
Using the DCC standard for service mode I tried to change a DCC address using a sequence of DCC reset messages followed by direct write Address messages. The DCC decoder has not acknowledged any of my programming attempts. I have set a long pre-amble (20-bits) and a single message repeat. Based on the number of bits transmitted and the default Gertbot Baudrate, I should easily be able to meet the 20ms between messages requirement stated in the DCC programming standard.

How fast does the Gertbot send out the messages? The DCC service mode standard requires maximum 20ms between the reset message and the programming command.
What does the Gertbot transmit between messages? 0's, 1's or random bits?
How does the Gertbot queue up the DCC messages?

Kind regards,
Maarten M

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Tue Apr 07, 2015 8:09 pm

Maarten M wrote:I am ..The DCC decoder has not acknowledged any of my programming attempts.
The Gertbot I/O section has no way to read responses. How do you know you are not getting any?
How fast does the Gertbot send out the messages? The DCC service mode standard requires maximum 20ms between the reset message and the programming command.

Hummm, I did not know about that rule. At the moment reset messages are treated like all normal messages. It always send one idle packet after a command to guarantee the 5ms between same address rule.
What does the Gertbot transmit between messages? 0's, 1's or random bits?

It sends idle packets. This can be disabled by setting the bit 0 of the 'flags' in the DCC command. (This is in the manual section 6.2)
The option to set that bit is NOT in the GUI. (But is very useful if you try to trigger the output signal on a scope....)
In contrast to some commercial DCC controllers it does not repeat the last set of N 'speed' commands over-and-over.
It is an option I have been thinking about but then decided to leave it up to the Pi to implement that
How does the Gertbot queue up the DCC messages?

It has an internal DCC queue of 128 bytes per output channel. A message is put in the queue when it arrives from the PI.
It is taken from the queue after its has been sent <repeat> times.
If messages are arriving faster then it can send, it discards whole arriving DCC messages to make sure
the internal queue does not contain corrupted patterns.

As mentioned elsewhere I am working on a new SW release but I have NO LONGER ACCESS to ANY DCC material to test changes.

Maarten M
Posts: 4
Joined: Mon Apr 06, 2015 9:05 pm

Re: Gertbot as DCC Programmer?

Wed Apr 08, 2015 12:00 pm

Gert van Loo wrote:
Maarten M wrote:I am ..The DCC decoder has not acknowledged any of my programming attempts.
The Gertbot I/O section has no way to read responses. How do you know you are not getting any?
I try to change the Address (CV1) and afterwards verify the decoder still repsonds to command addressed to the original or new address. I will expand the system in the future to actively measure the acknowledge of the decoder.
The DCC service mode standard requires maximum 20ms between the reset message and the subsequent programming command.

Hummm, I did not know about that rule. At the moment reset messages are treated like all normal messages. It always send one idle packet after a command to guarantee the 5ms between same address rule.
The full set of standards making up DCC can be found here: http://www.nmra.org/index-nmra-standard ... -practices

I suspect the idle message between reset and programming command is stopping it working. I will try setting the flag bit 0 you mentioned.
As mentioned elsewhere I am working on a new SW release but I have NO LONGER ACCESS to ANY DCC material to test changes.
I have just started a DCC train project, and am happy to test.

Many thanks for your quick reply,
Maarten M

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Wed Apr 08, 2015 1:40 pm

I suspect the idle message between reset and programming command is stopping it working.
Setting the flag only suppresses FURTHER idle messages.Thus you always get one.
I will have to make a new image. I can do that in the next two days and send it to you separately.
If you want that, send me a pm and we can exchange email addresses.

[edit} : according to the standard the idle messages should not give a problem as it says
that certain addresses are not allowed for 20 ms.

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Sun Apr 26, 2015 10:32 pm

A new SW version is out 2.6
Maarten tested a pre-release and he told me it has fixed his programming issues.

heuristicjohn
Posts: 39
Joined: Thu Jan 31, 2013 11:55 pm

Re: Gertbot as DCC Programmer?

Tue Jul 21, 2015 11:44 am

I am currently successfully controlling a DCC train setup via Gertbot (Thanks, Gert !), but find I cannot program the decoder. I have read the previous posts (which mention the same problem), and am using the Gertbot GUI v2.6, to talk to a Bachmann 56-522 decoder, and monitoring the data on a Picoscope.
From the DCC spec S-9.2.1 p8, I understood that if I sent the message 03EC0002 twice, this should alter the CV1 address from 03 to 02. But it doesn't. Obviously I have misunderstood something. Help please, anyone ?

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Tue Jul 21, 2015 12:16 pm

The idle flags are still a bit of a mystery.
The way I read the DCC standard the programming should work even with idle flags.
Practice seems to contradict me.
Because of this I have not yet changed the idle flag in the python drivers.

This is the current code:

Code: Select all

#
# DCC configure
# This routine does NOT support the 'no idle' flag
#
# preamble and repeat are set per board, not per channel
# dc is not very well supported and the  use is generaly discouraged
#
# 19-Oct-2014 : This function is NOT tested!
# 
def dcc_config(board,channel,repeat,preamble,dc) :
   #GB_CHECK(board>=0  && board<=3,   "dcc_config illegal board\n")
   #GB_CHECK(channel>=0 && channel<=3,"dcc_config illegal channel\n")
   #GB_CHECK(repeat>=4 && repeat<=255,"dcc_config illegal repeat\n")
   #GB_CHECK(preamble>=14 && preamble<=255,"dcc_config illegal preamble\n")
   #GB_CHECK(dc>=-100 && dc<=100,"dcc_config illegal dc\n")
   id = board<<2 | channel
   no_idle = 0 # set to 1 only for testing, debug & development 
   wrtbuf = [PRE, CMD_DCC_CONFIG, id, repeat, preamble, dc, no_idle, POST ]
   os.write(filehandle,bytes(wrtbuf))
 
To get programming to work try switching the 'no_idle' mode on:

Code: Select all

   id = board<<2 | channel
   no_idle = 1 # <<<<<<<<<<<<< 
   wrtbuf = [PRE, CMD_DCC_CONFIG, id, repeat, preamble, dc, no_idle, POST ]

heuristicjohn
Posts: 39
Joined: Thu Jan 31, 2013 11:55 pm

Re: Gertbot as DCC Programmer?

Sun Jul 26, 2015 4:01 pm

Thanks for your reply. After some floundering, I have realised that I should use your python3 program test_drivers.py to send messages via gertbot.py to the gertbot board, and that altering the no_idle value in gertbot.py from 0 to 1 does indeed turn off the idle flags.
However, with either value I am still unable to alter the CV1 address in my decoder by sending 03EC0002 twice.
I believe I have the correct message format, because I can e.g. alter the value set in CV52 ('dim' output of function 1 in my decoder) from its preset value of 64 to new value 128, by sending 03EC3380.
Obviously the system is working well, and this may not be the right forum to discuss problems in implementing the DCC specifications, but where else to look ? Any suggestions welcome !

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Fri Jul 31, 2015 2:26 pm

What DCC controller (receiver) are you using?
Maybe I can get some information from the manufacturer.

heuristicjohn
Posts: 39
Joined: Thu Jan 31, 2013 11:55 pm

Re: Gertbot as DCC Programmer?

Fri Jul 31, 2015 8:57 pm

The decoder is a Bachmann 36-552; I have in fact contacted Bachmann, who were very helpful, but unable to go into deep technical detail. However, I have come across a web site http://www.merg.org.uk (Model Railway Electronic Group) which is a mine of detailed information on every aspect of electronics applied to model railways. I am currently building a DCC programmer based on their design, and I think this will resolve my programming problems. I shall however (of course !) continue to use RPi and Gertbot as a basis for my control system. Thank you for your interest.

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Sat Aug 01, 2015 8:37 pm

The DCC controller must be a chip looking at the size of the PCB.
And as the DCC market is limited I would not be surprised if there is only one manufacturer.
Which would mean "all" DCC controllers are the same.

By-the-by : from a technical point of view the DCC standard is appalling!
You have to modulate the power signal!!
Much simpler would have been an RF modulated signal on top of DC.
- Much higher data bandwidth
- Much lower modulation amplitude (An radio receiver can work with micro-volts)
- Can used a standard radio receiver
- Can have multiple controllers (carriers) on the same track
- Signal passes through 'bad' connections
That is what you get if you let amateurs set a standard :roll:

User avatar
rpdom
Posts: 14684
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Gertbot as DCC Programmer?

Sun Aug 02, 2015 6:47 am

Gert van Loo wrote:By-the-by : from a technical point of view the DCC standard is appalling!
You have to modulate the power signal!!
Much simpler would have been an RF modulated signal on top of DC.
Having never looked at how DCC works, I always assumed that is what it did. Now you've told me how it does work, I don't think I'm going to touch it :shock:

User avatar
Gert van Loo
Posts: 2482
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: Gertbot as DCC Programmer?

Sun Aug 02, 2015 6:51 pm

DCC is a square wave operating between +15V and -15V. You send ones and zeros by changing the high/low ratio.
It is around 17KHz and the pulse width has to be accurate within 6 micro seconds.
The square wave also power the trains and that can easily require 1-2Amps.
(Or if you have a lot of trains 5Amps or more.)
As you can imagine, you need some good quality hardware and software to make that.

The Gertbot was originally not design for this but when I looked at the specification of the H-bridges
and the controller I thought it was feasible, but required a very timing robust program.
Got it done in the end!

heuristicjohn
Posts: 39
Joined: Thu Jan 31, 2013 11:55 pm

Re: Gertbot as DCC Programmer?

Wed Aug 19, 2015 7:37 pm

Let's not be unkind to DCC ! I for one am grateful to Gert for providing this facility - it motivated me to build a basic N gauge layout which I can drive via RPi and Gertbot, with plenty of scope for future expansion. To my mind, DCC is a neat method for providing both power and one-way communication to locomotives and other devices. If you need two-way communication, as in programming, then it transpires you need a version of the H-bridge driver chip with current sensing (eg L293E); this is because reply messages from the decoder are sent by the decoder connecting/disconnecting the motor load to send 1's and 0's, and the current sensing is used to detect the message. This could probably be achieved by building an add-on booster for the Gerbot DCC output, or more simply by building a simple stand-alone programmer, as I have done (using one of the two designs on www.merg.org.uk). DCC is out there, and it works ! It's just another case of horses for courses (or, in this case, brains for trains).

Nucleus_dk
Posts: 13
Joined: Sat Apr 18, 2015 9:53 am
Location: Denmark

Re: Gertbot as DCC Programmer?

Thu Nov 26, 2015 7:17 pm

Thanks for the DCC in Gertbot !

I am able to program and control Accessory Decoders and expect it to work for train decoders too.
Tested with servos, turnouts, signals, lights, and an extended decoder for motors. (ESU switchpilot + extension)

Im working on some software for railroad control, to control my own railroad that im about to setup for DCC use.
Using C++ and Gtkmm. (Build on RPI2 Fedora using Anjuta)

I have a few trains but they are all marklin using mfx, so i need to convert one of them to test the train control part.

The option to read the DCC for ex. railcom feedback, or at least CV information from decoders would be seriously great !
maybe a second board used for that ..... (please lol)

Return to “HATs and other add-ons”