Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20705 Discussions

Conditional assignments with generics

Altera_Forum
Honored Contributor II
1,123 Views

Is it possible in VHDL to assign a signal conditionally based on the value of a generics without creating additional unwanted logic?  

 

 

I think the following code created logic to evaluate the condition. 

 

signal_a <= signal_b when (GENERIC_A > GENERIC_B)  

else signal_c;
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
331 Views

What you wrote should work OK. You shouldn't get a 2:1 mux for a conditional assignment with a condition that's a compile-time constant. You could use a conditional generate, but VHDL doesn't have an if/else version of a generate, e.g. 

 

GEN_TRUE: if (GENERIC_A > GENERIC_B) generate begin signal_a <= signal_b; end generate GEN_TRUE; GEN_FALSE: if not(GENERIC_A > GENERIC_B) generate begin signal_a <= signal_c; end generate GEN_FALSE;  

 

So I'd probably stick with what you've got.
0 Kudos
Altera_Forum
Honored Contributor II
331 Views

Thanks for your reply. I tried the generate and the original way I had it and they both produce the same result. When the conditionals are in there, my design doesn't pass the timing requirement on those signals, but if I take the conditionals out it works just fine. Maybe it is a Quartus bug.

0 Kudos
Altera_Forum
Honored Contributor II
331 Views

If one version fails timing, did you analyze the difference between the critical paths in the passing and failing versions. It could be that you're on the cusp of meeting timing and small netlist changes or random placement variations are enough to push you over or under your timing constraint(s).

0 Kudos
Altera_Forum
Honored Contributor II
331 Views

Generally, Quartus isn't generating any unwanted logic. It's removing unneeded signals and registers unless explicitely told to keep it by synthesis attributes. The only disadvantage of using generics in conditional expresions is that you get some warnings regarding constant expressions. But it's the only plausible method to achieve conditional compilation inside a process, so the warnings should be accepted. You can expect a lot of similar meaningless warnings with parameterizable designs. 

 

Cause place and route is performed after minimizing logic expressions, I can't imagine why the synthesis should end up with different timing.
0 Kudos
Reply