PWM Signal Jitter from RC Receiver.

Hello,
I have been trying to read values from an RC receiver to be able to control servos through the arduino. The signal itself from the receiver is not jittery as if I directly connect the servo it works well, but when I try to get the arduino to read it, it fluctuates and jitters quite a bit, almost 30 milliseconds in the 1000 to 2000 range of the PWM. This little amount causes
It would be great if I could have some help, as this is the root of many problems.
Thanks!

Here is the code to read the signal:

const int ElevatorPin = 6;

void setup() {
 Serial.begin(9600);
}

void loop() {
int StickPosition = pulseIn(ElevatorPin, HIGH, 25000);
Serial.println(StickPosition);
delay(5);
}

i don't know. and presumably you mean 30 usec (not msec)

i found that pulseIn() (wiring_pulse.c) calls an assembler routine, countPulseASM (wiring_pulse.S).

the only things that I can think of affecting this are an interrupt and possibly the resolution of usec counter. So you could try disabling interrupts (noInterrupts() and interrupts()

How much have you tried changing in your sketch? Have you tried changing the delay() value? Try a higher baud rate?

gcjr:
the only things that I can think of affecting this are an interrupt and possibly the resolution of usec counter. So you could try disabling interrupts (noInterrupts() and interrupts()

Interrupts will definitely affect the time keeping of the pulseIn() function. The Serial.println(StickPosition) call will cause interrupts from the Serial background tasking.

As in reply #1 masking interrupts should mitigate this effect, but there is the potential that the serial output buffer will back up and ultimately give garbage output. You could also make the delay(5) longer or increase the baud rate in Serial.begin() so that the serial output is completed before the next call to pulseIn().

In the absence of interrupts, pulseIn() should resolve to about 1 uS, so if you still see the problem after trying the above then perhaps there's an issue with the pulses being measured, such as a slow rise and/or fall time.