Question about conditional assignment

R

Rebecca

Hello, all

I want to implement the following logic
if(C_ControlBits=0) then
NULL;
else
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end if;
Because C_ControlBits-1 will become -1 when C_ControlBits=0.
C_ControlBits is declared as constant in my design. But what's the
synthesizable VHDL code for this? I tried to put it into process but
failed.

Thanks for any hints,
Rebecca
 
J

Jim Lewis

Rebecca,
I would have to see more code to make a reasonable guess, so
instead I will make a blind guess. Often in a process
I find it handy to first initialize the entire array to
0 and then later over-write only the bits I need to set.

In this situation I would replace the conditional code
with:
Addr <= (others=>'0');
Addr(C_ControlBits+3 downto C_ControlBits) <= "1111" ;


Cheers,
Jim
 
B

Brian Drummond

Hello, all

I want to implement the following logic
if(C_ControlBits=0) then
NULL;
else
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end if;
Because C_ControlBits-1 will become -1 when C_ControlBits=0.
C_ControlBits is declared as constant in my design. But what's the
synthesizable VHDL code for this? I tried to put it into process but
failed.

Thanks for any hints,

Another wild guess...
look at "if ... generate" and "for ... generate"

- Brian
 
R

Rebecca

Jim:

I want to implement this
Addr(15 downto C_controlBits) <= SignalB;
if(C_ControlBits=0) then
NULL;
else
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end if;



And your suggestion is what I can use.
But is that a good idear to overwite it? I know it is handy, but would
it cause problem for syncrounous design because it induces extra delay/
unstable phases and then probably data hazard?

Thanks,
Hongyan
 
R

Rebecca

Sorry I didn't describe it clear, Brian. What I want to implement is

Addr(15 downto C_controlBits) <= SignalB;
if(C_ControlBits=0) then
NULL;
else
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end if;

I can't use the generated stuff here.

Thank you,
Rebecca
 
R

Rebecca

Jim:

I want to implement this
Addr(15 downto C_controlBits) <= SignalB;
if(C_ControlBits=0) then
NULL;
else
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end if;

Sorry that I didn't describe it clear and you had to guess. You
suggestion is what I needed.
But is that a good idear to overwite it? I know it is handy, but would
it cause problem for syncrounous design because it induces extra
delay/
unstable phases and then probably data hazard?

Thank you very much,
Rebecca
 
A

Andy

If this has to be sequential code (inside a process), then Jim's
solution works fine:

Addr <= (others => '0');
Addr(15 downto C_controlBits) <= SignalB;

If this is supposed to be concurrent statements, then generate will
work, since C_control_bits must be static because signalB is of static
width.

Addr(15 downto C_controlBits) <= SignalB;
if C_controlBits /= 0 generate
Addr(C_ControlBits-1 downto 0) <= (others=>'0');
end generate;

Take your pick.

andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top