# 3 to 8 decoder: simple circuit

Here will be explained on the decoder 3 to 8 in a simple. This decoder has 3 inputs and 8 outputs. Input is a binary combination of 0-7, one output will be logic 1 corresponds to the binary input.
The truth table is shown below.

C B A Q0 Q1 Q2 Q3 Q4 Q5 Q6 Q7
0 0 0 1 0 0 0 0 0 0 0
0 0 1 0 1 0 0 0 0 0 0
0 1 0 0 0 1 0 0 0 0 0
0 1 1 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 1 0 0 0
1 0 1 0 0 0 0 0 1 0 0
1 1 0 0 0 0 0 0 0 1 0
1 1 1 0 0 0 0 0 0 0 1

From the truth table above, one utput will be logic 1 depending on the binary input. If the binary input 000 (0 in decimal) output Q0 = 1, other output = 0. If the binary input 101 (5 in decimal) output Q5 = 1, other output = 0. Its means that every single output representing each state of binary inputs. Output is active if logic 1.

Input and output channels each is treated here as channel bits. The block can be described as follows:

### 3 to 8 decoder: non array

Block of decoder on the left is illustrated with line input and output separately for every bit.  Actually this way is intended to clarify that the required programming ideas in simple writing program. Programming here does not consider the efficient programming techniques. It aims to provide a lot of consideration and show that efficient programming is with a simple description.

Another explanation, the input and output channels will be treated as arrays. So that would seem programming will be easier and simpler.

Entities blocks can be written as follows:

    entity decoder is
Port (  A  : in STD_LOGIC;
B  : in STD_LOGIC;
C  : in STD_LOGIC;
Q0 : out STD_LOGIC;
Q1 : out STD_LOGIC;
Q2 : out STD_LOGIC;
Q3 : out STD_LOGIC;
Q4 : out STD_LOGIC;
Q5 : out STD_LOGIC;
Q6 : out STD_LOGIC;
Q7 : out STD_LOGIC
);
End decoder;


Block of the process can be written as follows:

begin
process (A,B,C)
begin
if A='0' and B='0' and C='0' then
Q0<='1'; Q1<='0'; Q2<='0'; Q3<='0';
Q4<='0'; Q5<='0'; Q6<='0'; Q7<='0';
end if;
if A='1' and B='0' and C='0' then
Q0<='0'; Q1<='1'; Q2<='0'; Q3<='0';
Q4<='0'; Q5<='0'; Q6<='0'; Q7<='0';
end if;
if A='0' and B='1' and C='0' then
Q0<='0'; Q1<='0'; Q2<='1'; Q3<='0';
Q4<='0'; Q5<='0'; Q6<='0'; Q7<='0';
end if;
if A='1' and B='1' and C='0' then
Q0<='0'; Q1<='0'; Q2<='0'; Q3<='1';
Q4<='0'; Q5<='0'; Q6<='0'; Q7<='0';
end if;
if A='0' and B='0' and C='1' then
Q0<='0'; Q1<='0'; Q2<='0'; Q3<='0';
Q4<='1'; Q5<='0'; Q6<='0'; Q7<='0';
end if;
if A='1' and B='0' and C='1' then
Q0<='0'; Q1<='0'; Q2<='0'; Q3<='0';
Q4<='0'; Q5<='1'; Q6<='0'; Q7<='0';
end if;
if A='0' and B='1' and C='1' then
Q0<='0'; Q1<='0'; Q2<='0'; Q3<='0';
Q4<='0'; Q5<='0'; Q6<='1'; Q7<='0';
end if;
if A='1' and B='1' and C='1' then
Q0<='0'; Q1<='0'; Q2<='0'; Q3<='0';
Q4<='0'; Q5<='0'; Q6<='0'; Q7<='1';
end if;

end process; 

Because input and output channels are not defined as an array, then the statement in the “process block” can not be written in short.
Furthermore, the input and output channels will be defined as an array. The block can be described as follows:

### 3 to 8 decoder: array

By treating an array of input and output channels, the program that has the relationship between the data D [3 .. 0] with Q [7 .. 0] will be easily written down and become simpler.

Entities blocks can be written as follows:

### 3 to 8 decoder: array

By treating an array of input and output channels, the program that has the relationship between the data D [3 .. 0] with Q [7 .. 0] will be easily written down and become simpler.

Entities blocks can be written as follows:

        entity decoder is
Port (  D : in STD_LOGIC_VECTOR (2 downto 0);
Q : out STD_LOGIC_VECTOR (7 downto 0)
);
end decoder;


The use of the array will cause the writing in “Process Block” to be more simple like the following:

        begin
With D Select Q
"00000001" when "000",
"00000010" when "001",
"00000100" when "010",
"00001000" when "011",
"00010000" when "100",
"00100000" when "101",
"01000000" when "110",
"10000000" when others;

DEMO
Good Luck...

Last updated by at .