priority encoders and encoders vhdl

Status
Not open for further replies.

dinkachikaa

Newbie level 3
Joined
Jan 26, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,301
what is the difference between priority encoder and encoder(without priority) vhdl program and when do we need to use k-map simplification for here?

this is the prog i know for priority encoder:

entity pri_encoder is
port( r: in std_logic_vector(3 downto 0);
code: out std_logic_vector(1 downto 0);
active: out std_logic);
end pri_encoder;
architecture arch of pri_encoder is
begin
code <= "11" when (r(3)=’1’) else
"10" when (r(2)=’1’) else
"01" when (r(1)=’1’) else
"00";
active <= r(3) or r(2) or r(1) or r(0);
end arch;



Is this way of writing in the architecture correct:

entity pri_encoder is
port( r: in std_logic_vector(3 downto 0);
code: out std_logic_vector(1 downto 0);
active: out std_logic);
end pri_encoder;
architecture arch of pri_encoder is
begin
code <= "11" when "1000" else
"10" when "0100" else
"01" when "0010" else
"0000";
active <= r(3) or r(2) or r(1) or r(0);
end arch;
 

what is the difference between priority encoder and encoder(without priority) vhdl program and when do we need to use k-map simplification for here?

Encoding will always be a priority encoder unless the inputs to be encoded are provably mutually exclusive. For example, taking your pri_encoder entity as you've written it there can be the following situations:
- 'r' is a primary input to the FPGA (i.e. it comes in on pins). In this situation, there is no way to guarantee the mutual exclusiveness of the individual bits of 'r', therefore 'pri_encoder' will be implementing a priority encoder.
- 'r' is connected to something that is guaranteed to have mutually exclusive conditions (i.e. only one bit of 'r' will ever be set at one time). In that case 'pri_encoder' can be considered to be implementing an encoder without priority. This can happen when you create a one-hot encoding and connect that to the input of the encoder.

You had a slight error in your second implementation, corrected below.

You have...
code <= "11" when "1000" else
"10" when "0100" else
"01" when "0010" else
"0000";
Should be...
code <= "11" when "1000" else
"10" when "0100" else
"01" when "0010" else
"00";

Kevin Jennings
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…