CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Simply and comprehensive Manchester encoding/decoding routin

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
manoel_filho
Guest







Simply and comprehensive Manchester encoding/decoding routin
PostPosted: Thu Apr 24, 2008 5:38 pm     Reply with quote

Hy Friends.

I really need fast help for this, I already done a lot of things with PIC’s, but none with communicating any type.

I am tired to search internet for comprehensive code to do only two relatively easily tasks, in a separate devices.

1 - A transmitter that sends 40 bits by RF, with one of this cheap FSK transmitter modules.

2 - A receiver that understands that I am calling him.

The rest I can handle and develop without any problem.

These 40 bits I pretend to send is performed with 5 bytes that means:

byte_0 = may be a preamble;

byte_1 , byte_2 and byte_3 = address to reach one of the receivers, yes there will be a lot of them.

Byte_4 = may be I use this for future, to send some commands to the receivers.

Byte_0, I think, will always be equal to 0xff;

Byte_1, 2 and 3 will have their value changed depending of what is the receiver I want to aim. Will be very helpful if I am in a routine, chose something, press one button, change these bytes values and set a flag to start the transmission.

After the receiver has been reached, I will send the byte_4.

For this, I use a 16f628A in both devices, running at 4Mhz internal oscillator.

Best regards.
foodwatch



Joined: 18 Apr 2006
Posts: 66

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Apr 27, 2008 8:25 pm     Reply with quote

You do not mention the type of rf module you are using. I use the Linx Technologies series of OOK (on-off keying) instead os FSK. The code then becomes simple RS232 code with a few additions:

1) Send data using ascii hex instead of binary. This leaves all the remaining binary codes available for control use.

2) Send a unique string to signal the beginning of valid data as most RF receivers ouput lots of noise and unwanted signals causing unnecessary interrupt activity.

3) For some RF modules data(garbage) is present even when no signal is present. A simple analog squelch circuit that open only with a real signal ussing the RSSI pin of the receiver if it has one.

4) Use a checksum to validate the integrity of the data. This helps weed out bad data. In my system I actually send a sequential number from each wireless sensor so I can tell if a transmission is missed.

These are some of the things I do with my product line. You don't mention distances needed. The best wireless modules I have used are from Linx Technologies as I mentioned before. They are available in 418, 433 and 900 Mhz versions. All you need is 3.3v and an antenna.

Hope this all helps...
foodwatch



Joined: 18 Apr 2006
Posts: 66

View user's profile Send private message Yahoo Messenger

PostPosted: Sun Apr 27, 2008 8:28 pm     Reply with quote

You do not mention the type of rf module you are using. I use the Linx Technologies series of OOK (on-off keying) instead os FSK. The code then becomes simple RS232 code with a few additions:

1) Send data using ascii hex instead of binary. This leaves all the remaining binary codes available for control use.

2) Send a unique string to signal the beginning of valid data as most RF receivers ouput lots of noise and unwanted signals causing unnecessary interrupt activity.

3) For some RF modules data(garbage) is present even when no signal is present. A simple analog squelch circuit that open only with a real signal ussing the RSSI pin of the receiver if it has one.

4) Use a checksum to validate the integrity of the data. This helps weed out bad data. In my system I actually send a sequential number from each wireless sensor so I can tell if a transmission is missed.

These are some of the things I do with my product line. You don't mention distances needed. The best wireless modules I have used are from Linx Technologies as I mentioned before. They are available in 418, 433 and 900 Mhz versions. All you need is 3.3v and an antenna.

Hope this all helps...
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Mon Apr 28, 2008 6:37 pm     Reply with quote

Thanks for your help foodwatch.

I am manoel_filho, I am facing some trouble to log-in with my original name, I trying to fix this with the forum administrator. Rudy is my dog's name. (one of my best friends)

Ok, let me explain a little bit better.

I am using a FSK modules, 433Mhz. like that´s from telecontrolli, the problem is that I’m not quit so sure that I can find this OOK modules in Brazil so easily, and yes, the garbage is present all times, I can see it by putting a LED on the receiver output. I will try to find out if I can get these modules.

I am working very hard around jmann’s code, http://www.ccsinfo.com/forum/viewtopic.php?t=22525, but like I explained before, I am not so familiar with PIC communication.

The transmitter routine "seems" to work fine, but the receiver routine is not working, I made a test to see if the RS232 incoming interrupt is working, by putting a simple LED to turn on when the code comes thru it, but no answer. I run the SIM simulator and the code seems to be lost, no WDT occurrence.
Here are my receiver code, based on jmann's routine:
Code:
#include <16f628a.h>
#fuses INTRC_IO, WDT, PROTECT, NOBROWNOUT, NOMCLR, CPD, PUT , NOLVP   
#use delay(clock=4000000, RESTART_WDT)
#use rs232(baud=1200, xmit=PIN_b0, rcv=PIN_b1, ERRORS, STREAM=Wireless)
#use fast_io(a)
#use fast_io(b)
#byte porta = 0x05
#byte portb = 0x06
#byte txsta = 0x98
#byte rcsta = 0x18
#byte rcreg = 0x1a
#bit trmt = txsta.1
#bit txen = txsta.5
#bit oerr = rcsta.1
#bit cren = rcsta.4
#bit spen = rcsta.7

#bit led=porta.0

int page=0;
int LastRXTime=0, time=0;
int rx_byte_0, rx_byte_1, rx_byte_2, rx_byte_3, rx_byte_4;
char manchester[16]={
   0b01010101, //0
   0b01010110, //1
   0b01011001, //2
   0b01011010, //3
   0b01100101, //4
   0b01100110, //5
   0b01101001, //6
   0b01101010, //7
   0b10010101, //8
   0b10010110, //9
   0b10011001, //A 10
   0b10011010, //B 11
   0b10100101, //C 12
   0b10100110, //D 13
   0b10101001, //E 14
   0b10101010}; //F 15
static int MANerror;
byte MANencode1(byte ByteIn)
   {
      return manchester[(ByteIn&0xf0)>>4];
   }
byte MANencode2(byte ByteIn)
   {
      return manchester[ByteIn&0x0f];
   }   
byte MANdecode(byte ByteToDecode1, byte ByteToDecode2)
   {
      int i, j, part1, part2;
    for(i=0;i<=15;i++)
    {
    if(manchester[i]==ByteToDecode1)
    break;
    }
   if(i==16)MANError=1;
   for(j=0;j<=15;j++)
    {
    if(manchester[j]==ByteToDecode2)
    break;
    }
   if(j==16)MANError=1;
   return (i*16 + j);
   }
void main()
   {
   set_tris_a(0b00000000);      
   set_tris_b(0b00000010);
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_RDA);
loop:
   while(true)
   {
   restart_wdt();
      }   
goto loop;
}
#int_RDA //Data Waiting in USART RX Buffer
void RecieveWireless()
   {
      static int WirelessData[12];
   static int RXModeByte;
      int data, checksum;
data=RCREG;     //Get Data From USAART RX Buffer
   led=1; //put this to verify interruption, but dosen't work.
      if (OERR) //Buffer Underrun
         {
         CREN=0; //Reset Usart reciever
         CREN=1;
      led_verde=1;
         return;
         }
   if (data==0x00)   // wait for the start byte -  anytime the USART Sync Bit is
        {
        RXModeByte=1;  // encountered, restart the recieve process
      led_amarelo=1;
        return;
        }
Switch (RXModeByte)
   {
      Case 0:
         break;
      Case 1:
            if (data==0xfe)   // Start Byte, now Wait for data
               {
               RXModeByte=2;  // begin waiting for data bytes
               LastRXTime=time;
               }
            else
               RXModeByte=0;  // not start byte, go back to wait for start.
            break;
      Case 2: //rx_byte_0
      Case 3:
      Case 4: //rx_byte_1
      Case 5:
      Case 6: //rx_byte_2
      Case 7:
      Case 8: //rx_byte_3
      Case 9:
      Case 10: //rx_byte_4
      Case 11:
     Case 12: //checksum
      Case 13: 
            WirelessData[RXModeByte-2]=data;  // Read in bytes, one at a time.
            RXModeByte++;                     // Increment count
            if (RXModeByte==14) //After all 13 databytes are recieved
               {
               RXModeByte=0;   //
               MANerror=0;      //reset error bit before decoding
               rx_byte_0=MANdecode(WirelessData[0],WirelessData[1]);
               rx_byte_1=MANdecode(WirelessData[2],WirelessData[3]);
               rx_byte_2=MANdecode(WirelessData[4],WirelessData[5]);
               rx_byte_3=MANdecode(WirelessData[6],WirelessData[7]);
               rx_byte_4=MANdecode(WirelessData[8],WirelessData[9]); 
               checksum=MANdecode(WirelessData[10],WirelessData[11]);
              if (!MANerror && ((int)(rx_byte_0 + rx_byte_1 + rx_byte_2 + rx_byte_4) == checksum ))     //Check For Errors:
                  {  //When no errors exist:
                    if(rx_byte_0==0x10)led_verde=1;
                    if(rx_byte_1==0x20)led_vermelho=1;
                    if(rx_byte_2==0x30)led_amarelo=1;
                    if(rx_byte_3==0x40)led_verde_1=1;
                    if(rx_byte_4==0x50)led_vermelho_1=1;
                  }
               else
                  {  //Errors Exist
                  }
                  //Optional:
                  //output_toggle(LEDwireless); //blink power LED with wireless packet data
            }
            break;
      default:
         RXModeByte=0;
         break;
   }
   return;
}

Please see if you can help me.

Regards.
rudy



Joined: 27 Apr 2008
Posts: 167

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Tue Apr 29, 2008 10:51 am     Reply with quote

Ok foodwatch.

I found the Linx Representative in Brazil, and now?

What module type do you recommend to acquire?

Can You help me on these codes?

Regards.

Manoel.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group