View previous topic :: View next topic |
Author |
Message |
Ringo42
Joined: 07 May 2004 Posts: 263
|
Reading an RFID chip |
Posted: Tue Sep 09, 2008 11:07 am |
|
|
I'm using a PIc 18f2221 at 20Mhz and want to talk to a EN4095 RFID chip. The tags I'm using are Manchester encoded and have 64 clock cycles per bit.
I'm just starting to think about how to do this. Since it is Manchester I need to see if the bit goes high or low in the middle of the period. What would be the best way to do this? I originally laid out the board and hooked up clock to A0 and the data in to A2, but now I'm thinking I probably should have put the clock on B0 so I could use an interrupt to count the clocks. Would this have been the easiest way? the clock runs at 125 Khz. So what I'm thinking is once I determine I'm starting, I can count 20 clock or so and see what the bit is, (about 1/3 into the period), wait 24 clocks (2/3) and check it again and at that point decide if it went up or down and if it is a 0 or a 1. then count the last 20 clocks and call the bit done and start over.
Just looking for opinions before I start down the wrong path writing the code.
Thanks
Ringo _________________ Ringo Davis |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Tue Sep 09, 2008 11:43 am |
|
|
From Google, here is some manchester CCS code:
http://www.radiotronix.com/downloads/an401.c
Also how about trying a search of the CCS forum? Lots of stuff if you just search on the word Manchester. |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Tue Sep 09, 2008 1:24 pm |
|
|
I did not realize ex_rfid.c existed. I'm hoping to strip that down to just what I need. Does anybody know of a reason that an 18F2221 at 20mhz would not work in place of the 18F452 at 20 mhz? I just need to move my pins over to the correct connections.
Ringo _________________ Ringo Davis |
|
|
Ringo42
Joined: 07 May 2004 Posts: 263
|
|
Posted: Wed Sep 10, 2008 8:33 pm |
|
|
I'm trying to get ex_rfid.c to work. I'm using an 18f2221 instead of a 16f876a. The code never returns any data from the RFID chip so I'm trying to figure out why. The data stream looks ok on my O-scope.
I have traced it all the way down to the isr_ccp1() in em_4095.c
That code is below
I enabling the int and setting RF_readMode = RF_FIND_WIDTH.
So theoretically the array widths[] should have the widths of the data stream, but I get either 0's or 255's
Comparing the 876a and 2221 data sheet the only thing I see that is different is the 876 says C0 is timer 1 input and the 2221 says c0 is timer1/3 input. I can not find anywhere if I need to tell it to use timer 1 instead of timer 3. Could this be the issue?
The pic runs at 20mhz. The clk on c0 is approx 120khz
The pulses range from 240us to 520 us, so I would expect the width values to range from 30 to 65.
Any theories, or anybody have any experience with this example code?
Thanks
Ringo
Code: | #INT_CCP1
void isr_ccp1()
{
int8 width;
//printf("c");
// Toggle between capturing rising and falling edges to meausure width
if(RE_FE_TOGGLE)
{
setup_ccp1(CCP_CAPTURE_FE);
RE_FE_TOGGLE = 0;
}
else
{
setup_ccp1(CCP_CAPTURE_RE);
RE_FE_TOGGLE = 1;
}
// Calculate the width
width = CCP_1 - old_clock;
old_clock = CCP_1;
switch(RF_readMode)
{
// Use to receive manchester formatted data from a transponder
case RF_MANCHESTER_DATA:
{
// if(width > 54) // Check for a phase change
if(width > 54) // Check for a phase change
{
bitValue = ~bitValue; // Invert the save bit value
storeData = TRUE; // Force a bit store
}
if(storeData)
{
shift_right(RFbuffer+RFbuffer_index, 1, bitValue);
++dataTransferred;
if(++RFbuffer_bitIndex == 8)
{
RFbuffer_bitIndex = 0;
++RFbuffer_index;
}
}
storeData = ~storeData;
break;
}
// Use to read high and low widths
case RF_MEASURE_WIDTHS:
{
RFbuffer[RFbuffer_index++] = width;
++dataTransferred;
break;
}
// Use to search for a certain pulse width
case RF_FIND_WIDTH:
{
if(width > (RF_widthToFind - RF_uncertainty)
&& width < (RF_widthToFind + RF_uncertainty))
{
RF_widthFound = TRUE;
}
widths[RFbuffer_index++]=width;
break;
}
case RF_FIND_PATTERN:
{
if(width > RF_findWidths[RFbuffer_index] - RF_uncertainty
&& width < RF_findWidths[RFbuffer_index] + RF_uncertainty)
{
if(++RFbuffer_index == dataTransferred)
{
RF_patternFound = TRUE;
}
}
else
{
if(RFbuffer_index > 0)
{
int8 pos, i, j;
pos = RFbuffer_index-1; // Save the initial position
// Try to match partial pattern
while(--RFbuffer_index != 0)
{
if(width > RF_findWidths[RFbuffer_index] - RF_uncertainty
&& width < RF_findWidths[RFbuffer_index] + RF_uncertainty)
{
for(i=pos, j=RFbuffer_index-1; j!=255; --i, --j)
{
if(RF_findWidths[j] != RF_findWidths[i])
{
break;
}
}
if(j == 255)
{
break;
}
}
}
}
}
break;
}
}
}
|
_________________ Ringo Davis |
|
|
|