No more secrets Part 4: Encode and Decode...

Da raspibo.
Jump to navigation Jump to search

Actually it is the reverse way round, let us decode first and encode then.

A decoder

A decoder is a circuit having n input lines and 2^n (2 elevated to the n-th power) output lines.

Each output is true for a specific configuration of the input.

We will implement a 2/4 decoder, i.e. a decoder having 2 inputs and four outputs.

This is its truth table:

IN1 IN0 OUT0 OUT1 OUT2 OUT3
0   0   1    0    0    0
0   1   0    1    0    0
1   0   0    0    1    0
1   1   0    0    0    1

The circuit to implement the decoder is the following:

Decoder.png

And this is the table you can use to set up the jumpers on your breadboard:

IN0->BBEI
IN1->AAGI
A->CE
B->CG
C->DD
D->out0
E->FF
F->out1
G->HH
H->out2
I->JJ
J->out3

To test this circuit, connect a led on each output line. Initially the led on out0 is on, the others off. In fact out0 is 1 when the input configration is 0,0. Now connect in0, in1 or both to the positive line. These configuration should turn on the leds at out1, out2 and out3, respectively, one at at a time.

A priority Encoder

An encoder is the reverse circuit of a decoder: it has 2^n input lines and n output lines.

A "normal" encoder should permit only input configurations in which exactly one input line is one, the others being zero. A 4/2 encoder has the following truth table:

IN3 IN2 IN1 IN0 OUT1 OUT0
0   0   0   1    0    0
0   0   1   0    0    1
0   1   0   0    1    0
1   0   0   0    1    1

Any other input configuration should not be permitted.

A priority encoder is an extension of an encoder. It has 2^n input, n+1 output lines: n of them are the input encoding and one is the valid configuration bit (V) which is one if at least 1 bit in input is one. Each bit represents a priority, when the input configuration is valid (V is 1) the output is the highest priority bit which is 1 encoded in binary.

A truth table can help to understand this concept.

IN3 IN2 IN1 IN0 OUT1 OUT0 V
0   0   0   0    0    0   0
0   0   0   1    0    0   1
0   0   1   0    0    1   1
0   0   1   1    0    1   1
0   1   0   0    1    0   1
0   1   0   1    1    0   1
0   1   1   0    1    0   1
0   1   1   1    1    0   1
1   0   0   0    1    1   1
1   0   0   1    1    1   1
1   0   1   0    1    1   1
1   0   1   1    1    1   1
1   1   0   0    1    1   1
1   1   0   1    1    1   1
1   1   1   0    1    1   1
1   1   1   1    1    1   1

When the IN2 is 1 and none of the input having higher priority than IN2 (i.e. IN3) is 1, the output is 1 0 (2 coded in binary). If IN0, IN1 or IN3has the highest priority "1" in the configuration the output is 0 0, 0 1 or 1 1 (the encoding of 0,1 or 3) respectively.

This is the circuit and the mapping for the jumpers

Priencoder.png

IN3->AA
IN2->BB
IN1->FFD
IN0->GG
A->CE
B->CD
C->II out1
D->E
E->out0
F->H
G->H
H->JJ
I->K
J->K
K->outV

If the circuit works properly, in its starting state, i.e. when all inputs are 0, all outputs should be 0. As usual connect led diodes on the output lines. The output bit V should be 1 when any of the input is one (it works as a 4 inputs OR gate). Try then some configurations from the table above and you'll see the right encoding appears on the output leds.