JVene
July 12th, 2007, 04:01 PM
Here's something I've not found another forum for...
I'm asking about the feasibility of an idea to use the audio card of a PC to generate the control signal for a DCC model train layout, passing that through an audio amplifier. It's a project aimed at a little father/son time (a 6 year old), while saving money on the control electronics.
If you're familiar with both electronics (not expert, just familiar) and programming, especially audio, you may find this interesting for discussion - especially if you're a parent. I'm asking for advice/suggestions, but it's also an interesting discussion topic for programmers just on theory.
Anyone around here have any knowledge/experience in software and technical work on DCC model train controls? (For those interested but not familiar, that's digital control for trains, a protocol for transmitting data over the power supplied to model train tracks).
The link isn't handy, but easy to find, from the NMRA (model railroad association) describing the technical details of DCC protocols, but it's fairly straight forward.
My son, 6, got an electric HO scale model train (Thomas the Tank Engine - a child's storybook character), a couple of cars and enough track for an oval. He's hooked, now, and wants the 'other' engines in the series. In the stories, each engine has a name, a character and a particular form (they all have faces with moving eyes). Its a great thing for some father/son time, and I realized that two engines on one track means digital control.
We got the first train setup, but I had no power supply. I cobbled one together with spare parts. A bipolar transformer, diodes, a few resistors, capacitors and a chip based operational 50 watt power amplifier (for those not familiar, operation amplifiers are a particular design with two inputs, a + and - input where the - input inverts the phase of the signal, and the output is the difference between these two inputs; typically used in audio applications).
The chip based amplifier can produce DC, handles a few amps current, gives me short circuit/over current/thermal protection. Using a simple volume control I can bias the voltage output of the amp, giving a speed control. Since it's bipolar, it can do forward and reverse.
But, that's a DC voltage swing on the entire track. Two engines on one track are a real drag that way (and, my son's likely to want, ask for, and end up getting a few more engines :) - ok, maybe I want a couple more, too).
So, I've found some DCC decoders for about $18 shipped. These are smaller than postage stamps, so they fit inside the engines. They respond to digital commands sent over the track so engines can be controlled independently. The track is powered by AC, which itself is modulated to include the data. The decoders can be programmed for an "ID" number, a single numeric value identifying each device (some devices are track switches, lights, horns, smoke, etc).
Here's were my inquiry comes in (in a moment).
What I learned is this:
The data is transmitted along with the power. The decoders actually control the engine speed independent of the power supply. Typical AC (house power) is 60hz (changes polarity in sine waves at 60 times per second). This AC track power is switched between about 9.1Khz and 4.6Khz in square waves.
The decoders interpret a data bit of 1 if the width of the positive and negative voltage swing lasts about 54 microseconds, which corresponds to a frequency in the area of 9Khz. If the pulse width lasts over 100 microseconds, that is interpreted as a data bit of 0. The spec states a zero can be elongated much longer.
Now, in the product line that does this stuff, power boosters (which simply amplify the digital signal to track power levels, and come in power ranges from 3.5 amps to over 10 amps at +- 16v) are about $100 to $500. The digital command module is another $100 to $250. That's not in the price range of a toy!
There are decoders for complex engines, with sound and other effects, that cost $100 or more. However, simple 1 amp speed decoders can be purchased for $18 or less. These seem a good fit for the toy Thomas engine (and the other engine characters).
Here's my design plan, and the actual area of my inquiry.
I intend to use the little audio power amp I've already built to power the DC version of the train to provide power (taking the position of the power booster). I plan to use the audio card to provide the digital output signal, which will drive the amp just as if it were sending out audio. Between the computer and the amplifier I probably need to add a small signal buffer, which will adapt the output of the computer (basically square wave audio) to the power amplifier, to adjust the track voltage to swing + and - at 16volts.
Thinking about audio as a digital output, I realize that 44.1Khz doesn't match well with a pulse duration of 54 microseconds. 1 sample at full amplitude is around 22 microseconds, two would be 44 and so 3 samples, lasting 66 microseconds, is too long. Switching to about 37 Khz sample rate, however, makes two samples just about perfectly align to a pulse width of 54 microseconds, making a digital 1 for the DCC standard.
4 samples make a zero.
So, I'm envisioning an application, for which I will choose C++ (my own favorite for over 15 years) that generates this audio control output according to a dialog based interface of sliders representing train speed and direction for each of the engines we end up deploying on the track.
The NMRA specs describe the format of the data rather explicitly, including modes for 'programming' the decoders (basically setting their engine ID), and the various commands for stopping, reversing, setting speed, etc). The standard indicates that a command is sent repeatedly, and decoders ignore the repetitions, but repetitions are needed to overcome track noise that corrupts the data stream occasionally. This also has the effect of keeping the power running as AC somewhere in the 4Khz to 9 Khz range.
Like IP, each 'message' includes the destination ID, which is how engines are addressed independently - messages are interleaved, and it seems the overall rate at which messages are dispatched are in the range of 50 to 200 messages per second, depending on the message length and format.
The spec also describes that slew rate limitations of the decoders. They expect at least 2 volts per microsecond, though the spec dictates the power booster/digital command must supply at least 2.5 volts per microsecond. The power chip I'm using provides 12 volts per microsecond. Pulse durations can vary some 10% or more, so timing is all that critical (I think the 1 pulse can range from about 52 microseconds to nearly 60 microseconds).
The power booster I built cost me about $15 in parts, plus an hour of fabrication which my son really enjoyed 'helping' with. A buffer would require a regulator, which I have the parts for, adding another $3 or $4 overall, plus some scrap cable/connectors for the audio interface. An old P2-400 with a sound card should suffice as the train controller, with an old 15inch monitor (all spare parts stuff).
I intend to set output from the audio card to 8 bit audio at about 18.5 Khz sample rate (where 1 sample is around 54 microseconds). That would make demand on the P2-400 minimal.
For other technical reasons I do intend stereo output and may create a second power booster (for something called track reversal loop, where a track loops back onto itself, requiring a reverse of polarity, or at least a synchronization of phase, where an engine transfers back onto track in the reverse direction). This may involve a few proximity sensors, so I can tell when an engine has entered into a reversal loop section. While there, the phase of the power signal must be inverted while the engine is running, which I plan to do by elongating a zero until phase is matched with the destination track, powered by the second audio channel/power booster.
Track reversal electronic devices cost about $45, and handle only one reverse loop. I think I can create 3 'sensors' (one at each entrance into the reversal section, one inside the reversal section) for about $1.50 each, using old cassette tape playback heads (or just loops of small gauge wire around a small iron core - to sense the 'noise' of the motor as it passes over the sensor under the track) and a couple of operational amplifiers to create a signal comparator that can generate a logic 1 which I can sense on one of the 8 lines of the parallel port. For our layout I don't suspect I'd have room for any more than two reversal loops, so two loop sections would be possible, software would otherwise handle the transition using stereo audio output.
If that's not quite clear, here's a clearer description of the problem.
For a short timeslice (say 10 microseconds, where we can consider the polarity at that moment) a train might be moving on a loop that joins the same track that entered the loop (like the loop of a lasso). If the track were really connected this way, the + polarity would end up connecting to the - polarity, creating a short.
So, the loop is cut into 3 sections. This looks, then, like a Y, where the two top legs of the Y are joined by a curve, but not electrically connected.
When the engine moves from part of the Y to the curve, the engine will complete a circuit connection, with it's wheels, between the Y and the curve - but only on one side of the Y at a time. One side as the engine enters the curve, and the other as it leaves.
The entire Y is a single electrical path (one rail +, the other rail -), and part of the 'main' track power - sharing the main track's polarity.
Some people have to rethink that to realize there really is a problem. It ends up that what is a 'right' rail physically connects to the 'left' rail when the curve ends up connecting to the base of the Y, creating a short. You have to envision this shape with two rails and follow the path from one side to the other to realize they would cross-connect.
Thus, the electrical isolation of the curve atop this Y.
At each of the two upper legs of the Y, and proximity sensor would inform the computer that the engine is about to enter the curve, and start powering it (from the second audio channel) in sync with THAT SIDE'S polarity direction relative to the engine's orientation. When the engine jumps the electrical isolation, it will receive power in sync with the polarity of the main track from that viewpoint.
A second proximity sensor will inform the computer when the engine is inside the curve section, meaning it's electrically isolated from the main track. At this time, the second audio channel, exclusively powering the curve section, would extend the zero length of a message until the main track switches phase (it's AC remember), bringing the curve and the main track in phase with respect to the polarity as viewed from the engine's orientation when it re-enters the Y (in what's now the reverse direction).
When the third sensor fires, it means the engine has left, is no longer on the curve section, and that can be powered down (or made available for another engine to enter).
If any other reverse section receives a signal of an engine entering a reverse loop while all this is happening, I'd probably have to issue a 'stop all engines' command and let either my son (or me) give one engine the go ahead manually. If I had full transponders, I could have the computer figure out which engine is there first, and hold the other(s), but that's just too much, especially since the odds are probably low.
Ok, finally, the nature of my inquiry and posting.
Does anyone have enough familiarity with DCC to advise if my plan makes any sense? Is the square wave DCC signal beyond the range of an audio power amplifier (I'm of the opinion it is within the capabilities, given some slight wave shaping care against square wave transitions creating harmonic distortions).
Anyone find the project interesting enough for me to continue the thread as I proceed to create the thing? I expect to get rolling in a month or less.
If you have kids and are curious about the Thomas engines (the 'standard' Thomas toys are wooden trains on wooden tracks), Bachmann makes the engines and can be found through a google search. Although an electric set, with track, can cost around $80 or so, it compares reasonable with the cost of wooden sets ($20 for a wooden engine, non-powered, similar costs for track). The DCC conversion is an electronic project (soldering iron, wire, disassembly - there's a web page of instructions, search Thomas DCC and you'll find it).
Track reversals aren't typically required - you can layout track without them. We have a 3' x 4' train table (intended for the wooden trains), but it's just a little too small for the HO track, even for a simple oval - but a slightly larger plywood sheet on top of the table gives just enough extra space to make it fit. I've found Atlas, the track manufacturer, has a free track layout software (not great, but adequate) - and I've designed a layout including a helix spiral elevator to a second table level 16 inches above the main table, two runs of track at 22" radius turns (with a 19" interior) made with flex track (shaped track - the standard is 18" radius) - and a second level with another layout including a reverse loop.
My son has been making 'city scapes' for years (started by shaping straws into light poles before he was 2), so we're 'decorating' the layout with traffic lights (playdo and LED's), signals and bridge lights (white LED's), street lights (which he now makes out of 6 gauge solid core copper wire) and other 'hand crafted' accessories, including bridges, stations, etc.
I'm asking about the feasibility of an idea to use the audio card of a PC to generate the control signal for a DCC model train layout, passing that through an audio amplifier. It's a project aimed at a little father/son time (a 6 year old), while saving money on the control electronics.
If you're familiar with both electronics (not expert, just familiar) and programming, especially audio, you may find this interesting for discussion - especially if you're a parent. I'm asking for advice/suggestions, but it's also an interesting discussion topic for programmers just on theory.
Anyone around here have any knowledge/experience in software and technical work on DCC model train controls? (For those interested but not familiar, that's digital control for trains, a protocol for transmitting data over the power supplied to model train tracks).
The link isn't handy, but easy to find, from the NMRA (model railroad association) describing the technical details of DCC protocols, but it's fairly straight forward.
My son, 6, got an electric HO scale model train (Thomas the Tank Engine - a child's storybook character), a couple of cars and enough track for an oval. He's hooked, now, and wants the 'other' engines in the series. In the stories, each engine has a name, a character and a particular form (they all have faces with moving eyes). Its a great thing for some father/son time, and I realized that two engines on one track means digital control.
We got the first train setup, but I had no power supply. I cobbled one together with spare parts. A bipolar transformer, diodes, a few resistors, capacitors and a chip based operational 50 watt power amplifier (for those not familiar, operation amplifiers are a particular design with two inputs, a + and - input where the - input inverts the phase of the signal, and the output is the difference between these two inputs; typically used in audio applications).
The chip based amplifier can produce DC, handles a few amps current, gives me short circuit/over current/thermal protection. Using a simple volume control I can bias the voltage output of the amp, giving a speed control. Since it's bipolar, it can do forward and reverse.
But, that's a DC voltage swing on the entire track. Two engines on one track are a real drag that way (and, my son's likely to want, ask for, and end up getting a few more engines :) - ok, maybe I want a couple more, too).
So, I've found some DCC decoders for about $18 shipped. These are smaller than postage stamps, so they fit inside the engines. They respond to digital commands sent over the track so engines can be controlled independently. The track is powered by AC, which itself is modulated to include the data. The decoders can be programmed for an "ID" number, a single numeric value identifying each device (some devices are track switches, lights, horns, smoke, etc).
Here's were my inquiry comes in (in a moment).
What I learned is this:
The data is transmitted along with the power. The decoders actually control the engine speed independent of the power supply. Typical AC (house power) is 60hz (changes polarity in sine waves at 60 times per second). This AC track power is switched between about 9.1Khz and 4.6Khz in square waves.
The decoders interpret a data bit of 1 if the width of the positive and negative voltage swing lasts about 54 microseconds, which corresponds to a frequency in the area of 9Khz. If the pulse width lasts over 100 microseconds, that is interpreted as a data bit of 0. The spec states a zero can be elongated much longer.
Now, in the product line that does this stuff, power boosters (which simply amplify the digital signal to track power levels, and come in power ranges from 3.5 amps to over 10 amps at +- 16v) are about $100 to $500. The digital command module is another $100 to $250. That's not in the price range of a toy!
There are decoders for complex engines, with sound and other effects, that cost $100 or more. However, simple 1 amp speed decoders can be purchased for $18 or less. These seem a good fit for the toy Thomas engine (and the other engine characters).
Here's my design plan, and the actual area of my inquiry.
I intend to use the little audio power amp I've already built to power the DC version of the train to provide power (taking the position of the power booster). I plan to use the audio card to provide the digital output signal, which will drive the amp just as if it were sending out audio. Between the computer and the amplifier I probably need to add a small signal buffer, which will adapt the output of the computer (basically square wave audio) to the power amplifier, to adjust the track voltage to swing + and - at 16volts.
Thinking about audio as a digital output, I realize that 44.1Khz doesn't match well with a pulse duration of 54 microseconds. 1 sample at full amplitude is around 22 microseconds, two would be 44 and so 3 samples, lasting 66 microseconds, is too long. Switching to about 37 Khz sample rate, however, makes two samples just about perfectly align to a pulse width of 54 microseconds, making a digital 1 for the DCC standard.
4 samples make a zero.
So, I'm envisioning an application, for which I will choose C++ (my own favorite for over 15 years) that generates this audio control output according to a dialog based interface of sliders representing train speed and direction for each of the engines we end up deploying on the track.
The NMRA specs describe the format of the data rather explicitly, including modes for 'programming' the decoders (basically setting their engine ID), and the various commands for stopping, reversing, setting speed, etc). The standard indicates that a command is sent repeatedly, and decoders ignore the repetitions, but repetitions are needed to overcome track noise that corrupts the data stream occasionally. This also has the effect of keeping the power running as AC somewhere in the 4Khz to 9 Khz range.
Like IP, each 'message' includes the destination ID, which is how engines are addressed independently - messages are interleaved, and it seems the overall rate at which messages are dispatched are in the range of 50 to 200 messages per second, depending on the message length and format.
The spec also describes that slew rate limitations of the decoders. They expect at least 2 volts per microsecond, though the spec dictates the power booster/digital command must supply at least 2.5 volts per microsecond. The power chip I'm using provides 12 volts per microsecond. Pulse durations can vary some 10% or more, so timing is all that critical (I think the 1 pulse can range from about 52 microseconds to nearly 60 microseconds).
The power booster I built cost me about $15 in parts, plus an hour of fabrication which my son really enjoyed 'helping' with. A buffer would require a regulator, which I have the parts for, adding another $3 or $4 overall, plus some scrap cable/connectors for the audio interface. An old P2-400 with a sound card should suffice as the train controller, with an old 15inch monitor (all spare parts stuff).
I intend to set output from the audio card to 8 bit audio at about 18.5 Khz sample rate (where 1 sample is around 54 microseconds). That would make demand on the P2-400 minimal.
For other technical reasons I do intend stereo output and may create a second power booster (for something called track reversal loop, where a track loops back onto itself, requiring a reverse of polarity, or at least a synchronization of phase, where an engine transfers back onto track in the reverse direction). This may involve a few proximity sensors, so I can tell when an engine has entered into a reversal loop section. While there, the phase of the power signal must be inverted while the engine is running, which I plan to do by elongating a zero until phase is matched with the destination track, powered by the second audio channel/power booster.
Track reversal electronic devices cost about $45, and handle only one reverse loop. I think I can create 3 'sensors' (one at each entrance into the reversal section, one inside the reversal section) for about $1.50 each, using old cassette tape playback heads (or just loops of small gauge wire around a small iron core - to sense the 'noise' of the motor as it passes over the sensor under the track) and a couple of operational amplifiers to create a signal comparator that can generate a logic 1 which I can sense on one of the 8 lines of the parallel port. For our layout I don't suspect I'd have room for any more than two reversal loops, so two loop sections would be possible, software would otherwise handle the transition using stereo audio output.
If that's not quite clear, here's a clearer description of the problem.
For a short timeslice (say 10 microseconds, where we can consider the polarity at that moment) a train might be moving on a loop that joins the same track that entered the loop (like the loop of a lasso). If the track were really connected this way, the + polarity would end up connecting to the - polarity, creating a short.
So, the loop is cut into 3 sections. This looks, then, like a Y, where the two top legs of the Y are joined by a curve, but not electrically connected.
When the engine moves from part of the Y to the curve, the engine will complete a circuit connection, with it's wheels, between the Y and the curve - but only on one side of the Y at a time. One side as the engine enters the curve, and the other as it leaves.
The entire Y is a single electrical path (one rail +, the other rail -), and part of the 'main' track power - sharing the main track's polarity.
Some people have to rethink that to realize there really is a problem. It ends up that what is a 'right' rail physically connects to the 'left' rail when the curve ends up connecting to the base of the Y, creating a short. You have to envision this shape with two rails and follow the path from one side to the other to realize they would cross-connect.
Thus, the electrical isolation of the curve atop this Y.
At each of the two upper legs of the Y, and proximity sensor would inform the computer that the engine is about to enter the curve, and start powering it (from the second audio channel) in sync with THAT SIDE'S polarity direction relative to the engine's orientation. When the engine jumps the electrical isolation, it will receive power in sync with the polarity of the main track from that viewpoint.
A second proximity sensor will inform the computer when the engine is inside the curve section, meaning it's electrically isolated from the main track. At this time, the second audio channel, exclusively powering the curve section, would extend the zero length of a message until the main track switches phase (it's AC remember), bringing the curve and the main track in phase with respect to the polarity as viewed from the engine's orientation when it re-enters the Y (in what's now the reverse direction).
When the third sensor fires, it means the engine has left, is no longer on the curve section, and that can be powered down (or made available for another engine to enter).
If any other reverse section receives a signal of an engine entering a reverse loop while all this is happening, I'd probably have to issue a 'stop all engines' command and let either my son (or me) give one engine the go ahead manually. If I had full transponders, I could have the computer figure out which engine is there first, and hold the other(s), but that's just too much, especially since the odds are probably low.
Ok, finally, the nature of my inquiry and posting.
Does anyone have enough familiarity with DCC to advise if my plan makes any sense? Is the square wave DCC signal beyond the range of an audio power amplifier (I'm of the opinion it is within the capabilities, given some slight wave shaping care against square wave transitions creating harmonic distortions).
Anyone find the project interesting enough for me to continue the thread as I proceed to create the thing? I expect to get rolling in a month or less.
If you have kids and are curious about the Thomas engines (the 'standard' Thomas toys are wooden trains on wooden tracks), Bachmann makes the engines and can be found through a google search. Although an electric set, with track, can cost around $80 or so, it compares reasonable with the cost of wooden sets ($20 for a wooden engine, non-powered, similar costs for track). The DCC conversion is an electronic project (soldering iron, wire, disassembly - there's a web page of instructions, search Thomas DCC and you'll find it).
Track reversals aren't typically required - you can layout track without them. We have a 3' x 4' train table (intended for the wooden trains), but it's just a little too small for the HO track, even for a simple oval - but a slightly larger plywood sheet on top of the table gives just enough extra space to make it fit. I've found Atlas, the track manufacturer, has a free track layout software (not great, but adequate) - and I've designed a layout including a helix spiral elevator to a second table level 16 inches above the main table, two runs of track at 22" radius turns (with a 19" interior) made with flex track (shaped track - the standard is 18" radius) - and a second level with another layout including a reverse loop.
My son has been making 'city scapes' for years (started by shaping straws into light poles before he was 2), so we're 'decorating' the layout with traffic lights (playdo and LED's), signals and bridge lights (white LED's), street lights (which he now makes out of 6 gauge solid core copper wire) and other 'hand crafted' accessories, including bridges, stations, etc.