Building Radio connection between two arduino board

I am recently building the radio connection with 2 x arduino board and 2 x Xbee pro S38 modules, that are respectively connect to one of the board. Let’s say they are respectively functional as transmitting and receiving.

What I managed to do is using transmitting side to send a signal(900mHz RF) every second; on the other side, receiving the signal and print the time by the “unsigned long time” command(or I am not sure what is the exact name). I want to see if the time difference between every two receiving signal at receiving side is exactly 1 second. Unfortunately it ends up with NOT! There will be 1003xxx microseconds(1second + error of 3xxx microseconds ) difference between two signal, which should theoretically be 1000000 microseconds.

Two radio module are in 20cm to each other, so basically distance wouldn’t cause any signal time difference in terms of light-speed transmitting.

Here are the codes I use:

Transmitting side

#include <SoftwareSerial.h>
SoftwareSerial xbeeSerial(2,3);

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

void loop(){
//Serial.write("H"); H is just a randomly used sign, so it doesn't matter what it exactly is
Serial.println("H");
xbeeSerial.write("H");

delay(1000); // transmitting signal every second. 1000milliseconds = 1second

}

Receiving side

int value=0;
unsigned long time;
void setup() {
Serial.begin(9600);
}
void loop() {
if (Serial.available()>0)
{
value = Serial.read();
time = micros();
Serial.println(time);
}
}

I plot this time error by matlab,

Y-AXIS is time error in unit of microseconds, X-AXIS is every record of time difference between two signal,

What I want to know is about the time error, is it possible to get rid of it?
Is there any programming problem?

Thanks

What I managed to do is using transmitting side to send a signal(900mHz RF) every second;

That's less than a single cycle. Did you mean "900 MHz" ?

The timers used have a granularity of 4 us, so getting better than this is optimistic.

Please remember to use code tags when posting code.

It's the hardware. The arduino uses a resonator module instead of a quartz crystal for timing, so the frequency is not exact.

Please edit your post and add the photo as an attachment.

Thanks a lot, I have modified!

Oh, that’s different. Xbee is likely packet based, so there are layers of negotiation and buffering going on between transmission and reception. You can’t expect the transmission to occur in a constant time.