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

Read Manchester code from u2270

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



Joined: 11 Nov 2008
Posts: 24

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

Read Manchester code from u2270
PostPosted: Tue Jan 20, 2009 8:58 am     Reply with quote

Hi, I tried to get help from many people on machester decoding. No one could help. So i started to read the manchester code. The idea is, if the width of the pulse is 90us, pic start to sample after 45us. So it would always stay in the middle of the pulse. This is so far i got to, but no idea why this never works. anyone, Please help. I'll work on myself on decoding, for now, i just want to read the code from EM4001. If you've any other method, let me know (viknes1985(at)hotmail.com) Crying or Very sad

Code:
#include <16F877A.h>
//#FUSES XT,NOWDT,NOPROTECT,NOPUT, HS, NOLVP

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP


#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_B6,rcv=PIN_B7,stream=TOPC)
//#use rs232(baud=9600,xmit=PIN_D7,rcv=PIN_D6,stream=SIGNAL)

//#byte a_port = 5        //Port you want to use
#byte b_port = 6
//#byte d_port = 8

#int_ccp1

void main ()

{
//SET_TRIS_A(0x0A);
SET_TRIS_B(0x81);
setup_ccp1(CCP_CAPTURE_RE); // to know the starting point

if (CCP_1) //if there's any rising edge
   {
   delay_us(45); //shift to half of the pulse
        while (TRUE)
        {
        int x=0;
        while (x<=64) //for 64 bits
        {
         if (input(PIN_B0))  //from u2270 output (manchester code)
         fputc('1'); //show 1 when high
         else
         fputc('0'); // show 0 when low
         
         delay_us(90); //shift to next pulse
         x++;
        }
        delay_ms(1000);
        fputs(" Next 64 bits ");
        }
    }
   
    else
    {
      fputs(" Not Yet find the rising edge ");
    }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 20, 2009 2:16 pm     Reply with quote

Your title says "read from u2270" but your post says EM4001.
Post the actual chip or board you want to read from, and post a link to
the data sheet for it.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Read Manchester code from u2270
PostPosted: Tue Jan 20, 2009 2:54 pm     Reply with quote

One big problem is that your code does not loop waiting for a rising edge. It checks just once in main(), and then main() exits (probably to Sleep).

Another problem is that you have lots of fputs() function calls. Don't you know that they take time? About 1 mSec per character at 9600 baud. And you are trying to find 90 uSec pulses! You must get rid of all that debugging stuff because it will kill your timing. Find some other way to debug, like writing to spare digital I/O pins. That will only take 1 or 2 instructions.

Another problem is that you seem to want to use Input Capture mode, because you set it up initially. But then you never use it after that. I don't think you understand what Input Capture is.

Once you get the basics out of the way, then you need to study up on the finer points of Manchester coding. Manchester code is self-clocking. That means it contains transitions that you can and should lock to in order to receive it. You apparently are treating 64 bits of manchester as if it were serial Async (as if for a UART). It is not. It has alternating clocks and data transitions. Your code should re-sync to the clock transitions to correct for any slight difference in clock speed between the sender and the receiver. 64 bits is a long time to maintain timing without any re-syncing. Maybe someone else can give a good reference for Manchester - I don't happen to have one handy.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
viknes1985



Joined: 11 Nov 2008
Posts: 24

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

Read Manchester code in PIC and display in PC via RS232
PostPosted: Tue Jan 20, 2009 8:34 pm     Reply with quote

Thanks for the quick replies. This is RFID reader that i'm using www.datasheetsite.com/datasheet/U2270 which read get the codes from EM4001. I need to program the PIC so it could read the manchester code from U2270. Correct me if I'm wrong at anywhere.

If fputc() takes long time, do you have any other suggestion or guide? And how to resync the clock transition of transmitter and receiver?
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Read Manchester code in PIC and display in PC via RS232
PostPosted: Tue Jan 20, 2009 9:39 pm     Reply with quote

viknes1985 wrote:
..If fputc() takes long time, do you have any other suggestion or guide?

Yea. As I said before, use spare digital I/O. As for re-syncing, poll for the clock transitions.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jan 21, 2009 1:19 am     Reply with quote

Quote:
If fputc() takes long time, do you have any other suggestion or guide?

The only meaningful way is to store the decoded bitsteam in RAM and print it when the frame has been received or an error occurred.

It's not shown in your code, but I expect that the tag data emission has to be triggered by a request from the reader?

As another point, to avoid false start detection, manchester decoding is usually synchronized on a known multi bit start pattern.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Jan 21, 2009 3:34 am     Reply with quote

To add to what has already been said.

#byte b_port = 6
Not needed as you are not using it and you do not specify fast_io for any ports anyway.

#int_ccp1
Directive telling the compiler that the function imediately following is the interrupt service routine for the CCP1 but the function imediately following happens to be main !

SET_TRIS_B(0x81);
Don't need this as again you are NOT using fast_io

Your understanding of manchester code also seems to incorrect.
You should be looking for transitions. A low to high transition in the middle of the bit indicates a 1 and a high to low a 0. You also need to ignore the transition if it is at the beginning of the bit.

You should use these transition not only for retrieving the data but re-syncing your clock or timer.

The hardest part will be trying to determine if the first transition is a data transition (in the middle of the bit) or one you should ignore.

Have fun.
viknes1985



Joined: 11 Nov 2008
Posts: 24

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

As a beginning
PostPosted: Sat Jan 24, 2009 1:21 pm     Reply with quote

Thanks for the reply. Yes FvM, i aware of the bit pattern, according to the datasheet it's 9 bit of 1s. But for now i only wanted to display the the manchester code via hyperlink.

And Wayne, thanks for the advice. I'm still new to this PIC. Still in learning stage, I appreciate your advice. How to collect, let say 64 bits and then store it in a variable?

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