Reading input pins @ timed intervals and storing in an array
JetMan
Posts: 39
I'm working on creating a card reader solution for my house. I have currently connected a wiegand card reader to pins 0..1 of my prop. I'm attempting to figure out how to correctly time the reading of the pin pulses and then compile them in to one long binary value once done.
The wiegand data stream flows at approximately 50us pulses with 1ms mark space. pins are alternating data (when P0 goes high it equals a zero , when P1 goes high it equals a one)
this is my code so far , but I keep getting random numbers that never change despite reading different cards.
Wiegand Reader.spin
The wiegand data stream flows at approximately 50us pulses with 1ms mark space. pins are alternating data (when P0 goes high it equals a zero , when P1 goes high it equals a one)
this is my code so far , but I keep getting random numbers that never change despite reading different cards.
{{ 26-Bit Wiegand Card Reader }} CON _clkmode = xtal1 _xinfreq = 8_000_000 OBJ pst : "Parallax Serial Terminal" VAR byte WD1 byte bitcount byte RX_DT[26] long bit_time long space_time PUB ReadCard pst.Start(115_200) bit_time := 400 '640 = 80us space_time := 8_000 '8_000 = 1ms bitcount := 0 dira[0..1]~ dira[16]~~ Repeat bitcount := 0 If INA[0] <> INA[1] CDR PUB CDR pst.str (String(pst#CS)) repeat 26 If INA[0] := 1 byte[@RX_DT][bitcount] := 1 bitcount ++ waitcnt (bit_time + cnt) If INA[1] := 1 byte[@RX_DT][bitcount] := 0 bitcount ++ waitcnt (bit_time + cnt) waitcnt (space_time + cnt) repeat 26 pst.Str (String(pst#NL,"Bit:")) pst.dec (WD1++) pst.str (String(pst#TB,"Dat:")) pst.dec (RX_DT[bitcount]) bitcount ++ bitcount := 0
Wiegand Reader.spin
Comments
You need to synchronize to the low to high edges of the signals. The fastest way is to use waitpne / waitpeq.
I think it is also much simpler to collect the bits at the moment you receive them, insted of storing them in an array first.
Here is a possible code: This expects always 26 bits for one value, I don't know this wiegand protocoll, so I can't say if this is always the case. I also don't know it is LSB first or MSB first (the code above is for MSB first).
Andy
Edit: changed the debug output a bit after googling the wiegand protocol.
Thanks for the reply . I've tried using waitpne and waitpeq previously also with no results. I sampled your code into my project and it still produces all zeroes. I've tried several different permutations of code but so far all I've been able to get is some repeating numbers using a series of if statements. I don't know what I'm missing but it's driving me nuts here. I know the prop is seeing my pins change state and I know the card reader output is as specified because I monitored both pins using my o-scope. ???????
One other thing you could try first is program a counter in POSEDGE mode on the one-bit. Then - after you detected the pin change - you simply look at the counter, e.g. This reads the bit value (0/1, frqa == 1) and (post-)clears it for the next event. HTH
You need be happy that You can run Propeller on 8MHz Crystal at all.
Edited:
PLL8x and smaller shall be possible
To use pll16x You can't have any crystal that is bigger as 7MHz
This test program should give us an idea what's coming to those pins. You'll have to add display code and clock setup: