# Electronic – How to make a 7 to 3 priority encoder

encoder

I'm trying to make a 7 to 3 priority encoder for a circuit diagram for a class. The problem is that we have to take in a 7 bit number and output a 3 bit answer representing the maximum number of consecutive ones in the input.

Example:

``````0011100 = 011 (3)
1111111 = 111 (7)
0000000 = 000 (0)
``````

The issue at the moment is that regardless of the input, it is always outputting 111 (7).

I have circuits for handling every possible combination of consecutive ones in the input, and am then piping that into a 7 to 3 priority encoder, but for some reason the encoder is not working the way it should. What am I doing wrong? Or is there a better way that I should be doing this?

Original Circuit diagram: Attempt 2: • on your diagram, did you confuse `PE2` and `PE3` outputs?
• for `1111111`, `PE1..PE7` are all going to be `1`, so the last diagram would be wrong.
• `NAND` is a much easier function to play with for consecutive `1`s.

here's how I would do it:

``````LEN1 = AND(OR(a,b,c,d,e,f,g),NOR(NAND(a,b),NAND(b,c),NAND(c,d),NAND(d,e),NAND(e,f),NAND(f,g)))
LEN2 = AND(OR(NAND(a,b),NAND(b,c),NAND(c,d),NAND(d,e),NAND(e,f),NAND(f,g)),
NOR(NAND(a,b,c),NAND(b,c,d),NAND(c,d,e),NAND(d,e,f),NAND(e,f,g)))
LEN3 = AND(OR(NAND(a,b,c),NAND(b,c,d),NAND(c,d,e),NAND(d,e,f),NAND(e,f,g)),
NOR(NAND(a,b,c,d),NAND(b,c,d,e),NAND(c,d,e,f),NAND(d,e,f,g)))
LEN4 = AND(OR(NAND(a,b,c,d),NAND(b,c,d,e),NAND(c,d,e,f),NAND(d,e,f,g)),
NOR(NAND(a,b,c,d,e),NAND(b,c,d,e,f),NAND(c,d,e,f,g)))
LEN5 = AND(OR(NAND(a,b,c,d,e),NAND(b,c,d,e,f),NAND(c,d,e,f,g)),
NOR(NAND(a,b,c,d,e,f),NAND(b,c,d,e,f,g))
LEN6 = AND(OR(NAND(a,b,c,d,e,f),NAND(b,c,d,e,f,g)),
NOT(NAND(a,b,c,d,e,f,g)))
LEN7 = NOT(NAND(a,b,c,d,e,f,g))

ANS1 = OR(LEN1,LEN3,LEN5,LEN7)
ANS2 = OR(LEN2,LEN3,LEN6,LEN7)
ANS3 = OR(LEN4,LEN5,LEN6,LEN7)
``````