Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'if' vs 'when' for making multiplexer

Tags:

hardware

vhdl

i have been told to use 'when' statement to make multiplexer but not use 'if' statement as it will cause timing errors... i don't understand this ... so what is the difference between 'if' and 'when' ? and do they map to the same thing in hardware ?

like image 515
Ahmed Kotb Avatar asked Mar 09 '10 21:03

Ahmed Kotb


2 Answers

OK, lets discuss some points at first on the difference between if and when statements:

  • Both are called Dataflow Design Elements.

when statement

  • concurrent statement
  • not used in process, used only in architecture as process is sequential execution

if statement

  • sequential statement
  • used in process as it is sequential statement, and not used outside the process

And you know multiplexer is a component don't need process block, as its behavior doesn't change with changing its input, so it will be outside process, so you have to write it using when statement as it is concurrent statement.. And if you wrote it with if statement, timing errors may occur. Also all the references and also Xilinx help (if you are using Xilinx) are writing the Multiplexer block using when statement not if statement

Reference: Digital Design Priciples & Practices, John F. Wakerly, 3rd Edition

like image 60
Mohammad Kotb Avatar answered Sep 30 '22 10:09

Mohammad Kotb


See these:

  • VHDL concurrent statements, which includes when.
  • VHDL sequential statements, which includes if.

Basically, if is sequential, and when is concurrent. They do not map to the same thing in hardware... This page describes, at the bottom, some of the special considerations needed to synthesize an if statement.

like image 26
Aidan Cully Avatar answered Sep 30 '22 11:09

Aidan Cully