Working principle of servo

I was trying to control the servo using just delayMicroseconds() function but the result wasn't so satisfy. As compare to the servo library, the amphere used for the library version is a lot much lesser and the it is more stable.

Library:

  • amphere 0.0++A
  • the shaft is tight, I can't move it

delayMicroseconds():

  • amphere up to 3.0++A
  • the shaft is very lossy, can be easily rotated

CODE of delayMicroseconds():
int x = 20;
const int servo = 9;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(servo, OUTPUT);
delay(3000);
}

void loop() {
digitalWrite(servo,HIGH);
delayMicroseconds(1000);
digitalWrite(servo,LOW);
delayMicroseconds(18000);
}

chunhou:
void loop() {
digitalWrite(servo,HIGH);
delayMicroseconds(1000);
digitalWrite(servo,LOW);
delayMicroseconds(18000);
}

What happens if you try ....

digitalWrite(servo,HIGH);
delayMicroseconds(1500);
digitalWrite(servo,LOW);
delayMicroseconds(20000 - 1500);
delayMicroseconds(1000);

delayMicroseconds doesn't work if called with large arguments - try this:

 digitalWrite(servo,HIGH);
 delayMicroseconds(1500);
 digitalWrite(servo,LOW);
 delay (20);

chunhou:
I was trying to control the servo using just delayMicroseconds() function but the result wasn't so satisfy

For long intervals like that you should not be using the delayMicroseconds() function because it blocks the Arduino from doing other things.

Have a look at how millis() is used to manage timing without blocking in several things at a time. The same technique can be used with micros().

...R

Thank you all, I tried and it worked finally. Yes, because the delayMicroseconds() doesn't work with large arguement.