Go Down

Topic: Easiest way to avoid servo twitch on power-up? (Read 6373 times) previous topic - next topic

EngineerWannabe

I'm going to have a servo attached to a valve which has a limited turning arc and it would be great if I could eliminate the power-up twitch that servos give.
From what I understand, if the servo signal is sent before the power then the twitch won't happen or will be unnoticeable.

Could I achieve this from a programming perspective? I could have one of the Arduino's digital pins give power to the servo - so would I tell this pin to supply power a few seconds after the Arduino is powered on?

UKHeliBob

What happens if you don't attach() the servo until you need to move it ?  The attach() is usually done in setup() but doesn't have to be.  You could do it before each servo move and detach() it afterwards or make it a one time event by flagging the attach() the first time that the servo is moved and then not doing it again for subsequent servo moves.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

PaulS

Quote
You could do it before each servo move and detach() it afterwards

It's even easier than that. The servo goes to the last commanded position when attach()ed. What is the last commanded position?

Write a position for the servo before you attach it. What position? Well, you need to keep track of that before you shut the Arduino down, in EEPROM most likely.
The art of getting good answers lies in asking good questions.

PeterH


Could I achieve this from a programming perspective?


You'd need to have a means to switch off power to the servo (a transistor would do the job) and also you would need to know what the physical position of the servo was at startup (so that you don't ask it to jump to a different position). Do you know what the initial position will be?

zoomkat

Quote
it would be great if I could eliminate the power-up twitch that servos give.


Perhaps you should post the particular code you are using that has the twitch issue.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

retrolefty

  Having used hobby servos in R/C models for decades I'm of the opinion that there is no way to totally eliminate servo 'twitching' at intial power-up, it's just the nature of basic servo design. Some will twitch more then others but it's totally normal to see them move a little (or a lot depending). Good programming practice (attaching servo and initializing a starting position early in the setup function may help somewhat, but again it's not always possible to eliminate twitching as the servo is in a undefined state when power is first applied but no valid command pulse being sent. Possibly eliminating the bootloader may shorted up the time to get the servo receiving valid in range commands and possibly shortening the servo initialization period.

Also the practice of detaching a servo (but with power still applied to it) is a undefined state for normal servos, they are just not designed to operate in any defined manner in that state.

Lefty

ovisoftblue

Guys, I found a solution to the twitching servos.

It's simple: servos are made of their circuitry, which consumes only a small amount of current, and their motors, which need serious currents to move.

In your design, you have to implement a high-side switch made with a switching NPN transistor to receive the signal from the Arduino (through a resistor, of course) and a MOSFET, to handle the high current to the servo. The collector of the NPN goes to 5V through a resistor, and the emitter goes to the ground.

The MOSFET gate has to be wired to the NPN's collector, directly, at the junction between the collector and the resistor. The Source pin of the MOSFET goes to the same 5V and Drain goes to the servo's +.

VERY IMPORTANT: in parallel with the servo(s) put a 2200uF electrolytic capacitor.

Between Source and Drain put a resistor to fuel the capacitor while the circuit is shut off. You may not need to, I did, it depends on how many servos you have. Alternatively, you can put a bigger capacitor.

In your sketch, do this:

1. assuming A2 is the pin you assigned for controlling the electronic switch you just built.
2.  #1: digitalWrite(A2, 1);
    #2: digitalWrite(A2,0);
    #3: digitalWrite(A2,1);

That's all. Now, the explanation, for those who didn't get it yet:

#1: the first digitalWrite sends power to the servo and fills the capacitor in the shortest amount of time.

#2: Before the servo can have enough power to move its motor, you shut off power to it, so all that it has available is what's stored in the capacitor, so the servo's "brain" is now active, but can't twitch, as it doesn't have enough power.

#3: Now, before the capacitor depletes and the servo is left out of conscience (and twitches to subsequent power-ons), you reapply power with line #3. As a result, it won't twitch anymore.

This works 100%.

If it doesn't, or you don't know how to do the circuit, you can buy a ready-made high-side power switch and do it with that. The capacitor is the most important in this equation.

And, don't forget to visit my site, www.greenoptimistic.com.

Robin2

I seem to have solved the problem by wiring a 4k7 resistor between the servo signal and ground wires. (Not my idea, I got it on another forum).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

zoomkat

The twitch could be caused by the arduino chip if the arduino pins have a positive blip when the chip boots up.
Google forum search: Use Google Search box in upper right side of this page.
Why I like my 2005 Rio Yellow Honda S2000  https://www.youtube.com/watch?v=pWjMvrkUqX0

ovisoftblue

Robin2, I'll test it - if it works, it's an even more brilliant solution than mine! :) However, I tried putting the control pin to zero and then powering the servo, didn't work.

Zimbu

Guys, I found a solution to the twitching servos.

It's simple: servos are made of their circuitry, which consumes only a small amount of current, and their motors, which need serious currents to move.

[snip]

I know this thread is very old, but has anyone else ever tried this solution from ovisoftblue?

It seems like a quite interesting solution to a problem that has been discussed in hundreds of different threads with no real solid answer found yet.

EntRy

And now the thread is even older... But I found a simple solution that works for me, based on ovisoftblue's concept.

I just placed a resistor between the power supply and the servo, so the electronics receive enough power, but the motor doesn't. Then, after a short delay, a relay is switched on to shunt the resistor. The servo now does not move at all anymore.

I am using the MG996R servo at 5V and a 150 ohms resistor did the job.




franciscorp

Sorry for disturbing the eternal sleep of this really old thread, but...
I found that the resistor solution given by Robin2 works, but instead of connecting to ground, I connected a 10K resistor between the servo data pin and 5V.
Kind of pull-up resistor, no transistors, mosfets or relays involved.

Zimbu

Thanks for this info. The previous solutions never worked for me so I finally gave up. Whenever I plug in my project, the servo still jumps around weirdly for a while. Sometimes it never stops and I need to restart again. Sometimes it goes away about 20 seconds or so.

I will definitely give your solution a try!

JCA79B

#14
Mar 23, 2019, 02:52 pm Last Edit: Mar 23, 2019, 02:56 pm by JCA79B
Save the current servo position to EEPROM before shutdown, then on startup, in setup:

Code: [Select]
void setup()
{
  int pos = 0, eeAdd = 0;  
  EEPROM.get(eeAdd, pos);
  servo.write(pos);
  servo.attach(9);

}


https://www.arduino.cc/en/Reference/EEPROM

Go Up