The TLP434 and RLP434 are basic modulator and de-modulator which reflect the voltage levels at DATAIN pin of transmitter on DATAOUT pin of the receiver. If they had done this perfectly then life would have been easier, but these modules have a very low bandwidth and tend to be noisy and data reliability cannot be guaranteed. So these devices are used along with encoder and decoder to ensure correct data reception.
In this article instead of using the encoder and decoder we use pulse width based data encoding almost similar to NEC protocol used in IR remote controls. The transmitter microcontroller sends the data packet by converting them into pulses of different duration tuned to suit the bandwidth of TLP and RLP modules.
Connections: You would need a normal IO port on transmitter microcontroller to bit bang the data into TLP434 module. On the receiver you will need to measure the pulse width to decode the data, so the DATAOUT of RLP434 module is connected to CCP1 pin of microcontroller. We use the TIMER1 of PIC16F877A in capture mode to measure pulse width.
Here are the circuit diagram used,
TRANSMITTER:
RECEIVER:
Transmitter Code :
{code}
#include <htc.h> #include "LCD.h" #include "UART.h" unsigned short Data[8]; unsigned char channel; __CONFIG( FOSC_HS & WDTE_OFF & CP_OFF & LVP_OFF & CPD_OFF & DEBUG_ON); #define BURST_DURATION 3700 //34000 #define BURST_LOWERBOUND BURST_DURATION-100 // 4147 = 4.5ms #define BURST_UPPERBOUND BURST_DURATION+100 #define BIT1_DURATION 2068 #define BIT1_LOWERBOUND BIT1_DURATION-100 // 1032 = 1.12ms #define BIT1_UPPERBOUND BIT1_DURATION+100 #define BIT0_DURATION 1034 //30000 #define BIT0_LOWERBOUND BIT0_DURATION-100 // 516 = 560uS #define BIT0_UPPERBOUND BIT0_DURATION+100 #define DATA_GAP_DURATION 6000 typedef union { unsigned char Bytes[3]; struct { unsigned short Temperature; unsigned char CheckSum; }Fields; }DataPacketType; unsigned char Temp; void ReadADCCH(unsigned char ch) { unsigned short CheckCounter; Temp = ADRESL; Temp |= (ADRESH<<8); ADRESL = 0; ADRESH = 0; channel = ch; TRISA=0;TRISE=0; switch(ch) { case 0: case 1: case 2: case 3: TRISA = 1<<ch; break; case 4: TRISA = 1<<5; break; case 5: TRISE = 1; break; case 6: TRISE = 2; break; case 7: TRISE = 4; break; } ADCON1 = 0x80; ADCON0 = 0xD3; while((ADCON0 & 0x02) == 0x02); CheckCounter = 0; while(ADIF == 0) { CheckCounter++; if(CheckCounter>100)break; } Data[channel] = ADRESL; Data[channel] |= (ADRESH<<8); } void SendPulse(unsigned short Duration) { RC6 = 0; Delay(Duration); RC6 = 1; Delay(1000); } void IdleLine(void) { RC6 = 1; } unsigned char BitCounter,ByteCounter; void SendPacket(DataPacketType *pDataPacket) { SendPulse(BURST_DURATION); for(ByteCounter = 0; ByteCounter < 3; ByteCounter++) { for(BitCounter = 7; (BitCounter >= 0) && (BitCounter <= 7); BitCounter--) { if( ((pDataPacket->Bytes[ByteCounter] >> BitCounter) & 0x01) == 1) { SendPulse(BIT1_DURATION); } else { SendPulse(BIT0_DURATION); } } } IdleLine(); } void CheckAlarms(void); DataPacketType Packet; unsigned char Send = 0; void main() { TRISCbits.TRISC6 = 0; IdleLine(); //InitUART(); while(1) { ReadADCCH(4); Packet.Bytes[0] = Data[4]&0xFF; Packet.Bytes[1] = Data[4]>>8; Packet.Bytes[2] = Packet.Bytes[1] + Packet.Bytes[0]; SendPacket(&Packet); } }
{/code}
Receiver Code :
{code}
#include <htc.h> #include "Serial.h" #include "LCD.h" #include "UART.h" unsigned char BitCounter = 0; unsigned char ByteCounter = 0; unsigned char BurstReceived = 0; unsigned short wTemperature; unsigned char valid = 0; DataPacketType DataPacket; unsigned char *pData; unsigned short Temp; const unsigned char validMsg[] = {"Valid packet received n r "}; void HandleReceivedBit(unsigned short Duration) { //if(Duration >= BURST_LOWERBOUND && Duration <= BURST_UPPERBOUND) if(Duration > BIT1_UPPERBOUND+3000) { BurstReceived = TRUE; pData = & DataPacket.Bytes[0]; BitCounter = 0; ByteCounter = 0; Print("rnB"); } if(BurstReceived == TRUE) { //if(Duration >= BIT0_LOWERBOUND && Duration <= BIT0_UPPERBOUND) if(Duration < BIT1_LOWERBOUND) { Print("0 "); *pData = (*pData << 1); BitCounter++; } else if(Duration >= BIT1_LOWERBOUND && Duration <= BIT1_UPPERBOUND) { Print("1 "); *pData = (*pData << 1) | 0x01; BitCounter++; } else { //Print("Invalid Data Duration n r "); //PrintNumber(Duration); return; } if( BitCounter >= 8 ) { //Print("8 bits received nr"); pData++; ByteCounter++; BitCounter = 0; } if( ByteCounter >= 3) { //if //( // DataPacket.Bytes[2] // == // (unsigned char) (DataPacket.Bytes[0]+DataPacket.Bytes[1]) //) { Print(validMsg); wTemperature = DataPacket.Fields.Temperature/7; valid = 1; //PrintNumber(DataPacket.Fields.DeviceStatus); //DisplayString(LINE2,"Temp = ", DataPacket.Fields.Temperature/7, DATA_WRITE); /*SetLine(1); WriteLCDData('T');WriteLCDData('e');WriteLCDData('m');WriteLCDData('p'); WriteLCDData(' ');WriteLCDData('=');WriteLCDData(' '); Temp = DataPacket.Fields.Temperature / 7; WriteLCDData(Temp/1000); WriteLCDData(Temp/100); WriteLCDData(Temp/10); WriteLCDData(Temp%10);*/ } BurstReceived = FALSE; pData = & DataPacket.Bytes[0]; BitCounter = 0; ByteCounter = 0; } } }
{/code}
Download the complete project : Click here..!
Also see :
- Low cost and long range RF module-1200 meter/1.2km in India
- Low cost zigbee modules for purchase in India
- TCS230 RGB color sensor operation and Code
- SIM300 SMS and Call Commands