125kHz RFID Reader Driver Technical Manual
Section 4. Using The Driver In Your Project

4. Using The Driver In Your Project

a) Functions

The driver is implemented as a single thread so you just need to make sure functions are always called from a single thread (it is not designed to be thread safe).  All RFID operations are carried out using a non stalling state machine approach.

void rfid_process (void)

This function should be called regularly as part of your applications main loop.

void rfid_read_tag (void)

Call this function to start the read tag process

BYTE rfid_get_read_tag_result (void)

Call this function to check for the end of the read tag process.  It returns 0 if still reading, 1 if completed. Bit 7 will be set if the read failed.

After a sucessful read the ASCII tag ID will be in rfid_data_nibbles[0] | rfid_data_nibbles[9]

void rfid_sampling_rising_edge (WORD us_since_last_rising_edge)

Call with us_since_last_rising_edge = The time in uS since the last edge interrupt. You application interrupt hander must create this value from an available microcontroller timer. The maximum time between interrupts will be approximately 1024uS, so your timer calculation only needs to deal with time values of up to say 1280uS (to give a reasonable margin of worst case tollerance).

Call with the timer value captured as close as possible to the rising edge occuring (reduce latency as much as possible).

This fucntion will ignore the value for the first 2 calls allowing for initial timer error.

void rfid_force_initialise (void)

In typical use this function is not requried as the driver will automatically initialise the HTRC110 IC on powerup. However if you are using this driver with multiple HTRC110 devices (for instance by switching the SCLK, DIN and DOUT lines by using one or more 74HC4053 IC’s) then this function can be called during your applications initialisation after selecting each HTRC110.  To read each HTRC110 call rfid_read_tag() and wait for rfid_get_read_tag_result() to return a completed result before switching to the next HTRC.

b) Timing Requirements

The decoding of the modulated tag datastream requries the Dout rising edge interrupt to be handled with reasonably low latency so that the time x 1uS since the last rising edge can be passed to the drivers rfid_sampling_rising_edge() function with as much accuracy as possible.  Depending on the RFID tags data rate (different tags are permitted to use different rates) the quickest interrupting will be a rising edge every 512uS, 256uS or 128uS.  Many tags use the slowest 512uS bit rate as it helps increase range.

In the Microchip PIC18 sample project using an 8 bit microcontroller running with a 125nS instruction clock (8MHz crystal with 4 x PLL) the rfid_sampling_rising_edge() function takes a maximum of 95uS to complete (typcially significantly less – the most time is taken after parity bits are receveid).  This is with no C18 compiler optimisations enabled.

The above should allow you to decide on a suitable interrupt arrangement for your microcontoller based on the other demands of your applicaiton.  Remember that the rising edge interrupt is only active when reading a RFID tag.  When the driver is idle the interrupt is disabled.

c) Memory Space Requirements

Using the PIC18 Sample Project the driver uses approximately 2534 program memory bytes (1276 x 16 bit instructions) compiling just the driver functions with the Microchip C18 MPLAB C Compiler for PIC18 family of 8 bit microcontrollers (with no compiler optimisations enabled).

The driver requries approximately 40 bytes of static RAM memory space.  It requires only a small amount of temporary variable storage space from the stack.

d) Troubleshooting

A few things to check if you run into problems implementing the driver in your application:

  • Are the communicaitons between the HTRC110 and your microcontroller working correctly – does the HTRC110 reply?  Use the RFID_SPI_SAMPLE_CS_PIN and a logic analyser to capture these if necessary.
  • Is the time value being passed to the rfid_sampling_rising_edge() function correct – check with a scope.
  • In the function rfid_sampling_rising_edge() breakpoint at the end of the section “//—– CALCULATE THE CYCLE TIMES —–”.  Is the rfid_1us_bit_rate correct?  If you use a logic analyser to capture Dout from the HTRC110 during tag reading you will be able to determin the bit rate by looking for the shortest low high pulse sequence (high edge to high edge) – does rfid_1us_bit_rate match?
RFID_SPI_SAMPLE_CS_PINUse