PDA

View Full Version : DCC in PBP



boroko
- 12th September 2008, 07:07
HI all,
I have been looking for a way to sent data over a two wire connection and have been stumped until I remembered that modern model railroad layouts use such a scheme to control their engines. Its called DCC.
http://www.nmra.com/standards/DCC/standards_rps/S-91-2004-07.pdf

They power the track with two pulse lengths of alternate polarity generated with an H bridge. There is an active DIY community, but everything I have found is in assembly. Has anyone done any of this in PBP?

I need the comm for other use, so the protocol is not as important as the coding and decoding on a PIC.

I'm going to try and get a fast enough PIC to use DT-ints for comm and still be able to get 8 channels of PWM.

Thanks for any thoughts
Bo

skimask
- 12th September 2008, 07:22
http://www.picbasic.co.uk/forum/showthread.php?t=4751
Putting DCC in the search field gets you a few results (I know, DCC is too short for the regular search)
Not a new idea though, putting an AC signal on a DC rider. I would think the hardest thing (if it's really that hard) is figuring out the hardware to superimpose this AC signal onto this DC carrier. Figure that out, and it would be just like sending serial data over 2 wires.

boroko
- 12th September 2008, 17:02
Thanks Skimask,
did the search and the only results were like mine: questions.
It seems that no one is interested.
I'll work on it and see if I can put it up. Seems like a powerful way to solve comm over two wires.

skimask
- 12th September 2008, 17:10
Well, what do you actually mean by sending data over 2 wires?
Do you mean just 2 wires or 2 wires that are already carrying power to another device?
I assume the 2nd...

Charles Linquis
- 12th September 2008, 17:23
I don't exactly know what you are trying to do, but a PIC with a USART can easily do comms and software PWM at the same time.

Acetronics2
- 12th September 2008, 17:23
Hi,

Here are some nice info ...

http://www.merg.org.uk/resources/dcc.htm

Assembler ... yess, but pretty well commented ! ... so you understand what's going on.

The "miniDCC" project also could be useful ...

Alain

boroko
- 12th September 2008, 17:56
Correct, send data over the only two connections available, that are also providing power.

To give this a bit of flesh, imagine addressing your Low Voltage Yard lighting. Two wires existing all over the yard. They normally are supplied with 12 vac. Insert a control box between the transformer and the yard wire that has a rectifier and H-bridge that reverse the lines at intervals of either 5 kHz or 8.5kHz. The receiver has a bridge rectifier and cap for storage of power and taps the raw lines to collect intelligence. On model trains, address, speed, accessory control, etc, are communicated. The commercial systems and the spec have a method for limited feedback by current (load) pulsing the line for simple acknowledgment.

Since my use is not for controlling trains, but instead, yard lighting and such, I need to be able to get into the code and tweak. The only examples of code that I have found are asm and as you can imagine, very dependent on cycle counts for correct timing. I'm not sure that I can handle that reliably. If someone had already done it in PBP, I could look at and get some ideas. I'm pulling apart the .asm code now and trying to get my arms around it so that I can do it a bit easier. I may be able to leave the message collection in .asm, and just write around it, but first I have to get the interspersed (and carefully timed) "train" stuff out of it and get the pulse measurement and word collection back working.

My app uses Darrel's DT-ints to generate 8 channels of PWM. To mix that with watching for, and decoding 100us and 200us pulses is a lot. My path is to separate them on different PICS until I can get it working. Once that is running, I will look at a faster PIC or moving up the food chain.


Hope that gives everyone a better idea of what I'm trying to do. Looks like my chance to figure this out and have something to contribute.

Thanks
Bo

mackrackit
- 12th September 2008, 18:11
Sounds like a low voltage X10?

Here is some info.
http://davehouston.net/

boroko
- 12th September 2008, 18:32
Like X-10 in as far as power line comm, but instead of imposing a signal on a carrier, the supply is kind of FSK (freq shift key) of the supply power. Seems very robust. on model trains, remember that the contact is by wheels, often on dirty track. Difficult at best.
Bo

boroko
- 12th September 2008, 18:43
BTW,

Alain:
MERG is an excellent resource for such things. I'm building a MiniDCC as a base to start testing. (I will have to get back into Model Railroad, so it will have a use after testing). The problem is that it is so well done, no one had needed to write in PBP, they just use it.

Dave:
Thanks for the link to your site. Very nice info, I will mine it further. Maybe tune up my X-10 system.

bo

mackrackit
- 12th September 2008, 18:53
Dave:
Thanks for the link to your site. Very nice info, I will mine it further. Maybe tune up my X-10 system.

I was meaning your yard light system would be like X10. Modulating a signal over DC like the trains should be pretty easy. But that was only an example... right?

And the site I linked to is a different Dave.

malc-c
- 12th September 2008, 21:49
Not sure if this is any help

http://www.trainelectronics.com/miniDCC/index.htm

It has some code and the site is about DCC

Acetronics2
- 15th September 2008, 08:37
Hi, Boroko

I found this tutorial ...

In French, ... yes, FreeBasic, yes ... but everything needed explained .

http://www.train35.com/dcc1.html

And easy to port to pbP !

Alain

boroko
- 15th September 2008, 19:05
Thanks Alain for the suggestion. I will look and see what I can learn from there.

Current plan is to use DT-Ints to capture and measure the width of the incoming pulses to determine weather they are short (58uS :"1") or long (100uS: "0") or standard AC power (16.7mS) and generate a level of 1 or 0 if it is data. If Std. AC I can jump to a fall-back and pick one of a few basic modes by cycling the power. The data pulses, once decoded, could be simply fed into the USART.

Meriachee
- 19th September 2008, 04:39
Bo, have a look at JMRI. Currently "decoders" which is the standard moniker for DCC assemblies that go into engines are run by pics. The latest crop have some interesting features, including "programmable" PWM. You can move the frequency range around to quiet noisy motors. It looks, programs and acts like NVRam. Quite cool, actually.

Hope it helps
Gary

boroko
- 20th September 2008, 19:46
Thanks Gary,
From what I can tell, PICS have been used extensively in decoders. The specific issue that I'm trying to nail down is all of the code that I have seen is in assembly. I can muddle through assembly, but in this app, the timing is very tight, and I haven't mastered the skill to mimic the code in PBP. I have been refining the attack and will whittle away at it. I DON'T want to specifically duplicate the existing function, if so I could just burn the available .hex. I'm trying to accomplish comm over 2 wire in a similar way that is done in DCC. That's why I need to have control of the code.
I appreciate all of the feedback that everyone has offered. It looks like I'll just have to upgrade my skill set a bit.
Thanks
Bo