Magnetic Stripe Read Head Amplifier

App Note AN309 (629 kB, 1 pdf file):   Magnetic Stripe Read Head Amplifier

Introduction
Now and then a technology comes along that’s easy to use, robust and adapts to many applications. Magnetic data stripes are one such technology. The obvious example is the credit card. But there are many other examples including paper airline tickets, shopping club cards, video rental store ID cards, driver licenses, vending machine debit cards, and the list goes on.

This application note briefly describes how an Okika Devices Field Programmable Analog Array (FPAA) can be used to construct a complete magnetic stripe read amplifier/decoder and how it can be easily interfaced to a host processor. The note also describes the benefits of programmable analog verses fixed function in such an application.

The Standard Card
"The beautiful thing about standards is that there are so many to choose from." How true. There are loads of standards to choose from when discussing magnetic stripe technologies, and I shall not endeavor to enumerate them all here. Suffice it to say that the most often referenced specification is ISO/IEC-7811. I'll just capture the highlights here with the understanding that we are using a read head and housing intended for plastic card magnetic stripe read applications. There are many quality suppliers of such, in this instance, Magtek products were utilized.

  For this discussion, the figure to the left represents the back of a typical plastic credit card. With the magnetic stripe on top as shown, the first (top) track is encoded in a format established by the International Air Transport Association; this track usually has your name encoded on it.

 

The second track (and this the real workhorse of the bunch) is in a format defined by the American Bankers Association. It contains your credit card number. The third track format is called THRIFT and was originally intended for use with Automatic Teller Machines (ATMs). Unlike the read-only tracks 1 and 2, the THRIFT track was intended for read and write applications. This never really caught on, and the track is not often used, except in those applications where the requirement to write back data is part of the design. Typical examples include copy machine and vending machine debit cards.

Viewing the card, as shown above, data is encoded from right to left. The encoding always starts with the least significant bit. (The right most bit is the LSB of the first character for the stripe.) The definition for each track is different and is summarized in the table below.

From Mag Stripe to ASCII Type…
There are a number of steps required to get from the magnetic read head signal to ASCII data digestible by most processors. The following diagram shows these translation steps as we move from top to bottom.

The Magnetic Stripe
Understanding the conversion process begins with knowing how data is stored on the card. Imagine a long chain of bar magnets, some are one unit in length (and always found in pairs) all the rest are two units long. Further, each of these bar magnets is arranged contrary to the state they would prefer, such that North always touches North, and South always touches South. In these areas where like poles are abutted, there are large concentrations of magnetic flux lines.

The Read Head Signal
The magnetic stripe is swiped passed the read head. A current will be induced as each of these regions of high flux concentration passes. N-N will induce a current in one direction, and S-S will induce a current in the opposite direction. As it turns out, the polarity of the read head signal doesn't matter. It is only the spacing in time of the transitions that is relevant to converting to an F2F waveform.

F2F or Aiken Biphase
For now, we'll put off the discussion of just how to create the F2F waveform from the read head signal and instead focus only on what F2F encoding is. Also known as Aiken Biphase, F2F encoding uses the space between flux transitions to encode a bit. A two-unit bar magnet represents a Zero, and a pair of one unit bars represents a One.

To put it another way, each bit occupies the same physical length on the stripe. A bit with an 'extra' flux transition in the middle of its length is called a One. Again, the polarity of these transitions is arbitrary; it is the relative space between transitions that signifies a One or a Zero.

Converting from Card Data to ASCII
Each track begins and ends with "clocking bits." Clocking bits are nothing more than a string of Zeros. As it turns out, a manual card swipe is a fairly constant speed event. Thus, a bit period from the beginning of a swipe is very close to a bit period at the end of a swipe. The "clocking bits" are examined for length (the bit period) and set the pace of the particular swipe. A Zero is recognized if the time elapsed between flux transitions is close to a bit period. A One is recognized if the time elapsed between flux transitions is close to half a bit period.

For processors equipped with a timer peripheral, it is possible to connect the FPAA output (which will be toggling between 0 and 3 V during a card swipe) to the timer port's input pin. Interrupts will be generated with each transition and storing the timer values into an array is all that is required of the interrupt service routine. A quick bit of post-processing on the array of values easily deciphers the Ones and Zeros.

For lower cost processors, you'll have to instead connect the FPAA output to a general purpose input pin on the processor. Once a first transition is detected (usually as an interrupt), the processor then has to completely devote itself to keeping track of time, polling the input pin at regular intervals, and recording when the transitions occur. Here again, post-processing of the array of time stamps will decipher the Ones and Zeros.

Keep in mind that the card may have been swiped backward. Flipping the data around is easily handled in software.

Now that you have a string of Ones and Zeros, you need to recognize where the data started, and how to interpret it. For an introduction to this part of the process, please see this note's Addendum.


Applying the AN231E04 as a Magnetic Read Head Amplifier and F2F Generator
Only GainInv and Comparator CAMs are required. The circuit demonstrated here is a sort of an "analog S-R flip-flop." The comparators and their feedback paths form a bi-stable circuit. The circuit will stabilize in only two states.

 

 

Looking at the circuit diagram on the left. Voltages are shown bold, and amplifier gains are shown in square brackets. The amplifiers are shown with a bubble on their outputs just to serve as a visual reminder that these are all inverting amplifiers. Assume there is no card present and that all node voltages are as shown. (A reminder: All analog signal processing within the FPAA is differential so that in the above diagram, a voltage of +2V means that OxP – OxN = +2V. Furthermore, the common mode voltage is Voltage Mid-Rail (VMR), and by convention, this is labeled as 0 V. VMR is actually 1.5 V above the chip's ground so a differential signal of +2V means that OxP = +2.5V and OxN = +0.5V).

Examine the node voltages for a moment, and you'll see that the circuit is in a stable state. The output is a logic high.

Now consider what happens when a card is swiped passed the read head. For the example shown above right, an S-S flux field passed over the gap in the read head. This induced a small signal negative going spike. The high gain input stages convert this small spike into a full rail signal. (Any input signal with an amplitude of greater than 25 mV will simply result in a clipped signal as shown.) This positive pulse presented to the negative terminal of the top comparator will cause it to change state as shown by the falling output waveform. Just the opposite is happening on the lower comparator as the entire circuit transitions to its other stable state. The output is now a logic low.

 The figure above is a scope shot of the circuit in action. In this particular case, a read head was interfaced directly to an AN231E04. The top trace shows the raw read head input… noise and all. The bottom trace shows the circuit's output signal (a 0 – 3V F2F logic waveform). No other components were used. Nothing to it; its that easy with programmable analog.

The circuit as shown above consumed only 2 of the 4 CAB's available within an AN231E04, so there is plenty of room in an AN231E04 for a second read channel. The figure below shows the implementation of the circuit in AnadigmDesigner®2 Software (note all CAM clocks in this circuit are 4MHz).

 

Benefits of Using Programmable Analog
The circuit described is simple enough and can, of course, be constructed using twenty or so standard components. So why programmable analog?

The obvious answer is component count. There were no extra components of any kind used in this application. The read head was interfaced directly to the FPAA. However, the real advantages don't become obvious until you take the circuit out of the lab and into the harsh light of the real world.
In the real world credit card stripe readers constructed without programmable analog aren't all they should be. You've seen evidence of this so many times that you have probably become numb to it.

Take a moment and recall all the cashier "swipe" techniques you have witnessed. The "slow and deliberate" swipe. The "fast swipe." The "run it backward" swipe. The "run it back and forth and back and forth" technique (one of my personal favorites). The "clean the card and try it again swipe." The "wrap the card in a plastic bag and try it again swipe." The "try the other card reader " technique. And then of course there it the ultimate contingency plan where the cashier holds the card up to the light just right so the badly worn raised numbers can be recognized and typed in by hand (usually while sharing a disgusted look with you).

Dirt, wear, temperature, and exposure to unintentional magnetic fields all conspire to render magnetic stripe cards difficult to read. Likewise, dirt, wear and corrosion work to render the read heads less and less efficient. So how can programmable analog fix the situation? The host processor can update the circuit parameters in just a few microseconds, or download a completely new circuit configuration to an AN231E04 in under 100 microseconds. So when a swipe fails, you can adjust the gain of the input amplifiers in just a fraction of a second.

The circuit can also be adjusted for reading cards with differing magnetic stripe coercivity. While usually not important for read heads, adjusting write head drive signals is essential to accommodate such coercivity differences.

These are some of the advantages of applying programmable analog just in standard card applications. In custom applications, there are even more advantages to using programmable analog. For high-security applications, the FPAA can be configured to handle different data encoding techniques including tone generation and decoding. Read and write functions and more.

Addendum - Credit Card Track Encoding and Data Standards
There are a lot of steps involved in recovering data off a simple magnetic stripe. So far we have covered read head amplification, generation of a F2F waveform and its interpretation into a string of ones and zeros. The next step in the recovery process is to convert the binary data into character data, usually ASCII. The rules for interpreting the data vary with which track you are reading.

Common Track Layouts
Common to every track is the "clocking bits." Clocking bits are found at both ends of every track. Clocking bits are a short string of zeros intended to give self-clocking card readers a chance to establish the swipe speed and set a bit cell time duration. In our application, the microprocessor will examine the clocking bit periods as a first step in decoding the binary data.

Also common to every track are the Start Sentinel (SS), End Sentinel (ES) and Logitudnal Redundancy Check (LRC) characters. On Track 1, the SS and ES characters are % and ? respectively. On Tracks 2 and 3, the SS and ES characters are; and ? respectively. Field Separators (FS) are common to Tracks 1 and 2.

If at first, you don't recognize a Start Sentinel, then chances are the card was swiped backward. You will have to adjust your decoding algorithm accordingly.

The LRC is the sum of all previous Bn bits for all the previous characters on the stripe (overflow is ignored). The odd Parity bit associated with each character will only flag a problem if an odd number of bits (like 1) were in error for that character. It is unlikely that there will be 2-bit errors in a single character, but if there is, the odd parity checking will not recognize the event. The job of the LRC then is to add one more layer of error checking for the data stream associated with the entire track.

Track 1 Specific Layout
zeros | SS | FC | Primary Acct (19 characters max) | Name (26 characters max) | FS | other data | ES | LRC | zeros

Track 2 Specific Layout
zeros | SS | Primary Acct (19 characters max) | FS | other data | ES | LRC | zeros

Track 3
There are too many non-standard uses of Track 3 to enumerate here. Suffice it to say, it is largely an abandoned track and consequently is where most specialized or custom systems will encode data. The original intent was to use this track as a Read/Write track and actually carry encrypted information about your bank account balance here. This allowed non- networked automated teller machines to dispense money without really knowing for sure what your actual balance was at the moment of the withdrawal. It didn't take the banking industry very long to realize that it is far better to instead network together ATMs and abandon the idea of dynamic data on your ATM card. Track 3 is now an orphan.

Track 1 Character Set - 6 Bit Alpha with Odd Parity

To convert to the ASCII value, ignore the P (parity bit) and add the hex value of B[6:0] to 20 hex. For example for the / character, 0F + 20 = 2F

Tracks 2 & 3 Character Set - 4 Bit BCD with Odd Parity