FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-08-2006, 06:40 AM
Geo
Guest
 
Posts: n/a
Default Simple problem, understanding the case sentence

Hi, I've just started a digital electronics course where we will be
mainly working with VHDL, I've started reading a book and trying some
of the exercises. I'm just starting VHDL and got some problems with an
exercise requiring to describe a 2-to-1 multiplexer using a CASE
statement (in the sequential statements chapter).

I've already implemented the multiplexer using a when statement in the
output assignent, but failed when trying with the case statement, see:

Code:
library ieee;
use ieee.std_logic_1164.all;

entity multiplexor is
port(
entrada0, entrada1: in std_logic;
selector: in std_logic;
salida: out std_logic
);
end multiplexor;

architecture comp_multiplexor of multiplexor is
begin
-- it works using this:
-- salida <= entrada0 when selector = '0' else entrada1;

-- but this one doesn't work:
case selector is
when '0' => entrada0;
when '1' => entrada1;
end case;


end data_flow;
Am I doing things correctly? The compiler tells me about an unexpected
prefix for a array/slice/ (or something like that) on the when choices
lines.

I have problems with another exercise, however I'm sure it's about the
same thing (it's a 2-4 decoder using a CASE statement too), but I'd
like to ask if it's possible to do something like this:

entity dec24 is
port( ...
input: in std_logic_vector( 1 downto 0 );
output: out std_logic_vector( 3 downto 0)
);
end dec24

architecture bhv_dec24 of dec24 is
begin
case input is
when B"00" => ...
when B"01" => ...
...
end case;
end bhv_dec24;
[/code]
My question is about the when B"00" choices, is it correct to use such
a expression here?

Also, would the next expression be ok?

output <= ( 0 => '1', others => '0' );

I would use this one, for example, in the when B"00" choice for
assigning '1' to the appropiate output bit and '0' to all of the
others.

Last, I'd like to apologize for having some none English identifiers in
the first code, I'm not a native English speaker and just copied&pasted
that one. Thanks in advance for your help.

Regards,
José Jorge Enríquez.

PS: sorry for my poor English.

Reply With Quote
  #2 (permalink)  
Old 02-08-2006, 07:10 AM
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence

Hola José,

you have to use the case statement within a PROCESS.

ARCHITECTURE xy OF ts IS

BEGIN

PROCESS(Selector, a, b)
BEGIN
CASE Selector IS
WHEN '1' => Salida <= a;

WHEN '0' => Salida <= b;

END CASE;
END PROCESS;

END xy;

Rgds
André

Reply With Quote
  #3 (permalink)  
Old 02-08-2006, 11:47 AM
vishnu
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence

i think it will work if you like this
library ieee;
use ieee.std_logic_1164.all;


entity multiplexor is
port(
entrada0, entrada1: in std_logic;
selector: in std_logic;
salida: out std_logic
);
end multiplexor;


architecture comp_multiplexor of multiplexor is
begin
case selector is
when '0' => salida<=entrada0;
when '1' => salida<=entrada1;
end case;


end data_flow;

Reply With Quote
  #4 (permalink)  
Old 02-08-2006, 07:05 PM
Geo
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence

That's it! I just didn't notice any comment/advice about it, thank you.

Best wishes,
José Jorge Enríquez.

Reply With Quote
  #5 (permalink)  
Old 02-08-2006, 07:09 PM
Geo
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence

Thanks for your comments, I just didn't pasted the the correct code
here :P. (You can see the end data_flow at the end of the code that
does not match any previously declared identifier).

The solution is to place the case statement within a process, as André
pointed out in the previous post.

Thanks (and sorry for posting incorrect code),
José Jorge Enríquez.

Reply With Quote
  #6 (permalink)  
Old 02-09-2006, 06:27 PM
Isaac Bosompem
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence


vishnu wrote:
> i think it will work if you like this
> library ieee;
> use ieee.std_logic_1164.all;
>
>
> entity multiplexor is
> port(
> entrada0, entrada1: in std_logic;
> selector: in std_logic;
> salida: out std_logic
> );
> end multiplexor;
>
>
> architecture comp_multiplexor of multiplexor is
> begin
> case selector is
> when '0' => salida<=entrada0;
> when '1' => salida<=entrada1;
> end case;
>
>
> end data_flow;


You could also do:

architectur comp_multiplexor of multiplexor is
begin

salida <= entrada0 when selector='0' ELSE entrada1;


end comp_multiplexor;

Reply With Quote
  #7 (permalink)  
Old 02-12-2006, 04:07 AM
Geo
Guest
 
Posts: n/a
Default Re: Simple problem, understanding the case sentence

I've already done that, you can see the code commented out in my first
post. The problem was that the book exercise required the use of a case
statement and I couldn't make it work (but it's working now). Thank you
anyway.

Regards,
José Jorge Enríquez.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem while using if or case statements [email protected] FPGA 1 03-23-2007 12:40 PM
Problem with pin assign using CASE hgs FPGA 2 01-29-2007 07:33 AM
Problem with pin assign using CASE hgs FPGA 0 01-28-2007 11:19 PM
Simple problem, understanding the case sentence Geo VHDL 0 02-08-2006 06:39 AM
process sentence in synthesis Jluis VHDL 3 05-05-2004 11:07 AM


All times are GMT +1. The time now is 11:55 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved