Shop OBEX P1 Docs P2 Docs Learn Events
Magnetic Card Reader and BS2p40 — Parallax Forums

Magnetic Card Reader and BS2p40

skinnydudeskinnydude Posts: 20
edited 2005-07-07 20:19 in BASIC Stamp
I'm trying to read track 1 from a TTL magnetic card reader using the BS2p40 I/O pins.· I think I'm missing data from the read.· Is this PIC fast enough to read the data directly or should I use a FIFO to buffer the data?· As of right now, I'm trying to see if I get a start sentinel before I go any further with the code.

' {$STAMP BS2p}
' {$PBASIC 2.5}
'This will poll the /RCP pin and when it goes low, it will read the /RDP pin
'Constants

'Variables
timeoutcount· VAR·· Word···· 'counter for timeout
data1········ VAR·· Byte···· 'test data
readnum······ VAR·· Word
'I/O Pins used for card reading
nRCP··· PIN 15·· '/RCP input clock
nRDP··· PIN 14·· '/RDP input data
'Initialize I/O pins
INPUT·· nRCP
INPUT·· nRDP
Main:
··· timeoutcount = timeoutcount + 1
··· IF (timeoutcount = 200) THEN
····· DEBUG "timeout, data1 = "
····· DEBUG DEC data1, CR
····· DEBUG "number of bits read = "
····· DEBUG DEC readnum, CR
····· data1 = 0
····· readnum = 0
··· ENDIF
··· IF (nRCP = 0) THEN
····· timeoutcount = 0
····· readnum = readnum + 1
····· data1 = data1 >> 1
····· data1.BIT6 = nRDP^1
····· IF (data1 = %01010001) THEN
······· DEBUG "start sentinel"
····· ENDIF
··· ENDIF
··· DO
··· LOOP UNTIL (nRCP = 1)
··· GOTO Main
· END

Comments

  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-05 15:01
    Hello,

    ···Please provide more information on the card reader so we may attempt to help you.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com


    Post Edited (Chris Savage (Parallax)) : 7/5/2005 3:05:38 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-05 15:03
    I've tried with a couple different readers and have never been happy with the results. The problem is that the clock timing pulse (on my unit, anyway) is too narrow to simply examine the state of a pin, and spread too far apart for PULSIN at "normal" swipe speeds.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-05 15:27
    The card reader I'm using is the Neuron MCR-530N-2R-0201

    I think it is the same as the Magtek version which has a pretty goof PDF at

    http://www.magtek.com/documentation/public/99875148-6.pdf

    If the pulse width for the clock is too narrow, should I use a FIFO to buffer the data first and then manually clock the data in?· If so, do you have any suggestions on a FIFO to use?· Thanks.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-05 15:47
    Okay,

    ·· This doesn't look too complicated.· It looks like when your swipe a card the Card Present line goes low.· At this point you need to start monitoring the Strobe line for transitions (This is the clock line), and for each HIGH to LOW cycle you need to read the state of the DATA line.· A HIGH on the DATA line will be a logic 0, and a LOW will be a logic 1.·

    · It would be helpful to know the bit rate (I didn't look it up), as that would tell you if this could be done with a BASIC Stamp.· If it couldn't, an SX chip would most definately work, and could even be done via an ISR and the data buffered.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-05 16:07
    I think the bit intervals vary depending on how fast I swipe the card or depending on the data on the card itself.· It's rated at 3.39ms - 226us (10-120 cm/s).· Also the clock line is low (valid) for only 1/3 the bit interval.

    Also, the sx chip is runs at 50 MHz, but only does 10k instructions/sec, but the p40 is at 20 MHz Turbo (what does the turbo mean?) and runs 12k instructions/sec.· So the SX would still be faster?

    Post Edited (skinnydude) : 7/5/2005 4:10:44 PM GMT
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-05 16:19
    I think Chris was referring to the core SX chip, not the BS2sx. The core SX (used to make the BS2p, et. al.) can run ~50 million instructions per second when using a 50 MHz clock source. The SX/B compiler makes programming the core SX very simple.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-05 16:37
    Well, I am using the BS2p40 which has the·Ubicom SX48AC microcontroller on it with a 20 MHz clock.· So do you think if I replaced the 20 MHz clock with a 50 MHz clock, it would clock in data correctly?· Or would it be better just to use a FIFO to buffer the data?
  • allanlane5allanlane5 Posts: 3,815
    edited 2005-07-05 17:24
    Yes, use a FIFO. There are WAY too many things that can/will go wrong if you try to change the clock speed. For one thing, every single speed-dependent keyword will run with the wrong timing. That's assuming that the interface with the EEPROM will continue to run at all.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-05 17:28
    Unless you can find a purpose-built FIFO for the mag-stripe reader, your best bet is to create one using an SX chip. And, no, you cannot change the clock on your BS2p to 50 MHz; if you do, it won't work as all instructions (including reprogramming it) are designed for 20 MHz.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-05 17:34
    · Jon has set you on the right path.· I would consider using the SX/B to create an SX-Based interface for the reader that could transfer the data via serial communication.· There are a few ways to go about it.· Interrupts will make things much easier.

    ··· I don't know if you have a loop monitoring the states of those lines if the BS2P40 will be fast enough or not.· I guess you'd need to try it to find out.· I was recently told a BS2 was too slow to read a rotary encoder, but I have the thing working great, and that's considering it has to update the display as I spin the knob.· I had to try it to find out though.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-05 22:43
    ·· By the way, according to an e-mail sent to support it appears that you have some trial test code for this application.· One thing I see that could hinder it functioning properly is DEBUG statements (At least one) during the routine reading the data from the card.· The DEBUG statement will severely inhibit reading bits like that at high speed.· You should buffer the whole stream of bits then display the output to the DEBUG screen.



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-06 16:13
    I'm not printing anything to the screen until I get either good data or a timeout, so I would assume it wouldn't slow the read down unless it has to print anything out.· I'm going to try to use a Xilinx CPLD to make a FIFO.· What is the minimum voltage level that needs to be used in the input pin on the BS2p40?· The Xilinx can output 3.3v or I could use a pullup for a 5v source.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-06 16:21
    The BASIC Stamp sees 1.4v as "1" -- unless you're using the BS2px and configure pins for CMOS levels; that changes it to 2.5v.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-07 15:05
    It does seem like the BS2p40 is too slow to read the data input.· I saw that there was a new BASIC Stamp 2px 24-Pin Module which runs at 32 MHz.· I was wondering if you think that this will be fast enough to read the pins and if it will work in the BS2p24/40 Demo Board for testing.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-07 15:10
    ·· I think Jon had the best suggestion...The SX chip would have more than ample processing power, and could be setup as a co-processor with a serial interface.· You could also have a buffer (FIFO).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-07 15:39
    I think the BS2p40 and BS2px has the SX chip on it.· When you say SX chip, you mean the Ubicom SX48AC, right?· I was trying to keep costs down by not using a FIFO or USART.

    How do you set the SX chip up as a co-processor with serial interface?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 16:01
    The SX/B help file (attached) has examples.· You can get an SX starter kit for the same price as a premium BASIC Stamp -- and then you'll have the tools to develop other projects.· We appreciate you being a customer, and want to make sure that you use the right tools for the job you want to do.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    chm
    452K
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-07 16:34
    ·· And once you have the development kit, you can program other SX chips for other applications, and each is under $5.00 per chip!· Not too shabby for making your own controllers.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-07 16:42
    If the BS2p40 has the SX chip on it, what's the difference between programming the basic stamp and using the SX development board?· Shouldn't the speed of reading the input pins be about the same, or does the basic stamp compiler do lots of other instructions to slow down the reading of the input pins?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2005-07-07 16:51
    ·· The SX Chip on the BS2p Stamp Modules is running the BASIC interpreter, which is reading tokenized BASIC data from the EEPROM on the module.· The SX chip running raw assembly language and at 50 Mhz is going to be a·lot faster.· There are some trade-offs, but the SX chip can also do interrupts.· This could be a bonus in your situation.· The 2 chips would work in conjunction.· The SX code to do what you need doesn't really need to be very complex.· You basically want a co-processor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 16:52
    No, what you're missing is that BASIC Stamp modules are running an interpreter that needs to fetch its instructions from an outside EEPROM -- this takes time and slows overal execution speed.· If you program an SXmicro in SX/B (similar to PBASIC) you're running the program directly in assembly (after compiling and downloading), thus getting full speed from the processor.· SX/B doesn't have all the niceties (like 16-bit variables, multiple output variables in many commands, etc.)·of PBASIC, but it's pretty close and (in my opinion) perfect for building accessory projects like yours.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 7/7/2005 6:18:17 PM GMT
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-07 19:23
    Ah, ok.· Now everything makes sense.· So before I go out and order stuff, I want to make sure I'm ordering the right development boards.· I was looking into getting this

    http://www.parallax.com/detail.asp?product_id=45181

    and getting this just in case I need it

    http://www.parallax.com/detail.asp?product_id=45300
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 19:29
    The 45181 gives you all the development tools (including the SX-Tech board with an SX28) that you need. Since your requirement isn't I/O intensive, you don't need the 45300 unless it's just for future projects and taking advantage of the boss's maniacal pricing on that product.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • skinnydudeskinnydude Posts: 20
    edited 2005-07-07 19:40
    Great, thanks!· I'll probably order both b/c the 45300 has more ram and EEPROM just in case I need it.· I need to be able to hopefully outpout data to an LCD and pass the data back and forth serially to another computer.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-07-07 20:19
    The SX/B help file shows how to connect to a parallel LCD -- you can use that as a starting point.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.