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

Re: Servo start up

I'm attempting to detect a stall condition by an indirect method--measuring the servo's input current. For ethical reasons (!!) I didn't want to try to find out how Tam Valley does it, so having learned that they have the feature, I thought I should figure out my own method. And I found a rather odd thing: with the digital servos, when they're moving, they draw heavy pulses of current at a 300Hz rate, which suggests that the 50Hz input is just giving an input comand, not controlling anything that actually happens at a 50Hz frequency. Anyway, it seems that these 300Hz current pulses aren't very different in magnitude for unloaded motion versus stall, but the length of the pulses does change quite dramatically. So my design went from an attempted analog current measurement to detection of the pulses (via a transistor base in parallel with a 1 ohm resistor) and then a low-pass filter, and an analog input to the processor. This seems to work quite well for a single servo, but I feel there are too many analog components for a setup with multiple servos, and I'd grudge having an analog input per servo. So now I'm thinking maybe have a single current sensor on the power supply that feeds all the servos, and accept the need to operate only one at a time. Maybe I should do a Youtube video!

Incidentally, one thing that I like much better about the digital servos is that they can creep along at a very slow rate, yet move quite smoothly. When you try to run analog servos at a slow rate, they always seem to move in jerks. It's not very satisfying. 

 

Servos – Analog, Analog Digital, Digital Servo Control Circuits

Due to the various servos, servo controllers, feedback systems and control signals developed, there is some confusion as to what, in the Hobby Community, is referred to as an analog or digital servo and more importantly how they operate. I am going to try to not add to that confusion as even many available references tend to get it wrong or at least add to the confusion. What I do want to do is clarify the two primary control mechanisms and or signals currently in use. Most of the servos and all of the less expensive servos on the market are controlled by digital pulses with the pulse width (Pulse Command) defining the servo position (three wire connections which include power, ground and command signal).

For most servos a 1 millisecond (msec) or less pulse width corresponds to a minimum deflection or rotation of the mechanism and a 2 msec or more pulse width corresponds to a maximum deflection or rotation. Pulse widths between 1 msec and 2 msec are linearly interpolated by the Servo Control Circuit, so a pulse width of 1.5 msec should result with the servo in the center position.

These are the type of servos (referred to by some as analog servos) used with Geoff's decoder. The Servo Control Circuit which receives the position command and feedback and controls the motor can be implemented with analog, digital or a mix of analog and digital circuitry which is the source of some of the confusion regarding servo classification. Some of these servos also have a fourth wire which provides an analog feedback signal which is proportional to the position of the servo.

For more incite into pulse width controlled servos you can check out the SparkFun: https://www.sparkfun.com/videos#all/bMXx25Q5s24 and https://www.sparkfun.com/videos#all/We6t-4wmAMU. The Adafruit Analog Feedback Servos About Servos and Feedback article is not bad either.

Pulse width controlled servos have major accuracy and repeatability problems which resulted in the design of newer breeds of servos. To improve performance the latest variants of pulse width controlled servos can be programmed (and therefor sometimes referred to a digital servos) including minimum and maximum deflection and rotational speed and acceleration (We can compare programming or tuning these controllers to programming decoder CVs). These improved servos still did not provide the performance needed in some applications especially for robotics and advanced aircraft. Enter servos where digital commands are sent to the Servo Control Circuits (ala DCC). Still generally three wire systems with power, ground, but now the third wire carries digital command packets to and in some systems feedback packets from the Servo Controllers. The Servo Control Circuits in all of these controllers are programmable and obviously digital systems. So far none of the posts and comments I have read on the MRH forum have referred to this type of digital servo.

All of these servos types receive and are controlled by digital signals. The Servo Control Circuits (and internal feed back) can be analog, digital or an analog / digital mix, so which servos are analog and which are digital? Your pick!

Ken K

et al - a little catching up

Dave,

Good call on using the LocoNet Railsync signals. Almost all of the DCC cables from the major DCC suppliers include NMRA compatible (S-9.1.2 DCC Power Station Interface) signals for driving boosters, so you are correct that using these signals could be use instead of tapping off the track. These signals should carry less noise and thus be more reliable.

How is the work progressing on the Faller car project? In terms of detecting the location of Faller vehicles, I understood on my last visit to Miniatur Wunderland that they were working on a system to more accurately detect vehicle location. At the time the software was guestimating to about two meters. They were also testing a multi satellite (RF) tracking system for the trains and ships, but I do not remember the manufacturer. Will try to find reference.

John P,

Hopefully my previous comment sheds some light on why you are seeing the 300 Hz noise. The input pulses are simply a command and have little to do with the operations of the motor drive circuit. The 300 Hz is probably being generated by the PWM bridge drivers controlled by the Servo Control Circuit. There will always be some 300 Hz current (the base PWM freq of most of the servos I have are in the k Hz range) as the Servo Control Circuit as most servos do not implement a dead zone.

After the comments regarding transient servo events at power-on, I grabbed five cheep and three more expensive servos to do some testing on. Results to follow.

Michael,

Sorry to hear of your health problems. As an engineer who has in the last eighteen months experienced one silent heart attack, two bradycardia events (one flat line), a quad bypass, one little stroke (also causing many DUH moments) and now forced retirement, I can sympathize with your frustration. Keep asking questions and contact me directly if you need additional guidance (or want to commiserate).

Ken K

HVT Dave's picture

@ Ken K

Ken,

I wish you continued improving health and strength in the face of your personal challenges.

Thank you for confirming my suspicions about the RailSync signal.  

Concerning detecting the Faller cars an explanation is in order.  The circular HO test track has in its center a small roadway for testing Faller cars. Turnouts and stops are accomplished with 9g servos currently controlled by two Tam Valley Quad-Pic controllers.  The cars follow a magnetic strip embedded in the roadway and four Hall Effect Sensors installed in gaps in the mag strip are connected thru an SE8c to JMRI.  The problem is with the Quad-Pics connected to track power, I have on more than one occasion inadvertently changed the Quad programming while programming a loco.

The roadway on the main layout is still in the design phase and would require at least four of the new QuadLN controllers (or 8 Quad-Pics).  And then along comes Geoff with his Arduino Pro Mini decoder, an economical solution to two needs.  Two Arduinos will now be replacing the Quad-Pics on the test track.  One will be DCC connected to RailSync running 5 servos, 4 LEDs and 4 push switches.  The other needs to provide feedback to JMRI so it will be LocoNet with 4 servos, 4 pairs (HIGH and LOW) of LEDs, 4 push switches and 4 HES.  All the parts have arrived but the project boards.

There is a mission statement for the layout and it includes learning new skills, then sharing them with others.  Arduino implementation and coding will definitely meet that goal.

Warmest Regards,

Dave

Dave

Servo speed

Great work, Geoff.

I have made 2 decoders, based on Arduino Uno. Both are working great. I have one question, is it possible to change speed of servos? I am using script for 10 servos.

Thank you for your reply.

Regards from Slovenia, 
Sebastjan

geoffb's picture

@Sebastjan

Hello Sebastjan,

Terrific! smiley  Vesel sem, da se jim dela!   I'm glad you got them working!

If you read: SMA 13 - Update to the 17 Pin Configurable Multi Function Decoder here:http://model-railroad-hobbyist.com/node/19775  you'll find the The 7 Servo 10 LED decoder configuration list down the page. Each servo pin has 5 CV's associated with the servo control. So for example,  the servo on F1 has::

{35, 2},      //F1 Configured as Servo -  0=On/Off,1=Blink,2=Servo,3=Double LED Blink
{36, 1},      // Rate  Blink-Rate,PWM=Rate,Servo=Rate  1 is the slowest
{37, 28},    //  Start Position when F1=0 - OFF
{38, 140},  //  End Position when  F1=1 - ON
{39, 28},     //  Current Position

So you can change the rate for the servo controlled by F1 by changing CV36. 1 would be the slowest and higher would give you a faster transition.

If you want an even slower transition, you can change the sketch (program) with a little caution. Find these lines in the sketch:

void loop()   //**********************************************************************
{
  //MUST call the NmraDcc.process() method frequently
  // from the Arduino loop() function for correct library operation

  Dcc.process();
  SoftwareServo::refresh();
  delay(8);
  for (int i=0; i < numfpins; i++) {

and change the "delay (8);" to "delay(10);" or "delay(12);" etc.

and see if this slows things down enough for you. You can try a higher loop delay here, but the larger the delay will increase the chances of missing a DCC command to the decoder. The DCC command stations usually repeat the commands on the DCC communications bus (track) so it's likely to respond to a repeated command, even if it misses the first. That's why you will need to be cautious as you increase the loop delay here.

Decoder control CV's can be set via DCC commands, but unless you  REMOVE THE "//" in the define statement at the beginning of the sketch, and reload the decoder sketch, every time you power on the decoder it will revert to the programmed "factory" settings. So either change the settings in the sketch the way you want or perform the double load.

Have fun!  smiley

Best Regards,

Geoff Bunza

@geoffb

Hi, Geoff.

Thank you for reply. I have find how to change speed with CV before, but I would like a little slower.
I will try to change the script. 

I am using Arduino Nano V3 with DSmain and Desktop Station controling my trains on layout.
and Yaasan's page, he is author of program and DSmain.

Here are two videos from my small layout
This servo is controling a water pump for steam locomotives
http://www.youtube.com/watch?v=hnppfYpPPAw

on second video I am controling a decoupling system on my layout
http://www.youtube.com/watch?v=5Vl6Nyg2aXs

​Best regards,
Sebastjan

geoffb's picture

@Rob T Re:Femptoduino

Hi Rob,

You bet it's interesting. The Femptoduino is the smallest version of an arduino with all the pins that I've used that you can directly wire to. The Femptoduino in the video is actually on a "carrier" or development board. Here are some more variations that I've tried (each for different reasons):

From Left to Right, Top to Bottom: 2 variations of Pro Mini Boards, the Arduino Uno, Moteino, Femptoduino, Beetle, and 2 variations of Digispark Boards.With the exception of the Digisparks, all these arduinos use the Atnel328P processor, so they can all run the same sketches. The Beetle has fewer pins available for one to connect to. The Digispark uses an Atmel Tiny85 which has 6 pins for connections but also has less memory and fewer functions, but can still run most sketches that modelers might want to use. The Pro Mini Boards come in at the lowest cost of about $2.25 each, last time I checked. The Moteino distinguishes itself as having a 2 way radio transceiver built onto it, which I used in my battery powered locos.The Femptoduino is shown is just the raw board by itself.

Have Fun.

Best regards,

Geoff Bunza

 

geoffb's picture

@Sebastjan

Hi Sebastjan,

Thanks for sharing your work. I bet you will come up with even more ideas for animating your layout! Keep going!

Best Regards,

Geoff

 


>> Posts index


Journals/Blogs

Recent Blog posts: