Wireless Transmitter Receiver Pair Corruption?

Hey Guys,

I have a KLP Module (transmitter/receiver) pair for sending and recieving bytes between two arduino boards. After filtering out the noise, most of what I receive is great, but every once in a while (20th or so byte) instead of receiving the expected byte I get a different one. Without going into details this byte comes in at the expected time and passes the noise filter (for the sake of this post lets assume its correct but the code is below). This means that the transmitter is sending the wrong number or the reviever is getting the wrong number. Do you know why this could be?

If it helps the noise filter is just two steps. First the transmitter sends 9 coppies of the same byte, then if the reveiver gets 7 of the same byte in a row (except 0) then it counts as correct, there are not very many lost bytes but some of them are getting replaced with the wrong number. This probaby means that either the transmitter is sending the wrong number 9 times, or when the receiver gets the number it is interpreting it the same wrong way every time.

Any Ideas?
Pooh

Transmitter

byte counter;
byte count;
unsigned long time;

void setup(){
  Serial.begin(2400);
  counter = 0;
  count = 0;
  
  time = millis() + 100;
}

void loop(){
  
  
  if(millis() > time)
  {
    count = 0;
    while(count < 9)
    {
      Serial.print(counter);
      count++;
    }
    counter++;
    
    
    time = millis() + 100;
  }
    //delay(2000);
}

Receiver

int incomingByte = 0;

// stores the multiple input we are waiting for
int currentByte = 0;

// stores the number of multiple inputs
int numCurrentBytes = 0;

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

void loop(){
  if(Serial.available() > 0){
    incomingByte = Serial.read();
    
    if(currentByte == incomingByte && incomingByte != 0)
    {
      numCurrentBytes++;
      
      if(numCurrentBytes >= 7)
      {
        Serial.println(currentByte, DEC);
        numCurrentBytes = 0;
      }
    }
    else
    {
      numCurrentBytes = 1;
      currentByte = incomingByte;
    }
  }
}

Sorry I can't help much, as I don't read code too well yet, but I'm interested in the topic so I thought I'd give it a bump & see if that generates any replies.
Just a thought: should that = in the last line of your receiver code be==?

Can't think why that should cause this problem, but who knows?

These types of transmitters/receivers need a pattern of bits to "train" the receiver so that it locks on to the timing. Typically you "wrap" your actual data in a packet that has leading data to train the reciever, your actual data, and finally some kind of error checking or checksum. For training a good sequence is a few 0xAA followed by a few 0x55 characters.

I haven't used this library yet (but I intend to), but you might take a look at VirtualWire (a PDF document).