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 1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

what is the problem with my manchester en(de)coding program?
PostPosted: Wed Feb 23, 2005 10:46 am     Reply with quote

Here are my program for manchester en(de)coding, I could detecting data at receiver side, but the data is not correct, what is the problem?

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;
    //premable data to init TWS
 
      putc(0xF0);
       delay_us(500); // *
       putc(0xF0);
       delay_us(500); // *

    for (i=0; i<2; i++)
    {
 
        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);
 
    }
    //
    putc(0xF0);
}
//

void remoteprintf(char *c)
{
   int8 i,length;
   length=strlen(c);
   for (i=0; i<length;i++)
      SEND_DATA(c[i]);

}


void main()
{
  char data[]="I am flying!";
   setup_port_a(ADC_OFF);
 
   setup_CCP1(CCP_OFF);
   setup_timer_1(T1_DISABLED);

   enable_interrupts(global);

   while(1)
   {
   

  remoteprintf(data);
  putc(0xF0);
  delay_ms(50);


  }
}







Code:

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

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)
         {
   //      putc(datar);
         ddh=DECODE_DATA(datar);
          if(status==0)
            {
            status=1;
            ddl=ddh;
            }
             
         else
           {
            status=0;
            ddh<<=4;
            datadecode=(ddh | ddl);
            putc(datadecode);
           }
         }
   }       
   }
}

young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 12:43 pm     Reply with quote

I found one problem, this is the delay between each character is a very critical issue, the lower the baud rate, the longer the delay between each character. that is one of the reason why sometimes I run the program well, sometime, it does not runs well.
Humberto



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

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 1:07 pm     Reply with quote

Hola young,

I didnīt analize all your code but if you use the
Quote:

#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1)

preprocessor directive, you are telling to the Compiler that you are
going to use the hardware UART to transmit/receive chars in
RS232 Mode, while your real intention is to do that but using another
coding, let say Manchester.

You can keep such directive in your code but only for monitoring purpose,
and in your Manchester Tx routine redirect the output to another pin and
remember that putc() or any function related to RS232 will be
addressed to the defined rs232 pins.

Then take a byte and encode it in Manchester code, remember that it needs a
transition in each bit, so for every byte you need to encode, you will get
two output bits because the added transitions.

So your encoding routine will have this format
Code:

int16 Manchester_encoding(int8 Tx_byte)
{
 ------------
 your code
 ------------
 return((uint16);
}


Let me know if I had been clear in this explanation.

Regards,

Humberto
Guest








PostPosted: Wed Feb 23, 2005 1:56 pm     Reply with quote

Thank you:

This so far I get the most clear advice. I understand for
Quote:

preprocessor directive, you are telling to the Compiler that you are
going to use the hardware UART to transmit/receive chars in
RS232 Mode, while your real intention is to do that but using another
coding, let say Manchester.

that Manchester output pin and RS232 pin shpuld be totally different. I should not use the RS232 pin as input to transmitter,

However I am not clear about here

Quote:

You can keep such directive in your code but only for monitoring purpose,
and in your Manchester Tx routine redirect the output to another pin and
remember that putc() or any function related to RS232 will be
addressed to the defined rs232 pins.


I do not know how to redirect the Manchester output to another pin, and I could not understand
Quote:
remember that putc() or any function related to RS232 will be
addressed to the defined rs232 pins.
Imanjl



Joined: 15 Nov 2004
Posts: 42

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

Re:ENCODING PROBLEM
PostPosted: Wed Feb 23, 2005 2:06 pm     Reply with quote

I think that Humberto says right,,because u need an RF module
with UART interface like (RX-DFM-5v) from abacom company...

I myself have the same problem,,,and aslo find out that there is a chip with the name of DPC-2400 that can connect between the normal rf module and then gives us Rx like to connect to pic ...but i dont use it myself yet....if any one have any information about this ,,im so glad to know it
Guest








PostPosted: Wed Feb 23, 2005 2:22 pm     Reply with quote

Hi:

Do you mean that TWS434 RWS434 from rentron is not an RF module
with UART interface?
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 3:08 pm     Reply with quote

Thank you Humberto:
I do really need more advice on Manchester Tx. currently, I am sending the encoded data to PIN_A0, which you said it is wrong, so which pin or how to define another pin for data transfer. I thought that manchester use rs232 pin
Humberto



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

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 3:11 pm     Reply with quote

Hola young,

Quote:

However I am not clear about here

You can keep such directive in your code but only for monitoring purpose,
and in your Manchester Tx routine redirect the output to another pin and
remember that putc() or any function related to RS232 will be
addressed to the defined rs232 pins.


I mean that you can use
#use rs232(baud=2400, parity=N, xmit=PIN_A0, rcv=PIN_A1)
for monitoring in a PC (through an RS232 level shifter)

To re-assign the Manchester Rx and Tx PINs you can define:
#define M_Rx_PIN PIN_B0 // Manchester Rx Input PIN
#define M_Tx_PIN PIN_B1 // Manchester Tx Output PIN

In the TRISB register assign them as INPUT and OUTPUT respectively.

There are different ways to encode a byte, a good excercise is the one
where you need to generate one transition + delays for each bit.
To transmit at 2400 bauds you need to generate a inter-bit delay to
output a bit every 416.66 microsec.
Code:

    1 Start_bit  :  416.66 microsec
    8 Data_bits :  3333.33 microsec
    1 Stop_bit  :   416.66 microsec
   __________________________
    Total          4166.66 microsec

Inside the function test each bit of Tx_byte and generate the
delayed transitions following the Manchester encoding rules as shown
below:
Code:


Bit uncoded     Value Sent
   Logic 0       0 to 1 (upward transition at bit centre)
   Logic 1       1 to 0 (downward transition at bit centre)


Hope I had been clear.

Humberto
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 3:30 pm     Reply with quote

Thank you Humberto:

Yes, I am more clear than before, here is just try to clearify if my understanding is right.

1. first of define a Transfer Pin for Manchester as you shown

#define M_Tx_PIN PIN_B1 // Manchester Tx Output PIN

2. than use the manchester encoding method, as I posted at the beginning to chang it to manchester code

3. Then send the data bit by bit from M_Tx_PIN with certain delay for 2400 baud rate.

4. This pin goes to TWS434 (for RF communication)

5.Reveive the data from the pin
#define M_Rx_PIN PIN_B0 // Manchester Rx Input PIN

6 this pin comes from RWS434 (receiver)

7 detect the data (how to detected the data, usually, if using khbit(), it should be a rs232 pin, do I need to keep pooling data? I am still not sure about here yet??

more advice please
Humberto



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

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 3:56 pm     Reply with quote

YES !!! Iīm happy you understand the idea. I would like you start in this
way because itīs very demostrative to work bit a bit, but by far itīs not
the only way to do that, ok?

Regarding your answers, 1 to 6 are right.
Point 7:
Quote:

7) detect the data (how to detected the data, usually, if using khbit(), it should be a rs232 pin, do I need to keep pooling data? I am still not sure about here yet??


To detect the data you must know what is the iddle state of Rx output in
the RWS434 receiver.

kbhit() is a function related to RS232. Not applicable here.
The Manchester input pin may be any PIN configured as INPUT, BUT
to ovoid wasting time pooling a pin, you can use the external interrupt
PIN in the receiver PIC and trigger your Manchester Decoder when detect the Start bit.

I will be outside for the next 2 hours, then I will stay tunned !!!

Humberto
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 4:21 pm     Reply with quote

Here I got a little bit confused, if an external interrupt pin was used, what happens if the following data are send and received by M_Rx_PIN.

Origianal data(bit) Manchester Data
0111 01 10 10 10
1000 10 01 01 01

Manchester data 01 10 10 10 and 10 01 01 01 will be send and received by M_Rx_PIN, if interrupt was used all these zeros (0) will not be detected, only one(1) were detected, right? zero will not produce any interrupt, right?
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 4:27 pm     Reply with quote

another question is in www.quickbuilder.co.uk/qb/articles/ , it mentioned that

Quote:
we can use RS232 as a carrier for manchester encoding


How is these being done
Humberto



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

View user's profile Send private message

PostPosted: Wed Feb 23, 2005 7:07 pm     Reply with quote

Having the following byte to transmit: 0x62
Code:

      0x62 = 01100010     coding each bit with Manchester rule transitions 
       
 0  1   1   0   0   0   1   0     
   
01 10  10  01  01  01  10  01  we get 16 bits, hence two 8 bits groups

 0110  1001   0101  1001
 
   6     B      5     B 


To transmit 0x62 with zero DC component we need to send 6B5B, now
you can send it using RS232 as Manchester carrier, right ?

Another way is to send it bit a bit directly driving the TWS434, in this case
you must insert a START bits like 0000 in the beggining and then a
STOP bits like 1111 at the end of the packet, NOT in each byte, to
keep zero the DC component.

In the receiver side, the sequence 0000 (without any transition) it is very
easy to detect as a START, then the following transitions represent the
DATA field until you reach the unique sequence 1111 that it is easy to
detect as a STOP.

The bytes coded 6B5B plus START and STOP bits becomes

Code:


     0000 0110 1001 0101 1001 .......more coded DATA ...... 1111

    START   6    B    5    B                                STOP


Hope now is clear.

Humberto
Imanjl



Joined: 15 Nov 2004
Posts: 42

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

PostPosted: Thu Feb 24, 2005 3:21 am     Reply with quote

hi

Quote:
To detect the data you must know what is the iddle state of Rx output in the RWS434 receiver.


I put a scope probe on the rx output of rf module and the waveform was a continuous 01010101 bit with this pattern if we route this pin to PIC RX input It always fills the buffer and aslo generate RDA interrupt that is unwantted ..

So before sending 0000 start bit From Tx module Pic detect something else and even with Comparing 0000 To 0101 we are in an infinit loop .

??????????????
young



Joined: 24 Jun 2004
Posts: 285

View user's profile Send private message

PostPosted: Thu Feb 24, 2005 7:28 am     Reply with quote

Thank you Humberto:

Do you mean there are two way to send the manchester code: one is through rs232, one is through another pin like #define M_Tx_PIN. because what I read from
Quote:

you can send it using RS232 as Manchester carrier, right ?

Another way is to send it bit a bit directly


sound like two ways method.

and I am quiet clear so far by sending data bit by bit with your clear description.

however in the receiver side, I am still feel not confortable to use interrupt to receive the data?
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 1, 2, 3  Next
Page 1 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