I am trying to program my ESC and to control a motor using PID , but it seems that my PWM has jitter . The sound of the motor is not liniar . Twice in a second he spins faster for a very short time, but i can hear it .
Serial.begin(115200);
Serial.println("Program begin...");
Serial.println("This program will calibrate the ESC.");
motor1.attach(OUT1);
motor2.attach(OUT2);
motor3.attach(PH5);
motor4.attach(PH4);
Serial.println("Now writing maximum output.");
Serial.println("Turn on power source, then wait 2 seconds and press any key.");
delay(2000);
motor1.writeMicroseconds(MAX_SIGNAL);
motor2.writeMicroseconds(MAX_SIGNAL);
motor3.writeMicroseconds(MAX_SIGNAL);
motor4.writeMicroseconds(MAX_SIGNAL);
delay(2000);
// Send min output
Serial.println("Sending minimum output");
motor1.writeMicroseconds(MIN_SIGNAL);
motor2.writeMicroseconds(MIN_SIGNAL);
motor3.writeMicroseconds(MIN_SIGNAL);
motor4.writeMicroseconds(MIN_SIGNAL);
delay(2000);
motor1.writeMicroseconds(1200);
motor2.writeMicroseconds(1200);
motor3.writeMicroseconds(1500);
motor4.writeMicroseconds(1500);
I heard that using analog write will solve my problems , the problem is that i can`t start my esc and control them with analog.Write().
I searched on internet, and there were people saying that analog.write is more stable at jitter than write.microseconds. I am trying to do this quadcopter using FreeRTOS. And i can`t make the PID if i have those variations in PWM.
The Servo library's PWM is a completely different frequency to analogWrite's frequency - there's almost a 1:10 ratio difference, and the chances are your ESC won't like a 500Hz PWM signal.
Even if it does, your resolution will be much worse than with the Servo library.
Can you say, hand on heart, that the values you are writing are not the source of the jitter? (I only ask that because it is impossible to tell from the snippet of code you posted)
The values that i give to the write.Microseconds are fixed for example i give motor1.writeMicroseconds (1500) and i still hear that variation in speed.
What sort of motors are you driving?
What sort of load is on them?
Have you an adequate power supply for the motors?
How much variation in speed is there?
Does it matter?
nikel1992:
The values that i give to the write.Microseconds are fixed for example i give motor1.writeMicroseconds (1500) and i still hear that variation in speed.
A motor with no load is bound to be a bit unstable for the ESC. Try putting a load on it with a prop or something and test again.
I mounted the propellers to the quadrotor but i still have the same problem that increasing of speed. If necesary i can record the sound so someone give an opinion.
nikel1992:
I mounted the propellers to the quadrotor but i still have the same problem that increasing of speed. If necesary i can record the sound so someone give an opinion.
It may different noises, but you haven't answered the question "does it matter?"
The Servo library jitter is because it uses interrupts and the timer0 interrupt will
interfere with the precise timing.
If you are prepared to lose delay(), millis() and micros() then this line will turn off
timer0 interrupts:
TIMSK0 = 0 ;
If that doesn't cure the jitter you might have some interference issues (not impossible
with high current motors nearby).
The PWM outputs are hardware and thus immune from jitter, but only the timer1
output is 16 bit so that only pins 9 and 10 can provide accurate enough timing,
and you have to reprogram the timer hardware to get the right sort of frequency.