BIGMAC,I tried to make this Wiegand routine and I failed.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

BIGMAC,I tried to make this Wiegand routine and I failed.

4,952 Views
ganimides
Contributor I
Hi Bigmac!,
 
In my eagerness to make the things well I tried to make this code to read a Wiegand device but I had no luck.
 
Here I attached for you the timing of this protocol so that you can see if it agrees with my code or not.
 
Code:
unsigned int Read20BitData(void) {                unsigned char count;        unsigned int bits;        count = 0;             //size of each word        bits = 0;        for(count = 0;count < 20;count++)                 {                 bits = bits << 2;  //<< 1;                 //make room for next bit by shifting the result                for (;PTA_PTA2 == 1;)    __RESET_WATCHDOG(); // feeds the dog //wait for clock edge                for (;PTA_PTA2 == 0;)    __RESET_WATCHDOG(); // feeds the dog wait for clock edge                                if ((PTA_PTA3) == 1)                                 bits|= 1;       //either set                         else bits &= ~0xfffffffe;  //or clear LSB in bits                };         return bits;   };        /*************************************************        *              main routine*************************************************/void main(void) {                        DDRA_DDRA2 = 0                DDRA_DDRA3 = 0; //set one pin as an output                        //make PTB2 an output  for(;;) {         result = Read20BitData();    //read 20 bit word        }   };

 

  First,I have no idea if the data are stored right well into the var.¿How can data be viewed by a simulator?...the var is called "result".
 
 
Second,The data from device are delivered in ASCII format  and my LCD routines converts the BCD data to ASCII so I imagine that I just need some ASCII to BCD or ASCII to Binary trick to rebuild the data and 
display the right values on LCD.¿how can I do this?.
 
My functions is like this:
 
Code:
void printf_LCD_4bits(unsigned char fila, unsigned char columna, char *texto,char value){ unsigned char adrs;      adrs = columna - 1;   if(fila == 2)    adrs = adrs | 0x40; Ctrl4bits(adrs | 0x80); while(*texto)     Datos4bits(*texto++); // Datos4bits(':');  //Datos4bits( ((value%1000)/100)+0x30);  //Datos4bits( ((value%100)/10)+0x30); ----->this converts BCD to ASCII.I need the opposite  //Datos4bits( (value%10)+0x30);Datos4bits( (value%10)+0x30);}

 
 
Thank you BIG.
 
Have a nice week.
 
 
Ganimides
 

Message Edited by Alban on 2006-09-06 01:55 PM

Labels (1)
0 Kudos
7 Replies

798 Views
bigmac
Specialist III
Hello Ganimides,
 
I think there may be a misunderstanding with the way the Wiegand protocol works, although I am no expert in the matter.
 
  1. The timing in the diagram previously posted - the period between pulses should be approximately 2 milliseconds (not 2 microseconds).
  2. There are actually two data lines DATA0 and DATA1 required, that need to be simultaneously monitored, since the next data pulse could occur on either line.  Whether this data bit is zero or one will depend on the line on which the pulse occurs.  I presume you are using PTA2 and PTA3 for the lines, but it is not clear which way round.
  3. I understand one of the "standard" Wiegand protocols starts with a parity bit for the first 12 data bits, followed by 24 data bits, and ends with a parity bit for the last 12 data bits, a total of 26 bits.  The transmission time would be about 50 milliseconds.  Perhaps you need to check the data sheet for the reader, to clarify whether there are only 20 data bits and no parity bits.  You should also clarify whether the data bits represent BCD digits (nybbles), or ASCII characters (bytes).  Obviously 20 data bits does not give an integral number of bytes. Also check whether the transmission is LSB or MSB sent first.
  4. In order to synchronize the decoding process to the transmission, you would need to keep track of the period between pulses (on either line).  If this should exceed, say 200 milliseconds, you would know that the next pulse received was the first pulse of a new data block.
In view of the lengthy transmission period, there may be some advantage in using interrupts for the detection of each pulse, possibly two channels of KBI.  Global variables would be necessary for the data buffer, a bit counter, and possibly a flag to indicate when a transmission is completed, and further processing may take place (external to the ISR).  For the timing function, you could keep tabs of the number of timer overflows that occurred between data pulses.
 
Regards,
Mac
 
 
 
 

Message Edited by bigmac on 2006-09-06 05:45 AM

0 Kudos

798 Views
ganimides
Contributor I
Hi Big!.
 
PTA2 is CLK and PTA3 is DATA.THis device delivers ASCII data format.
 
All is nice but I need some routine where I`ll be able to research of.
 
 
Thanks.
 
 
Ganimides.
 
0 Kudos

798 Views
bigmac
Specialist III
Hello Ganimides,
 
If your reader has output lines identified as DATA and CLK, its output would not be Wiegand protocol, which requires DATA0 and DATA1 output lines, as previously explained.
 
Regards,
Mac
 
0 Kudos

798 Views
ganimides
Contributor I
Dear Big:
 
You are wrong.
 
My device is GP8F-W5 (it`s a low cost proximity card reader and the W5 means Wiegand) and in the catalog it is showed as WIEGAND).
 
THey have other devices just like GP8F-R2 (it`s a asinchronous serial port TTL which can work as RS232 adding a MAX232.)
 
If you want to take a look you can go to this link http://www.cika.com/quotation/search.php?prod_id=10.01.03.It`s  it`s in spanish language but it`s going to be usefull anyway so that you can take a look.
 
Besides, DATA0,DATA1 and DATA and CLK are the same thing.
DATA1 would be the CLK output.
 
I guess it depends on manufacturer.
 
Thank you for  the feedback.
 
 
have a nice week.
 
 
Ganimides.
 
0 Kudos

798 Views
Jaux
Contributor I
I have developed a Wiegand reader using the 908RS12 chip and that reply with the processed code via the RS-232 interface.

It was done in assembler - if you are interested let me know and I will post
0 Kudos

798 Views
Jaux
Contributor I
There are two standard formats for the output of a Wiegand reader : Data0, Data1 and Data ,Clock.

The difference is that the D0/D1 format send 0's and 1's on the two different channels and D/C sends 1's and 0's on Data and you will have to use the Clock signal to latch the data from this stream.
0 Kudos

798 Views
mrmc88
Contributor I
I know this post happened a long time ago but Jaux do you by chance still have that Wiegand code? If you do could you please post or email it, thanks!
0 Kudos