Wednesday 3 May 2017

code design - Difference between If-else and Case statement in VHDL


I want to understand how different constructs in VHDL code are synthesized in RTL.



  • Can anyone tell me the difference between If-Else construct and Case statement constructs of a process in VHDL in terms of how the code is inferenced into RTL circuit by the synthesis tool ?

  • Do consider the case of multiple nested if-else and mixing case-statements with if-else construct inside a process.

  • Also when to use which construct ?


PS: I have seen a related question "Multiple if statements in process in vhdl" but that doesn't answer my question in anyway.




Answer




Can anyone tell me the difference between If-Else construct and Case statement constructs of a process in VHDL in terms of how the code is inferenced into RTL circuit by the synthesis tool ?



The if-elsif-else construct infers a priority routing network:


schematic


simulate this circuit – Schematic created using CircuitLab


This corresponds to


if bool_expr_1 then
sig <= val_expr_1;

elsif bool_expr_2 then
sig <= val_expr_2;
elsif bool_expr_3 then
sig <= val_expr_3;
else
sig <= val_expr_4;
end if;

The case construct, on the other hand, infers a big ol' mux:


enter image description here



This corresponds to


case case_expr is
when c0 =>
sig <= val_expr_0;
when c1 =>
sig <= val_expr_1;
when c2 =>
sig <= val_expr_2;
...
when others =>

sig <= val_expr_N;
end case;

Obviously these are very simplified designs with only one value expression, resulting in one output.



Do consider the case of multiple nested if-else and mixing case-statements with if-else construct inside a process.



Per the above, you can see how they would nest/mix.



Also when to use which construct ?




Since if-else infers priority, it should be used when more than one input condition could occur. Using case, one the other hand, is appropriate when the inputs are mutually exclusive.


No comments:

Post a Comment

arduino - Can I use TI&#39;s cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...