On powerup the driver will initialise the HTRC110 and then place it in a low power standby state.
When your applicaiton calls the rfid_read_tag() function the driver then enables the HTRC110, carries out several configuration functions and RF value setting operations before placing the HTRC110 in read mode. In this mode the Dout pin of the HTRC110 simply passes the received modulated data from the RFID tag, or if no tag is present it will contain trash data. The 64bits of data the RFID tag will be continuously transmitting in a cycle containing 9 header bits, 40 data bits and 14 parity bits. The header bits allow the start of the data sequence to be identified and the 14 parity check bits provide sufficient error detection to ensure that only a valid RFID tag will be read. The EM4102 datasheet provides a lot of detail about the data bits and the possible modulation methods.
Once in read mode the HTRC110 outputs a 125kHz sine wave. The tag (if present) will interfear with the RF sine wave signal in order to pass its data stream back which the HTRC110 detects for us. When reading is active the Dout pin of the HTRC110 contains the raw data output of the tag after being filtered into a digital signal by the HTRC110.
Although the tag data length is 64 bits the driver needs to receive an initial 22 bits to determin the bit rate and then between 64 to 127 bits need to be received before we have a complete sequence.
Therefore a read can take 149 bits x 512uS maximum bit rate = 76mS.
Tags will often be set to use the slowest 512uS bit rate as slow transitions on the air interface are easier to detect, which means you get additional range and more reliable communications.
The EM4102 protocol permits tags to respond with Manchester, BiPhase or PSK (Phase Shift Keying) modulation. Although any of the 3 methods can be used tags basically always use Manchester encoding as there are many RFID readers out there that only support manchaester encoding. This driver supports Manchester and BiPhase encoding, as BiPhase is very similar to Manchester and there is minimal code footprint required to also support it. Although supporting PSK is not an particuarly complex task, it does requrie specific microcontroller hardware to be done efficiently and would cause unessary complexity so as PSK is not used in practice this driver does not support it.
For Manchester or BiPhase modulation the tag will be responding with 1 bit every 64, 32 or 16 periods of the carrier frequency, and will change state once or twice during this (the tag is allowed to use any of these three as its data rate). Using a clever detection method the driver only needs to detect each rising edge to determine the preceeding bit states, reducing the interrupt burden on the main application. Also only detecting each rising edge removes issues of dealing with non perfect high and low widths within each cycle – being radio they are often not perfectly 50/50, but the overall bit frequency will be relatively accurate.
So for either of these modulations the bit rate will be approximately 128uS, 256uS or 512uS. If the tag was using PSK modulation it would be changing state every carrier frequency period (every 8uS)
Once the bit rate has been determined by the driver it calculates the 125% and 175% bit times which it will then use to decode the data stream.
The driver now decodes the receied data bits on the fly as they are received. This is a much more efficient and minimal memory requriement approach rather than storing a large chunk of data and decoding it later.
To find the header the driver looks for the bit sequence 0111111111 which is the stop bit followed by header. This sequence cannot occur anywhere else in the tags 64 bit stream.
From the header bitstream the driver is able to determin if Manchester of BiPhase modulation is being used by the RFID tag. The driver then decodes the remaining bits of the 64 bit sequence, checking for a parity error as each parity bit is received.
If all of the parity checks pass and the final stop bit is received the RFID read is a sucess and a valid tag has been detected. The driver stores the 10 character ASCII hex tag ID ready for the main application to read and switches the HTRC110 back into low power mode. When a tag is present and in range there is typcially no need for a retry – the read sequence will typically work first time.
However the driver will retry for up to 150mS in case it helps where the signal is week. As this driver checks for parity errors as nibbles are received (rather than at the end) failures can occur early on in the bit sequence, so doing this will often mean the driver is ready to try again at the start of the very next sequence from the tag.
If no valid tag bitstream is detected the driver switches the HTRC110 back into low power mode and declares the read a failure.