This is a multipart message in MIME format. ------=_NextPart_000_00A8_01C85D95.6A948E10 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello, This mail is longer than I expected. I'm sorry for that. The basic issue is about the IOC feature, specifically trying to read a wiegand package. I'm trying to read a card number using a wiegand output reader. I'm using a PIC16F88x so I'm using the full portb interrupt on change. The IOC is properly set on by setting ICB<1:0> bits, since I'm using RB0 and RB1. On the interrupt, when IOC is detected I have the following code: if( RBIF && RBIE ) { RX_TEMP = PORTB; // Read PORTB RX_TEMP &= 0x03; // Leave only the necesary bits if( (RX_TEMP != 0x03) && RX_TEMP ) // Both bits can't be 1 or 0 at the same time *ERROR CONDITION* { if( RX_TEMP & 0x01 ) // If RB0 is 1 { getCardData( 1 ); } else { getCardData( 0 ); } wait = 2; // Wait for 500 uS RBIE = 0; // Disable IOC for the above time timeout = 200; // Timeout end of card (50 ms) } RBIF=0; //Clear IOC bit } Well, that's the basic code. It's working mostly, except that every once in a while, an interrupt generates but the code reads a bit incorrectly. The "wait" is used to avoid the IOC to interrupt when the wiegand signals return to high level. Since the wiegand LOW pulse is aprox. 40-50 uS and the space between bits is 2mS, the 500uS should be fine. Once the 500uS have finished the IOC interrupt is enabled: RX_TEMP = PORTB; RBIF = 0; RBIE = 1; This procedure is to ensure that any interrupt is clear before re-enabling the IOC. Problems: Once a read is finished, the firmware outputs a stream of data trough the serial port (see attached file). The correct number of the card should be FC 081 and Card No. 00695. As you can see, the number is read ok most of the time, but the parity is not. Page 2 here explains how the parity should be. http://www.hidcorp.com/documents/understandCardDataFormats_wp_en.pdf In the beginning I was using the internal oscillator, but that lead to aprox. 4 to 6 *ERROR CONDITIONS* detected, when I change the oscillator to 20 MHz external, that count went down to 0 to 1. That makes me wonder if there should be something I'm missing about the whole IOC feature. Regards, Mauricio ------=_NextPart_000_00A8_01C85D95.6A948E10 Content-Type: text/plain; name="output.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="output.txt" Facility Code: 081 Card Number: 00695 01010001 ** 1st byte read MSB on the left 00000010 ** 2nd byte read MSB on the left 10110111 ** 3th byte read MSB on the left 00000010 ** 4th byte read use only the last two Parity ERROR // Parity is not according the wiegand standard Using the above information, to form the card no: E FFFFFFFF CCCCCCCCCCCCCCCC O 01010001 00000010 10110111 XXXXXX10 -> 0 10100010 0000010101101111 0 bit no 0 12345678.... E: Even Parity F: Facility Code C: Card Number O: Odd Parity The parity is calculated as follow: Even parity: using bits 1 to 12 Odd parity: using bits 12 to 25 Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 162 ****** WRONG NUMBER ********* Card Number: 01390 10100010 00000101 01101110 00000000 Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 081 Card Number: 00695 01010001 00000010 10110111 00000010 Parity ERROR Facility Code: 162 Card Number: 01390 10100010 00000101 01101110 00000000 ------=_NextPart_000_00A8_01C85D95.6A948E10 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist ------=_NextPart_000_00A8_01C85D95.6A948E10--