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

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-09-2004, 10:33 PM
Julian
Guest
 
Posts: n/a
Default Multiplexer...

Sorry if this question is too newbie, but I dont't know how to actually do
this. I need to have a two input multiplexer.

For a one input multiplexer I know I can do:

assign my_signal = (when_this_is_true) ? (assign_this_value) :
(if_not_true_this_is_assigned);

But in pseudo code I would like to write:
if one thing is true assign A to my_signal, or if another thing is true
assign B to my_signal else assign C to my_signal. Could I do this with the
simple assign statement?
Or do I have to write a "regular" if-statement?

P.S. The code needs to be syntheziable!

Best Regards
Julian


Reply With Quote
  #2 (permalink)  
Old 09-10-2004, 03:30 AM
Jason Zheng
Guest
 
Posts: n/a
Default Re: Multiplexer...

Julian wrote:
> Sorry if this question is too newbie, but I dont't know how to actually do
> this. I need to have a two input multiplexer.
>
> For a one input multiplexer I know I can do:
>
> assign my_signal = (when_this_is_true) ? (assign_this_value) :
> (if_not_true_this_is_assigned);
>
> But in pseudo code I would like to write:
> if one thing is true assign A to my_signal, or if another thing is true
> assign B to my_signal else assign C to my_signal. Could I do this with the
> simple assign statement?
> Or do I have to write a "regular" if-statement?
>
> P.S. The code needs to be syntheziable!
>
> Best Regards
> Julian
>
>

you can do this with a cascaded ?: statement:

assign my_signal = predicate1 ? a : predicated2 ? b : c

Though it's perfectly legal to use this, I prefer the following:

reg my_signal

always @*
if (predicated1) my_signal = a
else if (predicate2) my_signal = b
else my_signal = c

The latter is a lot easier to understand than the cascaded ?: statement
Reply With Quote
  #3 (permalink)  
Old 09-10-2004, 03:30 AM
Jason Zheng
Guest
 
Posts: n/a
Default Re: Multiplexer...

Julian wrote:
> Sorry if this question is too newbie, but I dont't know how to actually do
> this. I need to have a two input multiplexer.
>
> For a one input multiplexer I know I can do:
>
> assign my_signal = (when_this_is_true) ? (assign_this_value) :
> (if_not_true_this_is_assigned);
>
> But in pseudo code I would like to write:
> if one thing is true assign A to my_signal, or if another thing is true
> assign B to my_signal else assign C to my_signal. Could I do this with the
> simple assign statement?
> Or do I have to write a "regular" if-statement?
>
> P.S. The code needs to be syntheziable!
>
> Best Regards
> Julian
>
>

you can do this with a cascaded ?: statement:

assign my_signal = predicate1 ? a : predicated2 ? b : c

Though it's perfectly legal to use this, I prefer the following:

reg my_signal

always @*
if (predicated1) my_signal = a
else if (predicate2) my_signal = b
else my_signal = c

The latter is a lot easier to understand than the cascaded ?: statement
Reply With Quote
  #4 (permalink)  
Old 09-10-2004, 10:02 AM
Ajeetha Kumari
Guest
 
Posts: n/a
Default Re: Multiplexer...

Hi,
You can concatenate "?" operators as in:

> But in pseudo code I would like to write:
> if one thing is true assign A to my_signal, or if another thing is true
> assign B to my_signal else assign C to my_signal. Could I do this with the
> simple assign statement?


assign my_signal = (one_thing) ? (A) :
(another_thing) ? B : C;

Get hold of a book on Verilog, that should tell you much more.

HTH,
Ajeetha,
http://www.noveldv.com

"Julian" <jul[email protected]> wrote in message news:<[email protected]>...
> Sorry if this question is too newbie, but I dont't know how to actually do
> this. I need to have a two input multiplexer.
>
> For a one input multiplexer I know I can do:
>
> assign my_signal = (when_this_is_true) ? (assign_this_value) :
> (if_not_true_this_is_assigned);
>
>> Or do I have to write a "regular" if-statement?

>
> P.S. The code needs to be syntheziable!
>
> Best Regards
> Julian

Reply With Quote
  #5 (permalink)  
Old 09-10-2004, 11:53 AM
John Penton
Guest
 
Posts: n/a
Default Re: Multiplexer...

Julian wrote:
> Sorry if this question is too newbie, but I dont't know how to
> actually do this. I need to have a two input multiplexer.
>
> For a one input multiplexer I know I can do:
>
> assign my_signal = (when_this_is_true) ? (assign_this_value) :
> (if_not_true_this_is_assigned);
>
> But in pseudo code I would like to write:
> if one thing is true assign A to my_signal, or if another thing is
> true assign B to my_signal else assign C to my_signal. Could I do
> this with the simple assign statement?
> Or do I have to write a "regular" if-statement?


If your various conditions are mutually exclusive (write something to prove
this), the following is probably the most readable:

assign output = ((condA) & inputA) |
((condB) & inputB) |
((condC) & inputC);

Or, if the conditions different values of the same signal (or group of
signals - think carefully about what "control" might be):

always @( <all input and control signals> )
case (control)
valueA : output = inputA;
valueB : output = inputB;
valueC : output = inputC;
default: output = 1'bx;
endcase

Note: "output" must be a reg.

HTH
John

--
John Penton - posting as an individual unless otherwise indicated.


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
multiplexer from slice / paremeter on with Rolf Kemper Verilog 2 08-10-2004 05:52 PM


All times are GMT +1. The time now is 03:18 AM.


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