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 CCS Technical Support

Problem with RF link getting out of sync

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



Joined: 13 Apr 2005
Posts: 6

View user's profile Send private message

Problem with RF link getting out of sync
PostPosted: Mon Oct 17, 2005 8:41 pm     Reply with quote

Hey guys,
I am working on a pretty simple RF link using a Linx 315 MHz transmitter and receiver. I was able to adapt some of the code for Manchester encoding and decoding off this site. I am basically sending 4 commands from one end to the other. Everything works great until you walk outside the transmitting range and lose signal and then come back in. For some reason, the receiver is getting data but it can't ever get the 4 commands like before. Once you power cycle the tranmitter, everything is back to normal. Have any ideas?

Transmitter Code:

Code:

#include <16F818.h>
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP, NODEBUG
#use delay(clock=20000000)
#use rs232(baud=2400, parity=N, xmit=PIN_B0, rcv=PIN_B1)

int1 forwardbutton = 0;
int1 rightbutton = 0;
int1 leftbutton = 0;
int1 resetbutton = 0;

void SEND_DATA(BYTE txbyte)
{
    int i,j,b,me;

    b = txbyte;

    for (i=0; i<2; i++)
    {
        delay_ms(10);
        me = 0;         // manchester encoded txbyte
        for (j=0 ; j<4; j++) {
            me >>=2;
            if (bit_test(b,0) )
                me |= 0b01000000; // 1->0
            else
                me |= 0b10000000; // 0->1
            b >>=1;
        }
        putc(me);
    }
}

void remoteprintf(BYTE c)
{
   //output_low(PIN_B2);
   //delay_ms(3);
   output_toggle(PIN_B2);

    putc(0xF0);
    delay_us(500);
    putc(0xF0);
    delay_us(500);
    putc(0xF0);
    delay_us(500);
    putc(0xF0);
    delay_us(500);

   SEND_DATA(c);

   delay_us(500);   //MAYBE??
    putc(0xF0);
    delay_us(500);

    //output_high(PIN_B2);
}



void main () {
     enable_interrupts(global);

   set_tris_b(0x02);   // 0000 0010 All outputs
   set_tris_a(0x0F);   // 0000 1111 Pins RA0 1 2 3 inputs


   while(1) {
      forwardbutton = input(PIN_A0);
      rightbutton = input(PIN_A1);
      leftbutton = input(PIN_A2);
      resetbutton = input(PIN_A3);

      //inputs are active low
      if(!forwardbutton && !rightbutton)
         remoteprintf(0x52);
      else if(!forwardbutton && !leftbutton)
         remoteprintf(0x4C);
      else if(!forwardbutton)
         remoteprintf(0x46);
      else if(!resetbutton)
         remoteprintf(0x43);
   }
}


Receiver Code:

Code:

#include <16F818.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=2400, parity=N, xmit=PIN_B0, rcv=PIN_B1,ERRORS)

int8 i;

BYTE DECODE_DATA(BYTE encoded) {
    BYTE i,dec,enc,pattern;

    enc = encoded;

    if (enc == 0xf0)    //  start/end condition encountered
        return 0xf0;

    dec = 0;
    for (i=0; i<4; i++) {
        dec >>=1;
        pattern = enc & 0b11;
        if (pattern == 0b01)        // 1
            bit_set(dec,3);
        else if (pattern == 0b10)
            bit_clear(dec,3);       // 0
        else
            return 0xff;            // illegal code
        enc >>=2;
    }
    return dec;
}

void main() {
   char datar,ddl,ddh,datadecode;
     int1 status;

     set_tris_a(0x00);   //0000 0000
     set_tris_b(0x02);   //0000 0010

     disable_interrupts(INT_EXT);
     disable_interrupts(GLOBAL);

     status=0;  //lsb part
     datadecode=0;
     while(1) {

      if (!kbhit()) {
            datar = getc();
            if(datar!=0xf0) {
                ddh=DECODE_DATA(datar);
                if(status==0) {
                     status=1;
                     ddl=ddh;
                }
            else {
                   status=0;
                   ddh<<=4;
                   datadecode=(ddh | ddl);   //makes 8 bit byte

               output_toggle(PIN_A3);  //its getting to this point but there is no match after this when "sync" is lost

                   if(datadecode == 0x46) {   //ASCII for F
                  //go forward
                  output_toggle(PIN_A0);
               }
               if(datadecode == 0x52) {   //ASCII for R
                  //go right
                  output_toggle(PIN_A1);
               }
               if(datadecode == 0x4C) {   //ASCII for L
                  //go left
                  output_toggle(PIN_A2);
               }
               if(datadecode == 0x43) {   //ASCII for C
                  //reset distance counter
                  //output_toggle(PIN_A3);
               }
               }
           }
           }
      }
}
fasteddye



Joined: 13 Apr 2005
Posts: 6

View user's profile Send private message

Wanted to add
PostPosted: Tue Oct 18, 2005 5:49 am     Reply with quote

I have also tried changing the baud rate to 1200 and 4800 with no change in result.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Oct 18, 2005 9:08 am     Reply with quote

In the Tx side add this

Code:


void main()
{
   setup_adc_ports(NO_ANALOGS);   // add this line
   setup_adc(ADC_OFF);                  //
.......
.......
.......
}



We doesnŽt know your hardware. In the transmiter side, PIN_B0 idle state is HIGH,
youŽll need to invert this signal to ovoid the RF transmiter keep modulating RF continuously generating unwanted noise that would block the receiver.



I would change the following function to introduce some pre and postambules STX ETX
and of course in the Rx side youŽll need little changes but this way know exactly when
to validate or ignore the received commands.


Code:

void remoteprintf(BYTE c)
{
    output_toggle(PIN_B2);

    putc(0xF0);
    delay_us(500);
    putc(0xF0);
    delay_us(500);
    putc(0xF0);
    delay_us(500);

    putc(0x02);         //  START OF MSSGE  STX   ***************
    delay_us(500);   
    SEND_DATA(c);
    delay_us(500);   
    putc(0x03);        //   END OF MSSGE    ETX   ***************

    delay_us(500);

}



In the following function, remove this unnecesary delay. This is not a good place
to introduce a delay. Before this you had been modulating data every 500 us, the RF
receiver is getting this sequence to "get in phase", then suddenly stop and wait 10ms
(for nothing) and you loose all the merit impossed by sending a previous "burst" of 0xF0.
This is mandatory to help to stabilize the RF receiver stage wich is expecting a
signal with 0 DC component.

Code:


    for (i=0; i<2; i++)
    {
        delay_ms(10);   //  REMOVE THIS DELAY   *************
        me = 0;            // manchester encoded txbyte
        for (j=0 ; j<4; j++) {
            me >>=2;
            if (bit_test(b,0) )
                me |= 0b01000000; // 1->0
            else
                me |= 0b10000000; // 0->1
            b >>=1;
        }
        putc(me);
    }



Quote:


I have also tried changing the baud rate to 1200 and 4800 with no change in result.


I would work at 1200 bauds while debugging.

Humberto


Last edited by Humberto on Tue Oct 18, 2005 11:10 am; edited 1 time in total
Guest








PostPosted: Tue Oct 18, 2005 9:51 am     Reply with quote

Can you explain this futher because I am not sure I understand:
Quote:

We doesnŽt know your hardware. In the transmiter side, PIN_B0 idle state is HIGH,
youŽll need to invert this signal to ovoid the RF transmiter keep modulating RF continuously
generating unwanted noise that would block the receiver.


Is there a command for inverting the signal or a way to force B0 low when not using it?

Also, do I need to disable ADC on the transmitter and receiver or just the transmitter?
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Tue Oct 18, 2005 10:59 am     Reply with quote

Quote:


Can you explain this futher because I am not sure I understand:



To transmit a command you are using putc(data), if you measure the xmit PIN output (PIN_B0 ) while not transmiting you?ll get a HIGH level - idle state -which is right.
From the RF transmiter point of view, you are enabling the RF modulation, which is not
what you expect.


To solve this:

1) For software UART handler.
#use rs232(baud=2400, parity=N, xmit=PIN_B0, rcv=PIN_B1,INVERT)
The PIC16F818 doesn?t have built-in UART at all, so you can use it.

2) For built-in hardware UART, it is necesary to wire an inverter between the Tx PIN and the RF transmiter.



Quote:

Also, do I need to disable ADC on the transmitter and receiver or just the transmitter?



From the PIC Mid_Range Reference Manual (Page 41):

"On a Power-on Reset, the pins PORTA<4:0> are configured as Analog Inputs
and reads as '0'."



Humberto
Guest








PostPosted: Sun Dec 25, 2005 12:20 am     Reply with quote

Hi,

Whats the need of #include <stdio.h> and <#include <stdlib.h> header file??
If can compile the code without it.....am I doing wrong.

Please help.....thanks
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sun Dec 25, 2005 6:44 pm     Reply with quote

Quote:

Whats the need of #include <stdio.h> and <#include <stdlib.h> header file??

If you are asking if you need both files to run the previous code the answer is no.


Quote:

If can compile the code without it.....am I doing wrong.

To know if you need them, the most common "warning advice" is an error message at
compilation time: "Undefined identifier"
The compiler complain because it does't find the definition of a built-in function used.
In other words, for example if you use the built-in function srand()
you will need to #include <STDLIB.H> where resides the definition for that functon.

Open the C Compiler Reference Manual in Built-In Function section (Page 88-220) and you will see
the library requeriments -if so- for every built-in function.


Humberto
Guest








PostPosted: Sun Dec 25, 2005 11:20 pm     Reply with quote

Hi Humberto,

Thanks for reply...I'm getting no warning at all!! But the problem is...when I compile the above TX code for 16f84a without those two header file... ROM uses is 24% and RAM uses 6%, after adding the header files...it increases to 25% and 18%....then what could be the possible reason??

Thanks again
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