Go Down

Topic: jittery servos (Read 1 time) previous topic - next topic

chopperaddict

Hi everyone
I am designing some model railway electronics using several Uno and Megas. I am no expert by any means.

I have written my code and it all works as expected, and I have tried connecting the servos to both PWM and Analogue output pins without success. I have preset the inputs and  outputs using Pinmode()

When my code comes to move the servo (which in its turn switches a point) the servo does move, but then sits there "jittering" quite badly.  I have tried the same servos running under the example servo sketch and they run smoothly.

I have tried using .write() and .writeMicroseconds(), both give the same result.

Here is a sample of one branch of the switching operation, all the other code simply records what is happening and sets a bunch of variables, including a few that I HAVE ADDED to the Servo.h file to help me control the system. They are :
 // My own internal class variables
  // to make processing much easier.
   byte currMode = 0;            // added IGT 6/2/2018
   byte branchAngle = 0;             // added IGT 6/2/2018
   byte mainAngle = 0;             // added IGT 6/2/2018
   byte pointNo = 0;            // added IGT 6/2/2018
   byte isActive;            // added IGT 6/2/2018
 
The servos themselves are held in an array, hence servos
  • .......


Here is the code sample :
Code: [Select]

 switch (buttonSelected)
         {
            case 1:
               sprintf(gbuff, "Adjust Mode is now %s!", pointAdjust ? "ON" : "OFF");
               Serial.println(gbuff);
               resetActiveFlag();   // set all other points to non active first
               pointMode = MAIN;
               servos[1].writeMicroseconds(MAINANGLE);
               servos[1].isActive = true;
               servos[1].currMode = MAIN;
               sprintf(gbuff, "point 1 switched to MAIN");
               Serial.println(gbuff);
               sprintf(gbuff, "Track [%d] selected\n", buttonSelected);
               Serial.println(gbuff);                 
               sprintf(gbuff, "Track %d selected correctly !", buttonSelected);
               Serial.println(gbuff);
               ACTIVEPOINT = 1;
               ACTIVEMODE = MAIN;
               ACTIVEANGLE = MAINANGLE;             
               break;
           


I really hope someone can come up  with a reason for this servo jitter ?

Thanks

Ian

vinceherman

#1
Feb 09, 2018, 02:52 pm Last Edit: Feb 09, 2018, 04:09 pm by vinceherman
Hi Ian,
Can you post the entire sketch?  Seeing the whole thing helps us identify potential issues.
Is it too big to make sense of easily?  Try removing  other pieces of your sketch until you get down to the bare minimum that illustrates your poor servo behavior.

I am pretty sure you already confirmed this in past posts covering other questions on this project, but to make sure we all have the best info, how are the servos powered? (best if through a separate supply with common grounds with the arduino)

And PICS!!!  Really.  any train layout, especially one in progress, is fun to look at!

jremington

About 95% of servo and motor problems reported on this forum are due to inadequate power supplies. For servos, use a separate, 5-6V supply capable of supplying 1 Amp per servo. Connect all the grounds together.

chopperaddict

Thanks for replies guys.

As far as servo power, I am using a "lab style" DC power supply unit that can easily provide loads of amps for the servos.  I do ALL have the grounds connected (PS and Arduinos)

The sketch is in 5 files and compiled comes to 124,500 bytes, so............. A little too large I think for showing here.

After I posted my original message, I kept researching and one person suggested putting a 100 pF cap across the 5v Power supply lead to each servo.  Sadly it made no difference, even with a 4000 pF cap in place

Anoother suggestion made by several people was to attach the servo, write to it, and then detach it again.  That meant a lot of work for my code, and loosing my special .h entries, but I tried it for a couple of the switches, and YES, it worked.

But I would far prefer to have all servos permanently connected if possible, so my actual problem still exists.

It seems to me that the issue has to do with spurious signals on the servo wires.  My button connections to set the switches (servos) are all pulled LOW with resistors, I have not done the same with the servo output pins ?

As to photos of the layout, sure, I am quite happy to do so, but there must be a better place for me to put them up to ??

jremington

#4
Feb 10, 2018, 06:29 pm Last Edit: Feb 10, 2018, 06:33 pm by jremington
Quote
one person suggested putting a 100 pF
Either a typo, or you misread it. pF=picoFarads, an extremely tiny amount of capacity, so try 100 uF (microFarads) or larger. But all that does is make up for an inadequate or unacceptably noisy power supply.

You should not need attach/detach.

Quote
I have tried the same servos running under the example servo sketch and they run smoothly.
Then something is wrong with your code.

chopperaddict

#5
Feb 10, 2018, 06:55 pm Last Edit: Feb 10, 2018, 07:01 pm by chopperaddict
Sorry, it is a typo, it should read uF, not pF.

But they made no difference, so I guess that rules out the "noise" issue ? I agree I should NOT need to have to attach/detach every time I access them, and I really do not want to do that.  That is why this thread is ongoing......

I cannot quite see how my code can be wrong as such, it simply attaches all 7 servos in a for loop in setup(), and  then uses them (basically .write()) as required, and that is when I get severe jitter from them.  The servo objects that are attached are held in an array, and then accessed via that array to use them.

jremington

#6
Feb 10, 2018, 07:09 pm Last Edit: Feb 10, 2018, 07:12 pm by jremington
By far the most likely explanation for jitter is that your power supply or wiring is inadequate. Put a scope on the power leads to see the voltage drops.

You don't have these servos on a breadboard, of course, and are using soldered connections. Breadboards cannot handle high current.

chopperaddict

Right now they (well, one actually) is plugged into the Mega for its control with a jumper lead, but the power connections are indeed soldered directly....

TomGeorge

#8
Feb 11, 2018, 12:13 pm Last Edit: Feb 11, 2018, 12:14 pm by TomGeorge
Hi,

How many servos are you controlling?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Write some code just to control your servos, make them all sweep.
But only connect one servo and try it.
Turn power off and add a second servo and try it.
Turn power off  etc etc.

Check to see if you get any jitter that way.

The Arduino gnd and the servo power supply gnd have to be connected together so you have a gnd reference for the servo input signal.

Monitor the servo power supply with your DMM.

What current is you powersupply?
What are the make/model of your servos?

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

chopperaddict

#9
Feb 11, 2018, 02:03 pm Last Edit: Feb 11, 2018, 02:10 pm by chopperaddict
Hi Tom

Lots of requests there, so a bit of clarification may help ?

Right now I am only using a single servo to test the system, changing pins to check the code works on each output, so I am only powering a single servo from my external lab power supply.

Attached are a JPG of my Fritzing layout, plus the fzz file if it helps ?

Oooops, I cant send an FZZ and my JPG is too large.  I will play with image and post separately

My power supply can provide up to 20v and around 12 amps, so should be enough ?

Servos are cheap and cheerful SG90 used on many aircraft and helis.  All test out correct when connected to an rx and tested with a 2.4Ghz Tx.  No jitter at all.

DMM shows a max of 0.03 millamps being drawn by the servo when switching

I hope that covers your questions Tom ?


chopperaddict

heres the PNG image promised of the fritzxing diagram I have prepared. :-) or I hope so....

wildbill

All test out correct when connected to an rx and tested with a 2.4Ghz Tx.
What does this mean? I'm also a little suspicious of your mention of AnalogWrite and the PWM pins earlier.

Can you try your servos with some of the examples from the reference e.g. Motor Knob. Do you get jitter now?

chopperaddict

#12
Feb 11, 2018, 03:03 pm Last Edit: Feb 11, 2018, 03:35 pm by chopperaddict
Hi Wildbill

I am not sure what the confusion on pintypes is ? I tried using both PWM and analog pins as output for the servo control to see if there was any difference - there wasn't

My reference to the 2.4GHz is radio control talk, where these servos are widly used.

I have tested the standard example and as reported previously, there was no jitter.

Does that clarify it ?

wildbill

So that suggests that your code or wiring are your problem. Do you have long wire runs to where your servo is located? If so, does your jitter free testing replicate that?

I'd take the physical setup where the jittery symptoms are observed and make a copy of your program and then remove all you can from it to try and isolate what's wrong - you've apparently established that the servos are ok.

chopperaddict

Hi Wildbill

Yes, I think my testing has established the servo is OK

The servo wire length is identical to the test using the sample code.

Obviously my current setup has to make use of a few breadboard connections, as shown in my Fritzing diagram, but I have built an adaptor board that uses all soldered connections between buttons and pulldown resistors.  The connections from this to the mega are made using standard Dupont cables, with a pin header being soldered onto my connection board.

The only "suspect" connections maybe the ground interconnection, and the fact that the servo power comes via Dupont connection from the breadboard into the servo connector plug.

I will try to make some of these more "permanent" in my testing sequence and report back.

Go Up