Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

need help with 8 to 3 encoder in vhdl

Status
Not open for further replies.

rg350dxlover

Member level 1
Member level 1
Joined
Jul 15, 2008
Messages
35
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Malaysia
Activity points
1,566
Hi... I'm new to VHDL and I have to do the code for 8 to 3 encoder. There seem to be a problem with my code but I can't figure out what it is. Help! Thanks... :cool:


library ieee;
use ieee.std_logic_1164.all;

entity encoder is
port( y : in std_logic_vector(7 downto 0);
s : out std_logic_vector(2 downto 0));
end encoder;

architecture behavior of encoder is
begin
with y
s <= "000" when "0000 0001"
"001" when "0000 0010"
"010" when "0000 0100"
"011" when "0001 0000"
"100" when "0010 0000"
"101" when "0100 0000"
"110" when "1000 0000"
end behavior;
 

You dont actually need when others, but without it you will create a latch.

Unless you expressly WANT a latch then you DO NEED the 'when others'. It's generally bad form to not explicitly cover every case.
 
The with-select construct must cover all combinations, so it is not possible to get a latch by skipping one or more cases.
 

The with-select construct must cover all combinations, so it is not possible to get a latch by skipping one or more cases.

I stand corrected. I just confirmed it in my VHDL reference (I dont use with select much).
 

I stand corrected. I just confirmed it in my VHDL reference (I dont use with select much).
I've NEVER used 'with-select' . I use 'case/when' (inside a process). I generally put EVERYTHING in a process. Maybe that's just style, but I don't like to have stuff just floating around free; seems like a good way to make a mistakes. (I also like to clock everything unless there's a good reason not to. At the very least, it will yield better performance.)
 

where is the comma ? , "011" when "0001 0000",
is that the error ? or u put it
 
Thank you all for your help. :smile: I've fixed my code. Added "select", "," and "when others" case and yet there's error. It says that "object with std_logic type cannot contain characters". So meaning I have to change the input and output type? or add library?
 

its probably complaining about the space in the middle of the output word. Either remove it or change it to _
 
Last edited:

Thank you all for your help. :smile: I've fixed my code. Added "select", "," and "when others" case and yet there's error. It says that "object with std_logic type cannot contain characters". So meaning I have to change the input and output type? or add library?

Get rid of that space. "0000 0001"==> "00000001"
 
Thank you all for the help. It's working now! =)
Merry Christmas!
 

A new problem now. How do I connect a module with another one? Like right now, I have decoder, counter, etc. in separate files. How do I put them together?
 

read about COMPONENT INSTANTIATION in vhdl
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top