DCC railway model controlled with Wi-Fi

From openPicus Wiki
Jump to: navigation, search

Contents

Introduction

This project had as objective to control Railroad model using an iPhone by the Web Browser (no need for an App!). Flyport integrated Webserver has been customized with several buttons and graphic to manage the railroad model.
DCC (Digital Command control) is used in model railroading to allow individual control of locomotives which are all on the same track.


Instead of the normal variable DC voltage that is applied to the track on DC layouts to control the speed and direction of the locomotive, an alternating square wave voltage is applied to the tracks. The square wave carries a digital signal which is received by decoders installed in each of the locomotives. The length of each square wave cycle indicates whether a 0 or 1 is being transmitted. Each decoder has its own address and instruction packets sent in the DCC square wave include the address of the locomotive that the instruction relates to. More information regarding the standards used can be found on the NMRA website: http://www.nmra.org/standards/DCC/

Implementation

I had recently constructed a DCC model railroad for myself and my son, but controlling each locomotive was not intuitive for my son. Also, the controller was restricted to a single point on the track so he could not walk about and control the layout at the same time.
Whilst looking around, I found a number of existing wireless controllers which were purpose built for controlling the layout – but these were very expensive and were still not that intuitive.
Having built a another project using the Flyport I started looking around to see if the Flyport could possibly be used to fulfil this purpose – become the controller for the model railroad. The key was being able to accurately provide a digital signal that could be understood by the decoders within the trains on the layout. Whilst looking around the forum, I found a thread relating to Timer4 – and on investigating PIC timers further, I realised that timer4 could be used for generating the DCC signal.
The basis for the project would be as per the following diagram: Rail.jpg The user would control the locomotives using a smart phone / tablet over Wi-Fi, connected to the home wireless network. The Flyport would also be connected to the wireless network and would serve the pages to the smart phone which would contain the control interface. When the user presses a button on the website, the Flyport converts this command into a DCC instruction packet and the instruction is placed in the array of instructions to be sent to the trains.

At the same time, the Flyport Timer4 has been set to interrupt – How long the next interrupt will be depends on whether or not the next bit (part of the message) to be sent to the rails is a 1 or a 0 – for a 1 the interrupt is set at 58us (micro seconds) and for a 0 the interrupt is set as 100us. At each interrupt the output of pin 25 is toggled between either high or low output. The Flyport reads the bits from the message array and sets the next timer accordingly, switching pin 25 on and off very quickly, but with precise timing. At the end of the message array it goes back to the beginning.
But the output from the Flyport is not enough to drive the locomotives, for that we need a booster. This will take the 0 to 3.3v signal and boost it so it becomes -15v to 15v and able to handle the current required to drive the locomotives. There are a number of DIY booster circuits available on the internet, but I opted to purchase a Tamvalley Depot (www.tamvalleydepot.com) 5A booster circuit board as it met my requirements and I did not have the time to construct my own booster.

As it turns out, the 3.3v output from the Flyport was not quite enough to drive the input signal for the booster, so the 3.3v had to be boosted to 5v first (using a couple of transistors/ resistors), and then this 5v signal was input to the booster.
I also added a 5v regulator circuit so the Flyport could be powered from the same supply that powers the booster – a 15v 4A DC power supply:
Rail2.jpg

Bill of materials

TR1 – BC547
TR2 – BC557
C1 – 100uF
C2 – 10uF
R1 – 470 ohm
R2 – 220 ohm
R3 – 1k ohm
R4 – 220 ohm
R5 – 220 ohm
Voltage Regulator – LM7805 3 LEDs
Flyport Module DCC booster
The 3 LEDs indicate the following:
1 – Wi-Fi Connected when lit; or if flashing – Emergency Stop mode (DCC removed from track)
2 – Flashes when command received from Website
3 – DCC signal is active

Source code

Source code for Flyport

Personal tools
Namespaces

Variants
Actions
START HERE
DEVELOPMENT
HARDWARE INFO
RESOURCES
PHASED OUT
Toolbox