How-to on PIC equivalent for equality comparator 74HCT688

Thread Starter

beowulf1231

Joined Aug 21, 2008
11
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.
 

Attachments

JDT

Joined Feb 12, 2009
657
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.
 

joeyd999

Joined Jun 6, 2011
4,377
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.
 

John P

Joined Oct 14, 2008
1,808
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.
 

t06afre

Joined May 11, 2009
5,934
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.
This function is more common on the 18F series of PICs
 

ErnieM

Joined Apr 24, 2011
8,040
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.

Rich (BB code):
    CLRF    MyData            ; start with MyData = 0;
TestLoop:
    BTFSS    PORTA,0         ; we check the clock line to be high    3 cycles
    GOTO     TestLoop        ; loop is not set                       2 cycle

;   to get here we have a valid clock hence valid data
;   so read it in bit by bit
    BTFSC    PORTA, 7        ; Test bit 0                            1 cycle
    BSF      MyData, 0       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 5        ; Test bit 1                            1 cycle
    BSF      MyData, 1       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 6        ; Test bit 2                            1 cycle
    BSF      MyData, 2       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 2        ; Test bit 3                            1 cycle
    BSF      MyData, 3       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 1        ; Test bit 4                            1 cycle
    BSF      MyData, 4       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 3        ; Test bit 5                            1 cycle
    BSF      MyData, 5       ; Set data if pin high                  1 cycle

    BTFSC    PORTA, 4        ; Test bit 6                            1 cycle
    BSF      MyData, 6       ; Set data if pin high                  1 cycle

;   now you have the incoming data safely inside the MyData register
;   and we only used 19 cycles
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:
Rich (BB code):
TestLoop:
    BTFSS    PORTA,0    ; bit clear so fall to next instruction, 1 cycle
    GOTO     TestLoop   ; goto is always 2 cycles                2 cycles
    BTFSS    PORTA,0    ; bit set so skip next instruction,      2 cycles
 

Thread Starter

beowulf1231

Joined Aug 21, 2008
11
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.
 

John P

Joined Oct 14, 2008
1,808
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:

Rich (BB code):
....................   if (bit_test(portb, 6)) 
0139:  BTFSS  06,6
013A:  GOTO   13F
....................   { 
....................     if (portd == 'A') 
013B:  MOVLW  41
013C:  SUBWF  08,W
013D:  BTFSC  03,2
....................      bit_set(portb, 5); 
013E:  BSF    06,5
....................
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:

ErnieM

Joined Apr 24, 2011
8,040
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.
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.)
 

MMcLaren

Joined Feb 14, 2010
842
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:

MMcLaren

Joined Feb 14, 2010
842
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.
Does anyone besides me recognize the genius in this simple, clever, and elegant suggestion?
 
Top