How-to on PIC equivalent for equality comparator 74HCT688

Discussion in 'Embedded Systems and Microcontrollers' started by beowulf1231, Nov 8, 2011.

  1. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    Hello,

    Im working on a project to catch an ASCII character from a 7-bit dataline and a 1-bit strobe line. The strobe signal is around 20μS long and data bit is around 50μS long.

    My current program uses a series of BTFSC's and BTFSS' to read the 7-bit data and compare with the intended ASCII character. Im counting the number of cycles on my program and it is already beyond 20μS.

    Now for my question, is there a faster way to implement this routine? Something to duplicate the function of 74HCT688 (equality comparator).

    Im planning to catch 3 different ASCII characters and I would need 3 if I use the 74HCT688's.

    Thanks in advance.

    P.S. I attached the datasheet of 74HCT688.
     
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You did not say which PIC you are using?
     
  3. JDT

    Well-Known Member

    Feb 12, 2009
    658
    85
    Connect your 7-bit parallel data to I/O on a single port. When the strobe appears, copy this port to another file register (take a "snapshot"). Then take as long as you like to decode.
     
  4. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    Two fast ways:

    1. Use a 'computed goto' with 128 destinations (1 for each of the 128 possible 7-bit values). Be careful crossing code page boundaries.

    2. If available, use the TBLRD instruction to read the converted value from within a 128 byte long table.
     
  5. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    If you have the PIC16F877 or I don't know which other processors, you have a "parallel slave port" available. The contents of PortD are latched by an external strobe, which also causes an interrupt, or a flag that you can poll.

    As for testing the incoming data, why do it bit by bit? Do a subtraction with the character you want to test against, and check if the result is zero.
     
  6. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    This function is more common on the 18F series of PICs
     
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    As stated, the OPs problem is data only appearing valid for 50μS with a clock signal of 20μS. If we make no assumptions about when this clock signal occurs during the valid portion (meaning the hold time may be zero) then we just have the clock time to read the data.

    If we look at the low end of PIC instruction rates, a 4MHz oscillator yields a 1MHz instruction rate, or 1 instruction per uS. Thus we have at least 20 instructions in this 20 uS slice of time.

    20 instructions is plenty of time to test the clock and acquire 7 arbitrary input pins even using BTFSS's. Code sample below.

    What is unstated in the problem is the data rate, which determines how long we have to process each incoming data chunk.

    Code ( (Unknown Language)):
    1.  
    2.     CLRF    MyData            ; start with MyData = 0;
    3. TestLoop:
    4.     BTFSS    PORTA,0         ; we check the clock line to be high    3 cycles
    5.     GOTO     TestLoop        ; loop is not set                       2 cycle
    6.  
    7. ;   to get here we have a valid clock hence valid data
    8. ;   so read it in bit by bit
    9.     BTFSC    PORTA, 7        ; Test bit 0                            1 cycle
    10.     BSF      MyData, 0       ; Set data if pin high                  1 cycle
    11.  
    12.     BTFSC    PORTA, 5        ; Test bit 1                            1 cycle
    13.     BSF      MyData, 1       ; Set data if pin high                  1 cycle
    14.  
    15.     BTFSC    PORTA, 6        ; Test bit 2                            1 cycle
    16.     BSF      MyData, 2       ; Set data if pin high                  1 cycle
    17.  
    18.     BTFSC    PORTA, 2        ; Test bit 3                            1 cycle
    19.     BSF      MyData, 3       ; Set data if pin high                  1 cycle
    20.  
    21.     BTFSC    PORTA, 1        ; Test bit 4                            1 cycle
    22.     BSF      MyData, 4       ; Set data if pin high                  1 cycle
    23.  
    24.     BTFSC    PORTA, 3        ; Test bit 5                            1 cycle
    25.     BSF      MyData, 5       ; Set data if pin high                  1 cycle
    26.  
    27.     BTFSC    PORTA, 4        ; Test bit 6                            1 cycle
    28.     BSF      MyData, 6       ; Set data if pin high                  1 cycle
    29.  
    30. ;   now you have the incoming data safely inside the MyData register
    31. ;   and we only used 19 cycles
    32.  
    Notes:

    While Port A was used in the example, any combination of input pins would work.

    The 3+2 cycles for TestLoop is the worst case number corresponding to the Clock line going high just after the first BTFSS does the actual test (during start of Q2). In such a case the instruction sequence is:
    Code ( (Unknown Language)):
    1.  
    2. TestLoop:
    3.     BTFSS    PORTA,0    ; bit clear so fall to next instruction, 1 cycle
    4.     GOTO     TestLoop   ; goto is always 2 cycles                2 cycles
    5.     BTFSS    PORTA,0    ; bit set so skip next instruction,      2 cycles
    6.  
     
  8. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    Thanks for the replies guys.

    t06afre, Im using PIC16F690

    JDT, the parallel data is continuously sending 20bytes at a time

    joeyd999, Im a newbie on PIC's, so I havent tried makings tables yet, but I will try to learn this one

    John P, I havent seen this on the PICF690 datasheet, but I wil try out the subtract instruction

    ErnieM, that is what I did the first time, but now I need to catch 3 characters. Got common levels on the same inputs, so I can make GOTO branch-outs but the routine is still over 20uS.

    Guys, another question, are there any side-effects if I set IRCF<2:0> all high to set 8MHz for system clock? The default is 4MHz. Maybe this can solve my timing issue...

    Thanks again guys.
     
  9. John P

    AAC Fanatic!

    Oct 14, 2008
    1,632
    224
    I don't know why anyone would want to do something so simple in such a time-consuming way. I wrote the equivalent in C (tacked onto the end of a program I'm working on) and compiled it. In this case data is assumed to come in on PortD, and PortB.6 is assumed to be the strobe, and PortB.5 is set high if the character 'A' is found:

    Code ( (Unknown Language)):
    1.  
    2. ....................   if (bit_test(portb, 6))
    3. 0139:  BTFSS  06,6
    4. 013A:  GOTO   13F
    5. ....................   {
    6. ....................     if (portd == 'A')
    7. 013B:  MOVLW  41
    8. 013C:  SUBWF  08,W
    9. 013D:  BTFSC  03,2
    10. ....................      bit_set(portb, 5);
    11. 013E:  BSF    06,5
    12. ....................
    13.  
    Edited to say no, I don't think the parallel slave port feature exists on the PIC16F690. You'd need to trigger an interrupt when the strobe arrives (or poll for it continuously, if you really want to do it that way) and then grab the port contents. It seems as if PortC is the only 8-bit port on that processor.
     
    Last edited: Nov 9, 2011
  10. beowulf1231

    Thread Starter Member

    Aug 21, 2008
    11
    0
    Yes, subtraction is the way to go. Thanks John P.

    Lol, why i didnt think of that the first time???
     
  11. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Now I'm more confused then ever. 20 bytes at a time? Is there a window in between these 20 characters for you to process them? If there is 20 bytes what are the 3 characters you are catching?

    As far as changing to 8MHz, go for it. PICs are quite happy running full speed.

    (I run mine at 80MHz with nary a fault evah.)
     
  12. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    I'm curious now... So it seems you're looking at a stream of 20 character records with at least 50 usecs between the start of one character and the next...

    (1) Are these 20 character records delineated?
    (2) Any pre-record or post-record actions required.
    (3) What action after each individual character is recognized? A separate active low output for each character?
    ..(a) Active low for one 50 us character duration or latched until end-of-record?
    ..(b) A cascaded output (all three chars in same record)? If so, what duration for the output?
    (4) Is there a character recognition sequence?

    Yes, use the 8 MHz INTOSC setting... that will give you a whopping 40 instruction cycles during the 20 us strobe to capture the ASCII data and about 100 instruction cycles or more between incoming characters to capture and process data.

    Regards, Mike
     
    Last edited: Nov 10, 2011
  13. MMcLaren

    Well-Known Member

    Feb 14, 2010
    759
    116
    Does anyone besides me recognize the genius in this simple, clever, and elegant suggestion?
     
Loading...