SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos

geoffb's picture

One of my earlier entries:  SMA10 – Build a 17-Function DCC Decoder for about $5 ( http://model-railroad-hobbyist.com/node/19070 ) generated a considerable amount of interest regarding the possible enhancement for controlling Servomotors (Servos). This is my next version of a 17 Channel Multifunction DCC Decoder based on a low cost $2.56 Arduino Pro Mini. This version supports configuring each of the 17 function pins for On/Off (LED/TTL) Control, or Configurable Blinking Control, or Configurable Servo Control, or Configurable Pairs Blinking Control. Yes, that does mean it can support 17 servos, each with rate, start point, and end point setting via DCC CV’s, per pin, as well as new LED configurable functions. Read On. Additional doc found here: http://model-railroad-hobbyist.com/node/19775 There is another decoder version added herein. Look for "New Decoder Version to Control Lighting Groups" in Page 12 of the Comments: http://model-railroad-hobbyist.com/node/19446?page=11   The most recent Update can be found here: SMA20 New Low Cost 17 Channel DCC Decoders with PC Boards & Dual Motor, LED, & Servo Control    http://model-railroad-hobbyist.com/node/24316

Comments

geoffb's picture

@Michael D and Jim B RE: LED Fading

Hi,

Michael, the resistor/capacitor solution can be made to work but has enough problems and adds extra cost that it commonly is avoided. The output circuit of the processor in the Pro Mini doesn't like to drive a heavy capacitive load. I'm going to leave it at that unless you really want the technical details.

Jim's comments are mostly correct but could use a little clarification. LEDs work over a very narrow voltage range, like 2.5 - 3.2 Volts for a modern ultrabrite green LED. An old (1986) red LED might operate over a 1.65-1.9 Volt range-- not much. But the real specification you need to pay attention to is that the brightness of a LED is proportional to the current through the LED, usually maxing out at 20ma for the most common. You can also find a few LEDs that have a maximum current of 10ma and a bunch of the really new ones that want over an amp! I am ignoring those for now.

Since the operating current range (and voltage range) is so small, the common technique to control LED brightness (as Jim pints out) is to vary the duration of the "ON" time at a (usually) constant frequency, hence the LED receives a repeated ON "pulse," and changing the pulse duration changes the perceived brightness of the LED, hence Pulse Width Modulation or PWM. This is not a square wave, which has equal on and off times, and which would create some intermediate brightness point. Also the mechanism in the Arduino using analogWrite is limited to a select set of pins per each different Arduino model because this is a hardware feature.

You may already know that some of the standard Arduino libraries use these hardware functions to control servos, and they are limited to the same pin sets. However, ANY Arduino Digital Output pin can be programmed to generate an appropriate PWM signal, it simply requires more work on the programmer's part. Note, for example, that this decoder can be configured to control 17 servos. It does this exclusive of the hardware PWM features. Remember that this little processor can execute 20,000,000 instructions (or so) a second-- that's a few to play with !

Fading a LED in the decoder was already discussed here:

http://model-railroad-hobbyist.com/node/19446?page=2

Look for @Tom Fading On a LED

There is a small explanation and code to download for a decoder configuration.

The fact that there are several ways to accomplish this, should be a big indicator for the reader that this is a very flexible tool. That is the point to remember, and why it's worth the effort to learn to use it in modeling.

Have fun!  smiley

Best Regards,

Geoff Bunza

 

Hi Geoff, which processor

Hi Geoff,

which processor will be the best for signaling? As I have no experience with different type of Atmel's and Arduino boards, I cannot give you an answer. With your example of fading I've made some tests and it looks good. But when I look to the signal aspects I have no idea how to solve the fact that two LEDs respectively two outputs must be linked. Maybe you have some helpful hints or a program.

Best Regards

Loeter

geoffb's picture

@Loeter re: Signaling

Hi Loeter,

Since your questions have been directed at controlling the lights on a signal mast, I am answering your question in this context, as opposed to controlling signaling logic for a portion or the whole of a layout.

Virtually any of the Arduino boards will handle signal mast control. Any version of the Pro Mini (which I use because of cost and size), and Arduino Uno, Nano, Due, Micro, etc. can do the job too. These versions exist because they were optimized for different purposes. The Uno line has a wide variety of interface boards, called shields, which you can get to do many things including motor control, GPS interfaces, small LCD displays, Bluetooth, BLE, and LAn interfaces, etc -- quite a bit and there are many more. There are differences among these concerning speed, number and kind of interface pins, size, and power consumption. Virtually all the sketches I post will run without modification on the Pro Mini and Uno types and most of the others too. Look for price differences and availability too. You can learn about their feature comparisons here: 

https://www.arduino.cc/en/Main/Products

I'll try to put an example sketch together for you to control multiple output as discussed, with fade, but you will have to wait until I get through the NMRA convention this month. I will need an answer to my last question "To be precise, four function keys (say F0-F3) would control a set of 5 LEDs: 2 red, 1 green, 1 yellow, and 2 white? Does this account for the full pattern?" I will put something together assuming you need to control 5 independent LEDs per signal mast unless you advise otherwise.

Have fun!  smiley

Best regards,

Geoff

 

Signal Aspects

orHello Geoff,

here are the signal aspects and why four funtions are needed.

The abbreviations Hp0...Sh1 were defined by the German Railways and show the aspects:

Hp0 = Stop (two red LEDs)

Hp1 = Clear (one green LED)

Hp2 = Approach slow (one green and one yellow LED)

Sh1 = Clear for Switching (one red and two white LEDs)

As you can see now, four F-Keys are needed.

I hope it helps to understand the funktion of this type of signals.

Best Regards

Loeter

(No subject)

geoffb's picture

@Loeter

Hi Loeter,

OK... it looks like you will need to control 5 independent LEDs (the two White ones are on or off together) with four functions. This should be pretty easy. I am going to assume the "decoder" will function entirely as a manual signal decoder, so out of the 17 controllable digital pins, I will build a configuration so a set of 4 functions can control a configurable group of 5 outputs. This should allow one :decoder" to control 3 signals or signal groups.

Do you really want this to be a function decoder or an accessory decoder?

Sound right?

Have fun!  smiley

Best Regards,

Geoff

Top Solution

Hi Geoff,

you are completely right and I think a function decoder is the right choice. Combined with fading it will show perfect signal aspects. I hope I do not disturbe you too much and I appreciate that you help so much with your deep knowledge.

Best Regards

Loeter  

geoffb's picture

@Loeter

Hi Loeter,

OK, I will run with this definition. 

Please have patience for a couple of weeks until I survive the NMRA national convention. This should not be difficult and I'll work with you until it works for you.

Have fun!  :-)

Best regards,

Geoff

Great! Thanks a lot. Loeter

Great!

Thanks a lot.

Loeter

geoffb's picture

New Decoder Version to Control Lighting Groups w/Fading On/Off

New Decoder Version to Control Lighting Groups of 5 Pins with 3 Groups of 4 Functions w/Fading

Hi All with special attention to Loeter.

I have uploaded a new decoder version which will control 3 Groups of 5 I/O pins (as in for LEDs), with each lighting group having a configurable pin pattern, and each function having a configurable set of lights to turn on and off. When any of the lights/LEDs turn on or off they will do so with a gradual fade, rather than instantaneously.

The folder and Arduino sketch can be downloaded here:
http://model-railroad-hobbyist.com/sites/model-railroad-hobbyist.com/fil...

After unzipping, place the folder into your Arduino folder on your computer, start the Arduino IDE/Editor and load it into your decoder.

In the sketch/program you will find:
byte FPins_Assigned [12][5] = {   // This array defines the pins controlled by each function
    {3,4,5,6,7},  // F0
    {3,4,5,6,7},  // F1
    {3,4,5,6,7},  // F2
    {3,4,5,6,7},  // F3
    {8,9,10,11,12},  // F4
    {8,9,10,11,12},  // F5
    {8,9,10,11,12},  // F6
    {8,9,10,11,12},  // F7
    {13,14,15,16,17},  // F8
    {13,14,15,16,17},  // F9
    {13,14,15,16,17},  // F10
    {13,14,15,16,17}   // F11

Each group specifies the actual IO pins that the respective function will control.
And this:
byte Function_Lites [12][5] = {  // This array defines the Lights/LEDs controlled in each light group per function
    {1,1,0,0,0},  // F0 Hp0
    {0,0,1,0,0},  // F1 Hp1
    {0,0,1,0,1},  // F2 Hp2
    {0,0,1,1,0},  // F3 Sh1
    {1,1,0,0,0},  // F4 Hp0
    {0,0,1,0,0},  // F5 Hp1
    {0,0,1,0,1},  // F6 Hp2
    {0,0,1,1,0},  // F7 Sh1
    {1,1,0,0,0},  // F8 Hp0
    {0,0,1,0,0},  // F9 Hp1
    {0,0,1,0,1},  // F10 Hp2
    {0,0,1,1,0}   // F11 Sh1

Each group here defines which Pins/LEDs will be turned ON/OFF by the respective Function.

When each LED comes ON or turns OFF it will fade On or Fade Off respectively.
Note Bene: Turn Off all functions in a group before turning the next Function in the same group ON.
Change one function at a time. I did not bother with any special overlapping timing here.

The preset configuration should match the German Signaling configuration Loeter had asked for, but
this Decoder can be used and configured to control any groupings you want (within the limits of the definition).

So, in summary... there are 3 groups of 5 pins controlled by 4 functions each. (Loeter requested a function (mobile decoder) configuration too). The fading is (by my eye) a bit better than my last attempt, too.

I will have another decoder version coming soon, dealling with LED control with fading, influenced by direcion too.

Have Fun!  smiley

Best regards,
Geoff

 


>> Posts index


Journals/Blogs

Recent Blog posts: