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

what is the problem with my manchester en(de)coding program?
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Guest








PostPosted: Mon Feb 28, 2005 4:21 pm     Reply with quote

Do I need to change the send date (decoding method), or just keep it that way, and using UARD on the receiver side?
Humberto



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

View user's profile Send private message

PostPosted: Mon Feb 28, 2005 6:11 pm     Reply with quote

You must use both functions:

In the Tx side

Code:

int8 j;
   
 while(1)
        {
         putc(0xF0); // 0b11110000 
         putc(0xF0); // Sync pulses used in the receiver side to wake up
         putc(0xF0); // Note also that 11 and 00 are forbiden according to
                     // Manchester rules, but they will be usefull as a 
                     // Data Preamble.
         for(j='A'; j<='D'; j++)
            {            // 'A' 'B' 'C' 'D'  = 8 bytes encoded           
              SEND_DATA(j);
            }
         putc(0x0F); // 0b00001111
         putc(0x0F); // Note also that 00 and 11 are forbiden according to
         putc(0x0F); // Manchester rules, but they will be usefull as a 
                     // Data Postamble.
         delay_ms(2000);
        }               



In the Rx side:

Code:


int8 Rx_buffer[15];
int8 data, index, j;
int8 some_char_recved;
 
 while(1)
       {
        if(kbhit())
          {
           do
             {
              data = getc();
              if(data==0xF0)
                {index = 0;}
              else
                {index++; }
             
              if(index>=15)
                {some_char_recved = TRUE;}
               
              Rx_buffer[index] = data;
                               
             }while(!some_char_recved);
          }

    if(some_char_recved) 
      {
       for(j=0; j<=15; j++)   // Print out the encoded receiver buffer
          {
           printf("%X", Rx_buffer[j]);
          }

       for(j=0; j<=15; j++)
          {                          // Print out the received Data decoded
           data = Rx_buffer[j];
           if((data !=0xF0) && (data != 0x0F))
             {
              data = DECODE_DATA(Rx_buffer[j]);
              printf("%C", data);
             } 
          }
        some_char_recved = FALSE;
       }
   }


Not tested nor compiled. Writted on line.

Humberto
Guest








PostPosted: Mon Feb 28, 2005 6:36 pm     Reply with quote

so in this way, I have to use rs232 RCV, TX pin, right? no need to define another pin as TX and RCV?
Humberto



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

View user's profile Send private message

PostPosted: Mon Feb 28, 2005 8:27 pm     Reply with quote

You must use rs232 in the regular mode, but:

In the Tx Side, Tx_PIN should be wired to TWS434 input.

In the Rx Side, Rx_PIN should be wired from RWS434 output.

Be sure that the iddle state of the receiver is HIGH,

if not reverse the START bit detect and the decoding bit test:
Code:
 
        if(kbhit())                   if(!kbhit())           
          {                             {
           .....                          .....
          }                             }


Humberto
Guest








PostPosted: Tue Mar 01, 2005 4:48 am     Reply with quote

Sorry, I forgot this:
Code:

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, STREAM=Comm) 
#use rs232(baud=2400, xmit=PIN_B1, rcv=PIN_B0, STREAM=RF)


In Tx side replace
Code:

    putc()   by fputc(...RF)
    printf() by fprintf(RF, ...)


In Rx side:

Code:

    if(kbhit(RF))
      {
       do
         {
          data = fgetc(RF);   
          .............
         }while........
      }
    fprintf(Comm, .........);


Humberto
Guest








PostPosted: Tue Mar 01, 2005 7:21 am     Reply with quote

Thank you Humberto:

After a long journey, we came to what I first asked for in the first post. but with a more clear idea about how manchester is working. uisng both way I could sending data correctly, the problem is the receiving, this problem have bother me for a whole week, I hope I could find a quick soon.
Humberto



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

View user's profile Send private message

PostPosted: Tue Mar 01, 2005 8:37 am     Reply with quote

Hi young,

You are right, but let´s assume that in the beggining of this thread
you was so confused that I preffer the little endian mode. Very Happy

Regarding receiving this kind of signal, you will need a work around
to improve the reception, a good scope is a must.
Be aware that this links are limited to short distances (~30m)

Hope you write us the final chapter of this story... Wink

Saludos,

Humberto
Guest








PostPosted: Tue Mar 01, 2005 8:55 am     Reply with quote

Thank you:
I know it is wired to ask the following question before I solve this one, but I would like to keep awared of the future option. The question is If I want to send data much longer distance than this one, what should I do?
Guest








PostPosted: Tue Mar 01, 2005 9:30 am     Reply with quote

Humberto:

I finally could see my program running using the following code, but I still have a minor problem, That this I could send and received data correclty with very little noise, however, When I want to send data more than 2, there is some unwanted data.

here is the case, when I send 'A', "AB", using my program, it is working find, when I send "ABC", there is unwanted data, here is the output, what might be the problem:
Quote:

ABCABCABCABCABCABCABCA$4$4$4$4$4$4$4$4$4$4$4$4$
4$4$4$4$4$4$4$4$ABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCA$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$ABCAB
CABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCA$4$ô$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$ABCABCABCABCABCABCABCABCAB
CABCABCABCABCABCABCABóABCABCABCABCA$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$ABCABCABCABCABCABCABCABCABCABCABCABCABCABCABCAB
CABCABCABCABCA$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$4$ABCABCABC


here is my program
Code:


#if defined(__PCM__)
#include <16F819.h>
#include <stdio.h>
#include <stdlib.h>
#fuses HS,WDT,NOPROTECT
//#device ADC=10
#use delay(clock=10000000)
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1)

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(char *c)
{
   int8 i,length;
   length=strlen(c);
   //premable data to init TWS
    putc(0xF0);
    delay_us(500); // *
    putc(0xF0);
    delay_us(500); //
    putc(0xF0);
    delay_us(500); // *
    putc(0xF0);
    delay_us(500); //
   for (i=0; i<length;i++)
     { SEND_DATA(c[i]);
     
     }
     putc(0xF0);
     delay_us(500);

}


void main()
{
  char data[]="AB";
   setup_port_a(ADC_OFF);

   setup_CCP1(CCP_OFF);
   setup_timer_1(T1_DISABLED);

   enable_interrupts(global);

   while(1)
   {
   remoteprintf(data);
   }
}


decoding

Code:

/*********************************************************/
/*                                                       */
/*      Decoding Manchester data bit by bit              */
/*                                                       */
/*********************************************************/

#if defined(__PCM__)
#include <16F819.h>
#Device *=16
#include <stdio.h>
#include <stdlib.h>
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT
//#device ADC=10
#use delay(clock=10000000)
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1,ERRORS)

#define M_Rx_Pin PIN_B0

int16 data_ori[40];
char data_decod[40];
char status;  //data 1 start 0 stop
int8 bit_num,data_num,i,j,k;
int1 tem;

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 data1[20],datar,ddl,ddh,datadecode;
  char status;  //data pre and post part
   SET_TRIS_b(0xff);
   set_Tris_a(0x00);
   SETUP_CCP1(CCP_OFF);
   SETUP_ADC_PORTS(NO_ANALOGS);
   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);
            putc(datadecode);
           }
         }
   }
   }
}

Humberto



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

View user's profile Send private message

PostPosted: Tue Mar 01, 2005 12:14 pm     Reply with quote

Great ! ! ! It´s running.

With this arrangement I guess that it´s almost all you can expect,
I assume that the antenna was tunned/installed properly.

RF links with AM transmiters in milliwatt range is not a reliable
configuration by design. To improve the data integrity and reliability,
you can add it some easy improvements like
error detecting + redundance technique
wich is transmitting the same packet more than once and validating
the received data by simple majority.

best wishes,

Humberto
Guest








PostPosted: Tue Mar 01, 2005 12:58 pm     Reply with quote

In the receivr, I reallized that some times the data wwasvery low, which at this period, data was misdecoded. why sometime the receiver side sometime have strong signal, sometime has weak signal.
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Tue Mar 01, 2005 4:21 pm     Reply with quote

I combined error check and data sending some special character. right now I am able to send whatever length of data I want.

A curious question? At my sending side, some times data is not sent out, I could not see data in the oscope. why?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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