Priority Encoder is an important class of Encoder. It is different from a ordinary encoder in that it gives priority to the input signal. The signal corresponding to the higher priority is outputted by the Priority encoder.
Here the design of 8 to 3 priority encoder is taken as an example for VHDL programming tutorial.
The truth table of a 8 to 3priority encoder is shown below:
In the truth table, the input data is x7x6x5x4x3x2x1x0 which is 8 bit input. And the 3 bit output is y2y1y0. The z signal indicates a condition that all input bits are 0 which is also a possible combination.
The priority is the signal with input 1XXXXXXX where X indicates dont care which means it does not matter whether it is 0 or 1. The next priority goes to 01XXXXXX and so on up on the table.
Suppose if 10100110 is the input data then the output is 111.
Below is the VHDL code for this 8 to 3 priority encoder:
library ieee;
use ieee.std_logic_1164.all;
entity prio_encoder is
port(
x : in std_logic_vector(7 downto 0);
y : out std_logic_vector(2 downto 0);
z : out std_logic
);
end prio_encoder;
architecture model of prio_encoder is
begin
process(x)
begin
if (x(7) = 1) then y <= "111";
elsif (x(6) = 1) then y <= "110";
elsif (x(5) = 1) then y <= "101";
elsif (x(4) = 1) then y <= "100";
elsif (x(3) = 1) then y <= "011";
elsif (x(2) = 1) then y <= "010";
elsif (x(1) = 1) then y <= "001";
else y <= "000";
end if;
end process;
z <= 0 when x = "00000000" else 1;
end model;
In the above code, we used if elsif then statement of VHDL to implement the priority encoder. Since the if statement is a sequential state it is written inside the Process statement with sensitivity signal as x. The first statement is checked first and then next statement inside a process since the statements are sequential. If the first statement is true then the output is send to the output and the process exits. If not then the second statement is checked and if it evaluates true then it corresponding output is outputted and so on. So this code implements priority.The last else statement is needed so that the synthesizer does not create a latch. That is all combination of the input must be included. Finally the z output when all inputs are 0s is implemented outside the process statement.
The simulated waveform is shown below:
Encoders are important part of a digital system. There are other application of encoders such as code conversion encoders and includes designs that needs to be encoded to reduce output signals.
Here the design of 8 to 3 priority encoder is taken as an example for VHDL programming tutorial.
The truth table of a 8 to 3priority encoder is shown below:
In the truth table, the input data is x7x6x5x4x3x2x1x0 which is 8 bit input. And the 3 bit output is y2y1y0. The z signal indicates a condition that all input bits are 0 which is also a possible combination.
The priority is the signal with input 1XXXXXXX where X indicates dont care which means it does not matter whether it is 0 or 1. The next priority goes to 01XXXXXX and so on up on the table.
Suppose if 10100110 is the input data then the output is 111.
Below is the VHDL code for this 8 to 3 priority encoder:
library ieee;
use ieee.std_logic_1164.all;
entity prio_encoder is
port(
x : in std_logic_vector(7 downto 0);
y : out std_logic_vector(2 downto 0);
z : out std_logic
);
end prio_encoder;
architecture model of prio_encoder is
begin
process(x)
begin
if (x(7) = 1) then y <= "111";
elsif (x(6) = 1) then y <= "110";
elsif (x(5) = 1) then y <= "101";
elsif (x(4) = 1) then y <= "100";
elsif (x(3) = 1) then y <= "011";
elsif (x(2) = 1) then y <= "010";
elsif (x(1) = 1) then y <= "001";
else y <= "000";
end if;
end process;
z <= 0 when x = "00000000" else 1;
end model;
In the above code, we used if elsif then statement of VHDL to implement the priority encoder. Since the if statement is a sequential state it is written inside the Process statement with sensitivity signal as x. The first statement is checked first and then next statement inside a process since the statements are sequential. If the first statement is true then the output is send to the output and the process exits. If not then the second statement is checked and if it evaluates true then it corresponding output is outputted and so on. So this code implements priority.The last else statement is needed so that the synthesizer does not create a latch. That is all combination of the input must be included. Finally the z output when all inputs are 0s is implemented outside the process statement.
The simulated waveform is shown below:
Encoders are important part of a digital system. There are other application of encoders such as code conversion encoders and includes designs that needs to be encoded to reduce output signals.
0 comments:
Post a Comment