In this lab assignment, you will complete the design of the magnetic stripe reader. You already have a working LCD controller from the previous lab. In this lab you will add a circuit that collects data from the magnetic stripe reader and sends it to the LCD interface to be displayed.
Once again, you should fully design and simulate a circuit before you try to construct it. You should do as much as you can before attending lab session. Do not wait until next lab session to start. It is important to design everything ahead of time and to get started as soon as possible.
You will have a total of four
The first thing you need to do is understand what the
Magnetic Stripe Reader produces. You
must study the datasheet and associated information, although we will
summarize the main points here. There are three signals that you need to
The timing diagram below, copied from the datasheet,
describes what happens when a stripe is read.
Pay attention only to the RCP1, RDP1 and
RCP is a clock signal, however, you should not use it to clock registers. Instead you should use the system clock, which is running much faster than RCP, to sample RCP. When you detect a 1 on RCP followed by a zero, you should sample the data bit on RDP. (To make this completely clear, we will NOT use RCP as a clock signal for our registers. This because it is not always running, only when a card is running through the reader.)
Data is sent in bit-serial fashion, 7 bits per character, low-order bit (LSB) first. The first six (low-order) bits are the 6-bit ASCII code, while the last, highest-order, bit is a parity bit, which you may ignore.
Note that in the timing diagram, the data is 0 for a while before a 1 appears - the first character starts with this first 1. The first character is a "start sentinel", which is '1000101'. This is actually the data value '5', with the high-order parity bit set. The character arrives in the order '1010001', that is, low-order bit first. All the character definitions are given in the following table, which appears in full in the documentation. (This is more readable than the corresponding table in the datasheet.) You should compare this character code to the character code used by the LCD - they are not quite the same so you will have to do a translation.
Your design should be done in two parts. The first part should just worry about
looking for edges on RCP, looking for the first data bit and counting data bits
to keep track of where characters start and end so that it can send a write
signal to the LCD controller. The second
part should just collect the data bits into a character that can be sent to the
LCD. Since you do not have enough room
The signals from the magnetic stripe reader are not synchronous to our clock, meaning they can change anytime, even right when our clock is "ticking". This means, that if we sample one of these signals with a register, we could violate the setup/hold time constraints of the register. We will address this in class, but for now, the way to solve this problem is to put two registers back to back (a shift register) on the RCP input and only use the output of the second register. (Why do you need to do this only for RCP?)
As always, you should make sure your circuit works in simulation before you try to build it. In addition to the LCD test fixture that we gave you last time, we will give you a magnetic card reader test fixture that will generate the appropriate inputs to test your circuit. The magnetic stripe card reader should send the characters "HELL0!!" to the LCD if your circuit works correctly.
You should be able to construct the circuit on
a single prototyping board by sharing columns with a
Note: Only cards with data on track 1 will work correctly. HuskyCards have all of their data on track 2 and will not work (unless you do the extra credit!). All credit, debit, and ATM cards should work. Many gift cards will also work. If you need a card to use, we have some for your use. Also note that if you don’t stop decoding once you receive the stop sentinel (not required), many spaces may be written to the LCD, overwriting some of the data displayed. You may want to swipe only part of the card to avoid this problem.
After you construct your entire circuit, it may not work correctly. Now what? The clock is running so fast (150KHz) that there is no chance of seeing what is going on. We could teach you how to use a logic analyzer, but that would take too much time. What we have done is to implement a stoppable clock. If you switch the board to Step Mode (SW8), when you swipe a card, the FPGA on the board will collect all the signals and then replay them to you as you step the clock. This way, you can see exactly what your circuit does and, we hope, show you the error of your ways. Here is how the debugging interface works:
Connection from cardreader to FPGA:
RCP1 - PD1
RDP1 - PD2
Connection from FPGA to your circuit:
outRDP - PD4
outRCP - PD5
outCLS - PD6
RCP - LD2
RDP - LD3
Common reset - LD6 (wired to
SW8 - same as always
Card Reader pinouts:
Pin 1 (white) - Frame GND
Pin 2 (grey) - Signal GND
Pin 3 (purple) - VCC
Pin 7 (orange) - RDP1
Pin 8 (red) - RCP1
Pin 9 (brown) -
How to use the debugging interface:
1) Press reset (
2) Single step the clock until the LCD is reset and ready for data.
4) Single stepping from here will pipe the data bits out in the following manner:
a) First 3 clock ticks,
b) RCP high 2 clock ticks
c) RCP low 2 clock ticks
d) repeat steps b and c until 32 bits have been delivered
e) last 3 clock ticks,
Here are a couple options for extra credit, and you may add to these if you have a good idea (check with us first).
To get full credit for the final project, turn in the following by the due date: