Hi!
I've written a program that reads the signal from a 40MHz rc-receiver and controls a servo. If the servo is connected (data-pin), the input signal jitters about 1ms. The problem still exists if i only connect a LED to the output pin. But if nothing is connected, the signal is stable.
This is my Code:
#include <Servo.h>
boolean RC1InputReady = false;
int RC1PulseStartTicks = 0;
int RCVal1 = 0;
Servo servo1;
int i;
void setup()
{
servo1.attach(6);
attachInterrupt(1,rc1,CHANGE);
Serial.begin(9600);
}
void loop()
{
if(RC1InputReady)
{
RC1InputReady = false;
Serial.println(RCVal1);
//servo1.writeMicroseconds(RCVal1);
}
servo1.write(map(RCVal1,1000,2000,0,180));
}
void rc1()
{
// did the pin change to high or low?
if (digitalRead( 3 ) == HIGH)
{
// store the current micros() value
RC1PulseStartTicks = micros();
}
else
{
// Pin transitioned low, calculate the duration of the pulse
RCVal1 = micros() - RC1PulseStartTicks; // may glitch during timer wrap-around
// Set flag for main loop to process the pulse
RC1InputReady = true;
}
}
I still don't know, what exactly the problem was, but changing the power cord did the trick. The wires are now a bit shorter. Is it possible that they catched up any interfering signals?
Are there any possibilities to filter those signals?
Well, there's nothing special about the supply circuit. Just a 5V 3A voltage regulator for servo, receiver and µC on a breadboard. The power source is either a 9V AC-adaptor or a 7.4V LiPo-battery.
A servo or other power hungry/noisy device should not be put on the same regulator as the microcontroller. In fact servos are usually connected more directly to the power raw DC power supply. Servos have their own internal regulation. The only limitation is the voltage tolerance of the servo which is model/vendor dependent. Almost all can handle 7volts & most work fine at 9 volts.
Servos contain electric motors. Motors are VERY electrical noisy. Some degree of isolation from the Arduino is recommended.