Lab 9: Magnetic Card Reader (Hardware)

In this lab, we will use a packaged magnetic strip reader, which has the on-board smarts to convert a sequence of magnetic fluxes into a data stream with associated clock. At first, we will look at this data directly and decipher the contents of a magnetic stripe.

Then, we will build circuitry to package the data (in either 5-bit or 7-bit clumps) into asynchronous RS-232 serial data that a computer can understand. In the process, you will become more familiar with digital electronics and how to characterize bit streams.

Next week, we will use this circuit to read card information onto the computer, so that we may very efficiently go through whole stacks of cards and find out what secrets (if any!) lie hidden in the stripe.

The Actual Lab

Some of the instructions below are less than fully descriptive. You are left to figure some things out on your own.

WARNINGS: Important!

Examine and double-check all your connections before turning on the power supply.

Lab Procedure

  1. Study the circuit diagram to familiarize yourself with the components you'll be using, how they're rigged up, and how the circuit works. Also, scan the Tips below to understand what's there for when you need it.
  2. Prepare your breadboard to support 5 V power and ground. Use the power supply's dedicated (non-adjustable) 5 V supply.
  3. Hook up the card reader to the breadboard, providing it with 5 V and identifying the leads that correspond to card-loaded, data, and clock. Note that the mounted card readers (Panasonic) are built to read track 2. A simple zip-tie shim with 1/8 inch spacing (helps to kink it several places so it holds its position better) will let you read track 1 with these readers. There are also a few fully-packaged readers (Omron) that have been modified to read track 3. One or two shims allow these to read tracks 2 and 1, respectively. Note the pinout is different for the two, as indicated on the circuit schematic.
  4. Use an oscilloscope to probe the data, clock, and card-loaded lines all at the same time. Trigger on the falling edge of card-loaded, and swipe a card, adjusting the timescale to get the full action. Sketch the 3 waveforms (crudely) for the write-up. See the tip below about zooming in on the action. Be sure you understand the roles and relative timings of all three data streams. Describe why all three signals might be called "active-low."
  5. Swipe the card with the zip-tie out of the reader (no shim), which will read track 2, and characterize the clock period. Then do the same for track 1, with the 1/8-inch zip-tie shim in place. For roughly the same swipe speed, is there a difference in clock/data rate? What do you infer about the density of data on the card for these two tracks? Note: your student ID doesn't have track 1 data (try it!), but credit cards or drivers' licenses do.
  6. Now just look at data and clock, trigger on the falling edge of the data channel, and set up the scope for a single sequence (capture). Swipe track 2 of a card (no shim), adjusting the scope time-base to get the (fast-ish) swipe all on the same frame—at least all the data transitions. Swipe the card so that as you look at the magnetic stripe on the bottom of the card, the reader reads left to right across the stripe.
  7. Pore over the data record, jotting down all the ones (low) and zeros (high) corresponding to each clock pulse. See tips below about zooming and tracking oscilloscope data. It's a huge string, but worthwhile. The bits should clump into groups of five, with a guaranteed odd number of ones within each group (a nice way to error check and keep the bit divisions straight as you go). You may find it helpful to use the scope's vertical cursor bars to delimit packets of five (see tip below). Once you have the data, look at the 5-bit code detailed in the magstripe documentation, realizing that the least significant bit is first, and the parity bit at the end. Since track 2 is mostly numbers, you should ultimately be able to read the data directly off the scope: 11100 is a seven, for instance. If you use your student ID, you'll see lots of zeros (00001). Include a sketch of at least two interesting (non-zero) packets in a row, both clock and data.
  8. You may optionally want to go through the same exercise with track 1, which has denser data (thus more of it to wade through), and follows the 7-bit code. But it is gratifying to read your name off the oscilloscope one character at a time...
  9. Now that we've done it the hard way, let's get set up to let the computer do the work. To do this, we have to form asynchronous RS-232 data packets that the computer can read. This involves first parallelizing the data (either in 5- or 7-bit groups), then formatting it into a proper asynchronous packet at the right bit rate, and finally converting the logic levels into ±12 V for RS-232 compliance. At this point, be sure you know what each element in the circuit is supposed to do. If you don't, debugging the circuit as you go is impossible. Don't forget to hook the unused flop's CLR to ground (lower right corner of drawing). Also, don't forget to make the connection called TRACK_2 at the inputs of U5C and U5D (NOR gates) to the TRACK_2 line coming out of U1D—the trace is not explicitly drawn on the diagram.
  10. Once the whole circuit is rigged, set the board for track 2 (close SW1), and swipe a card, capturing a sequence on the scope. In addition to data and clock, capture the PIC output: pin 17 (pin 11 on MAX232). You should be able to corroborate the data sequence from the card data to the serial packet, keeping in mind that the sequence will idle high, drop low for the start bit, then have positive logic for the data bits, returning to idle (high) for the stop bit at the end. If a data bit doesn't match up as expected (look at enough different data words to verify operation), then there is something wrong with that bit, and you should trace the problem. Sketch a few packets showing clock, data, and PIC output. Note the bit rate you measure of the PIC output.
  11. Now look at the MAX232 output (pin 14). This should look much like the PIC output, but what was at 5 V becomes −12 V, and what was at 0 V becomes 12 V. In other words, there will be a positive-going start bit, followed by data, with LSB first, and a return to idle at the end for the stop bit. The idle will be at a negative voltage, and data bits will also be inverted (1 = negative; 0 = positive). Sketch a few data words showing clock, data, and RS-232 output. Also be sure that the pattern looks right: no bit-mistakes.
  12. Repeat these sanity checks for the 7-bit mode, by opening SW1, and shimming the card reader for track 1. Now the serial packets should contain 7-bit sequences.
  13. Verify that the bit rate is one of: 1200 baud, 2400, 4800, 9600, or 19200. Which is it? If you're sharp, you can look at a number of packets and decide how many data bits there are, and whether parity is even, odd, or absent. It's nice to be able to look at a serial stream on the scope and know whether it's 9600 7E1, or 19200 8N1, etc.

Once you have an error-free RS-232 signal coming out (matching data from card bit-for-bit in all cases), you've finished this phase of the lab. Next week we'll gather the serial data on the computer and find out what's on all our cards.

Tips

  • A recommended layout (prototype was done this way) is to have the first column of the breadboard house (from top to bottom): SW1, LED, U2, U3, U1, and the connector to the card reader. The second column has U4, U5, and U6. The third column has U7 (PIC), U8 (MAX232), and the DB9-connector (which doesn't have to go on until next week). This is merely a serving suggestion, and you may well find a better way.
  • If the negative logic is killing you, you may find it easier to hook up the U1 inverter chip (if it isn't already) and look at positive versions of the same signals. Just be sure to switch to triggering on rising edges if you go this route.
  • It is most useful to have the scope in normal trigger mode (rather than auto: see TRIG MENU on scope). You may even want to arm for a single acquisition by hitting SINGLE SEQ each time before you swipe.
  • To zoom in on the data stream, use the HORZ MENU button and notice the window option. Once in window mode, the horizontal position adjustment knob and seconds/division knob help you navigate around. Also useful is the window zone mode showing you the main view, but with markers to show you where the current window is: you can adjust the horizontal position and SEC/DIV knobs in this mode to target a section of the data stream and then hit window to see what's in that window. The main mode goes back to the normal (full) view.
  • To use cursors, hit the CURSOR button, and select the time type. Now the channel 1 and channel 2 vertical position knobs control the positions of the two cursors. It is very handy to set the cursor separation to be 5 (or 7) clock periods apart, so that you can scroll the data sequence through and frame one word at a time. Be careful, though, since a non-uniform swipe speed will make this period change as the swipe goes along.
  • It is very hard to verify proper activity of the parallelized data, so be especially vigilant in hooking this up and making sure you've made all relevant connections. After the PIC, you can verify proper operation again.
  • CMOS logic gates want all their inputs either used or tied to ground. If you are going to test the circuit in an intermediate state of readiness, tie the unused inputs to ground. Otherwise you could get spooky anomalous behaviors.
  • The PIC chip is programmed with this code (PDF) compliments of Allen White.

    Lab 9 Parts List


    Lab 9 Write-up

    The due-date of the write-up for this lab will be deferred until after next week, when you complete the second phase of this project. But don't be lazy about it! Record all the relevant information now, and write-up the description of your circuit now, along with any choices you made, tests you performed, etc. This way you've got a good head start, and put words down on paper while the memories are fresh.

    Specific items are:


    Back to Physics 121 page