CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

HELP WITH WIEGAND DATA READ!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
janiga



Joined: 10 Apr 2006
Posts: 22

View user's profile Send private message

HELP WITH WIEGAND DATA READ!
PostPosted: Sun Apr 29, 2007 3:35 am     Reply with quote

Can someone see this code for errors. I am reading two inputs, one is data high one is data low. I need pulses 2 thru 25 (24 bit number) for my data. I have spent fustrating endless hours without success by rewriting code over and over, i am going crazy...HELP! Crying or Very sad

Link to wiegand protocol
http://www.kerisys.com/pages/download/techdocs/Pyramid_Series_Wiegand_Data_Format_Reference_Document.pdf
I cannot obtain the proper numbers in buffer after the 24 bit stream is read. I am reading only 2nd pulse on to 25th, thats were the data is, no parity checking for now which is bit 1 and 26.

Compiler Version 3.242
Device is pic16f917

Code:

#include <16F917.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz)
#FUSES PUT                      //Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOCPD                    //No EE protection
#FUSES BROWNOUT                 //Reset when brownout detected
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled
#FUSES NODEBUG                  //No Debug mode for ICD
#use delay(clock=20000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=9)

#include "C:\MEM TEST.h"
#include <LCD>
#include <25LC1024.c>
#include <STDLIB>
BYTE BUFFER[3];
INT I;
void main()
{
setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_OFF);
   setup_spi(FALSE);
   setup_lcd(LCD_DISABLED);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_16);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DIV_BY_16,255,16);///////setup_timer_2(T2_DIV_BY_16,249,10);
   setup_ccp1(CCP_PWM);
   setup_comparator(NC_NC_NC_NC);
   setup_vref(FALSE);
   lcd_init();
   setup_oscillator(False);

WHILE (TRUE){
printf(lcd_putc,"\fREADY");
WHILE (INPUT(PIN_D1)==1 || INPUT(PIN_D0)==1);
DELAY_MS(1);
FOR (I=0; I<=23;)
{
       WHILE (INPUT(PIN_D1)==1 || INPUT(PIN_D0)==1);
       IF (INPUT(PIN_D1)==1)
       {
       shift_left(BUFFER,3,1);
       ++I;
       WHILE (INPUT(PIN_D1)==0);
       }
       IF (INPUT(PIN_D0)==1)
       {
       shift_left(BUFFER,3,0);
       ++I;
       WHILE (INPUT(PIN_D0)==0);
       }
}
printf(lcd_putc,"\fDATbyte1 \n%x",BUFFER[0]);
DELAY_MS(2000);
printf(lcd_putc,"\fDATbyte2 \n%x",BUFFER[1]);
DELAY_MS(2000);
printf(lcd_putc,"\fDATbyte3 \n%x",BUFFER[2]);
DELAY_MS(2000);
printf(lcd_putc,"\fCOUNT \n%U",I);
DELAY_MS(2000);

}
}


Last edited by janiga on Sun Apr 29, 2007 11:31 am; edited 2 times in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Apr 29, 2007 6:48 am     Reply with quote

First remark: Don't use compiler version 4.013, it's an alpha release of the new v4.xxx compiler with many bugs. The last known stable compiler version is v3.249 which can still be downloaded from the website. If you really have to use a v4 compiler than use version 4.030 or higher, these versions are reported to become more usable.

Than on your program, can you provide some more information? What is working and what is not? What is the protocol you are trying to read? Even better when you can post a link to a document describing the protocol.

Always post a short and _complete_ program that we can compile without any editting. As it is now we don't know what is in all the include files, especially the #fuses settings and #device directive are missing.
janiga



Joined: 10 Apr 2006
Posts: 22

View user's profile Send private message

Update
PostPosted: Sun Apr 29, 2007 11:21 am     Reply with quote

Using 3.242 again and updated with link to what is actually being read. I get buffer read and write but data is not proper.

Thanks!
Ttelmah
Guest







PostPosted: Mon Apr 30, 2007 3:24 am     Reply with quote

Which means you are probably reading at the wrong time, or on the wrong edge. Smile

The tests seem to be wrong in the data input loop. If 'D1' is high (this appears to be the 'Data low' bit), then after shifting the bit in to the output register, you need to wait for 'D0' to rise (since this triggered the read).

So you need:
Code:

   //Why increment the counter in two places?.
   FOR (I=0; I<=23;I++) {
       //wait for one pin to drop
       WHILE (INPUT(PIN_D1)==1 && INPUT(PIN_D0)==1);
       //You are looking for either pin to drop, unless your signal
       //is inverted from the normal Wiegand format. Hence ought to
       //be '&&', not '||'?. Same applies on the first test outside this
       //loop.

       IF (INPUT(PIN_D1)==1) {
          //data low=1, so shift in a '1'
          shift_left(BUFFER,3,1);
          //now wait for the _other_ line to rise
          WHILE (INPUT(PIN_D0)==0);
       }
       else {
          //If the other line is high, then this one _must_ have fallen
          //shift in a zero
          shift_left(BUFFER,3,0);
          WHILE (INPUT(PIN_D1)==0);
       }
   }

Now your tests, seem to imply you may have inverted Wiegand data?.
Personally, I'd handle the tests very differently, and just have something like:

while ((input_d() & 3) == 3)

(if the lines are normal Wiegand format).
This will be quicker.
I would not delay for 1mSec after the first edge is seen, but just for slightly over the 50uSec, defined for the low time of the Wiegand data.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group