Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

DCC / Model Railroad


  • Please log in to reply
20 replies to this topic

#1 ChrZeb

ChrZeb

    New Member

  • Members
  • Pip
  • 9 posts

Posted 07 December 2012 - 04:44 PM

A DCC (digital command and control) signal is used to e.g. control speed of a model railroad machine. I have to generate a square wave signal with different period length. A logical "0" is 200us, a logical "1" is 116us. A booster will generate an AC Voltage out of this square wave to drive the machines. Now my questions: Is it possible to generate a square wave signal of this kind without any gap? Best idea would be to use a timer interrupt and to change the timer period according to the required puls length? Chris

#2 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 08 December 2012 - 04:37 AM

This could help: http://highfieldtale...r-for-netduino/ Cheers
Biggest fault of Netduino? It runs by electricity.

#3 ChrZeb

ChrZeb

    New Member

  • Members
  • Pip
  • 9 posts

Posted 08 December 2012 - 11:40 AM

This could help:
http://highfieldtale...r-for-netduino/
Cheers

Thanks - good idea -I tested it and....
because of frequency i need at least two SPI-bytes to generate a 58us pulse. As between two SPI Bytes there is short "1" pulse, it is not possible to generate a constant value of "0" for 58us.

May be i try a timer....

#4 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 08 December 2012 - 12:49 PM

I don't believe you will able to tune a timer for so short (and reliable) timings. Bear in mind you are running softyware over a managed framework, so time to time, the garbage collector starts, and wipes the unused memory. That takes time: small, but we're talking about microseconds. Also, consider that a simple "OutputPort.Write" operation itself takes some hundreds of microseconds. Now, suppose the SPI of a Netduino Plus, configured with a clock of 500kHz. Due some limitations, you cannot slow down the clock less than 400kHz or so. I remember that a lower value yields a strange behavior, while the "zero" hangs completely the board. So, the clock is 500kHz, which means a new bit outgoing from the MOSI pin every 2us, right? Since the DCC requires the logic "one" as 58+58us, you will need 29+29 bits. Again, for the logic "zero" (100+100us), you will need 50+50 bits. I hope that's clear enough. What else? Just create an arbitrary long byte array (or ushort array, if you like), then fill its bits with the "shape of the desired waveform. That is how my infrared transmitter works, and I did not see any relevant "delay" between the bytes. If you have either a scope or a logic analyzer able to plot the outgoing waveform, you may test by yourself! Cheers
Biggest fault of Netduino? It runs by electricity.

#5 ChrZeb

ChrZeb

    New Member

  • Members
  • Pip
  • 9 posts

Posted 09 December 2012 - 10:53 AM

Right - Timers don't work, bit SPI does not work too. I set the SPI to 500kHz. Between two Bytes in SPI there is a gap of 2.2us (measuring Clock-Pulses). During this gap the Data Port is high. So it is not possible to keep the SPI data for two bytes low. Seems to be, that I have to step back to an external Microcontroller. Chris

#6 ChrZeb

ChrZeb

    New Member

  • Members
  • Pip
  • 9 posts

Posted 09 December 2012 - 10:57 AM

...by the way... Someone else interested in controlling a model railroad using a netduino. My intention was to use a browser running on my iPad to control the model railroad.

#7 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 09 December 2012 - 03:23 PM

Right - Timers don't work, bit SPI does not work too.

I set the SPI to 500kHz. Between two Bytes in SPI there is a gap of 2.2us (measuring Clock-Pulses). During this gap the Data Port is high. So it is not possible to keep the SPI data for two bytes low.

Seems to be, that I have to step back to an external Microcontroller.

Chris


You are right: there's a spike between every byte pair. That's the way I used a low-pass filter to cut them off.
Have a look at the schematic: there is a resistor (1.5k) and a capacitor (1n), followed by a logic gate (better if Schmitt-trigger).
As for me, a simple R-C filter is dramatically easier than adding a second MCU.
http://highfieldtale...r-for-netduino/

By the way, I believe the spikes have not any influence in the railroad system. It is very narrow compared to the pulses duration.

Hope it helps.
Cheers
Biggest fault of Netduino? It runs by electricity.

#8 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 06 July 2014 - 03:08 PM

Nice post, i'm following your suggestions Mario to do my DCC controller.
One question. In the image you can see in blue the clock signal in yellow the data signal... 
Why the signal rises before the clock signal begins?
thanks
 
oo7o.jpg


#9 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 06 July 2014 - 04:31 PM

 

Nice post, i'm following your suggestions Mario to do my DCC controller.
One question. In the image you can see in blue the clock signal in yellow the data signal... 
Why the signal rises before the clock signal begins?
thanks
 
oo7o.jpg

 

 

Clunis, a piece of your code would help, as well as kind yet firmware version of the Netduino.

I've experienced a lot of different behaviors around SPI upon Netduino MCU and firmware version.

Ciao


Biggest fault of Netduino? It runs by electricity.

#10 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 06 July 2014 - 05:10 PM

I found the code googling in the net... I followed some intresting web pages 

 

for example this one

http://www.tinyclr.i...-velocità-.aspx

 

here the code.

http://pastebin.com/rjT9yQ9v

 

my firmware version is the last one downloaded from Chris post 

Version: 4.2.0 Update 1 (version 4.2.0.1) Netduino Plus 1

Ciao,

grazie!



#11 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 July 2014 - 03:36 AM

The Atmel-based Netduino, that is the first edition, had not troubles on SPI. However, yes, I remember there's this strange behavior about the MOSI signal off the pulsed pattern: it stays high. Also stays high between a byte and the next one, so that I inserted a small R-C lowpass filter to cut those spikes.

 

Despite this glitch, the waveform and its timing is correct. If you drive any SPI-enabled logic, you shouldn't have any issue.

Even in a non-classic usage as the IR transmitter, the spikes are not a problem. The receiver embeds a good bandpass filter which cuts anything falls off the expected message pattern.

 

Ciao


Biggest fault of Netduino? It runs by electricity.

#12 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 07 July 2014 - 11:08 AM

I'm not driving a SPI-enable logic device, but i'm thinking how to use the "enable pin" to cut off the signal before data, for example drive a transistor?



#13 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 July 2014 - 11:53 AM

Uh? well, you can do it, but...what's the goal?

Just formulate the question better: what is the expected waveform?


Biggest fault of Netduino? It runs by electricity.

#14 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 07 July 2014 - 12:26 PM

I want to cut the blue part of the yellow channel.

The expected waveform is the yellow trace between the blue.

 

19fj.jpg



#15 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 07 July 2014 - 01:06 PM

Since you have a scope, I'd suggest to display the "enable" signal aside to the two other traces. Furthermore, we may discuss on how cut the undesired sections.

Riciao


Biggest fault of Netduino? It runs by electricity.

#16 piwi

piwi

    Advanced Member

  • Members
  • PipPipPip
  • 114 posts
  • LocationGermany

Posted 07 July 2014 - 01:11 PM

there is another way of doing this, with a marklin modell train. You can use one of the .net microfamework harware boards to use the CAN bus signal, followed by some minor electronics for buffering (isolator and optocoupler). Have to dig up the schematics, pretty simple stuff. I did it on a breadboard. Then connect it to the second train controller box coming pretty much with every digital started pack and can be bought seperately as well.

 

Use some software in .net to write the CAN bus messages. And off you go, I succeeded in doing this even with an LCD touch connected to the NetMF HW and control the trains speed, extras, the train's track switches, pretty much anything connected and using the rails as means of communication. The CAN protocoll from Marklin can be found on the Marklin web site. 

 

One can even think of connecting a BLE or Wifi receiver unit to the .net board and be able to control your train from your mobile device. If you extend the controlling software with some nice UDP stuff UPNP is even in the game .... so your trainset will even be noticable on the network ....



#17 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 10 July 2014 - 08:26 PM

Hi guys, some good news!!!
I abandoned the SPI solution and decided to try with normal Serial signal.
With this simple code (http://pastebin.com/8J3bCJc7) I'm able to write on serial port the entire "Idle Packet" (I started my work analyzing this one). The random high and low bits are not really random they are "start" and "stop" bits... The trick is use these to form our packet!!!
 
According with this document http://www.nmra.org/...-91-2004-07.pdf i can stretch the zero symbol when i need to write three or more consecutive zero signals . So it's almost simple get a correct waveform.
 
See you soon!


#18 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 11 July 2014 - 03:47 AM

 

Hi guys, some good news!!!
I abandoned the SPI solution and decided to try with normal Serial signal.
With this simple code (http://pastebin.com/8J3bCJc7) I'm able to write on serial port the entire "Idle Packet" (I started my work analyzing this one). The random high and low bits are not really random they are "start" and "stop" bits... The trick is use these to form our packet!!!
 
According with this document http://www.nmra.org/...-91-2004-07.pdf i can stretch the zero symbol when i need to write three or more consecutive zero signals . So it's almost simple get a correct waveform.
 
See you soon!

 

 

That's a good news indeed, but I wonder why the SPI wasn't suitable for the desired waveform. With the SPI you can compose an "arbitrary" waveform, as long -yesy- there are some limitations.

Ciao


Biggest fault of Netduino? It runs by electricity.

#19 Clunis

Clunis

    New Member

  • Members
  • Pip
  • 9 posts
  • LocationItaly

Posted 17 July 2014 - 08:00 PM

Hi guys, I found this "booster" to convert my Netduino signal. We can input a low level signal (5V) and we get a DCC signal in the output. Very tasty!! But how to convert the 3.3V output to 5V? I suppose that an opamp in comparator configuration can works but i saw that the signal gets timing distortion. It deforms the square signal due to hardware limits. Can you give me some other valid solution?

Thanks

 

HBridge18200.GIF



#20 Mario Vernari

Mario Vernari

    Advanced Member

  • Members
  • PipPipPip
  • 1768 posts
  • LocationVenezia, Italia

Posted 18 July 2014 - 03:47 AM

A simple NPN transistor...


Biggest fault of Netduino? It runs by electricity.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.