I had been using VirtualWire for my RF links.
It's a very usefull and accurate program. It never has any problems when the TX and RX
processors have Xtal clock generators.
I did have problems when I use a ATtiny85 as RX with an internal clock.http://arduino.cc/forum/index.php/topic,60239.0.html
No matter how well I tune the TX or RX programs when ambient temperature changes
we can still get the occasional dropouts.
It seems to me that the operation of VirtualWire is too sensitive to clock frequency.
I wrote a simple class based on Manchester encoding.
The class has 5 functions:
MANCHESTER.SetTxPin(char pin); //set the arduino digital pin for transmit. default 4.
MANCHESTER.Transmit(unsigned int data); //transmit 16 bits of data
MANCHESTER.SetRxPin(char pin); //set the arduino digital pin for receive. default 4.
unsigned int MANCHESTER.Receive(void); //receive 16 bits of data. 0 if times out.
MANCHESTER.SetTimeOut(unsigned int timeout); //set timeout in ms. default blocks.
The code is based on the Atmel Corporation Manchester
Coding Basics Application Note.
I did not use any of their code but the program follows closely their operation.http://www.atmel.com/dyn/resources/prod_documents/doc9164.pdf
Quotes from the application note:
"Manchester coding states that there will always be a transition of the message signal
at the mid-point of the data bit frame.
What occurs at the bit edges depends on the state of the previous bit frame and
does not always produce a transition. A logical “1” is defined as a mid-point transition
from low to high and a “0” is a mid-point transition from high to low.
I use Timing Based Manchester Decode.
In this approach we will capture the time between each transition coming from the demodulation
Timer 2 is used with a ATMega328. Timer 1 is used for a ATtiny85.
Timer 2 in the ATMega328 and Timer 1 in a ATtiny85 is used to find the time between
each transition coming from the demodulation circuit.
Their setup is for normal count. No connections. No interupts.
The divide ratio is /256 with 16 Mhz the 328 and /128 for the 85 with a 8 Mhz clock.
This gives 16 usec per count.
The code gives a basic data rate as 1000 bits/s. In manchester encoding we send 1 0 for a data bit 0.
We send 0 1 for a data bit 1. This ensures an average over time of a fixed DC level in the TX/RX.
This is required by the ASK RF link system to ensure its correct operation.
The actual data rate is then 500 bits/s.
The library has two examples:
#define TxPin 4 //the digital pin to use to transmit data
unsigned int Tdata = 0; //the 16 bits to send
MANCHESTER.SetTxPin(TxPin); // sets the digital pin as output default 4
}//end of setup
}//end of loop
#define RxPin 4
MANCHESTER.SetRxPin(RxPin); //user sets rx pin default 4
MANCHESTER.SetTimeOut(1000); //user sets timeout default blocks
Serial.begin(9600); // Debugging only
}//end of setup
unsigned int data = MANCHESTER.Receive();
}//end of loop
Using an ATtiny85 with internal 8 Mhz clock as the RX I have found that I dont have any dropouts.
Download manchester.zip from:http://code.google.com/p/mysudoku/downloads/list