How dofor using generate or loop for this process ?

O

Olivier Dir

Hi all,
for this code I would like write this code with loop or generate.
I don't know if it's possible.



pSelFifo : process(Clk, SRst)
begin
if SRst = '1' then
SelFifo <= (others=>'0');
elsif Clk'event and Clk='1' then
if DataAvlble(1) = '1' then
SelFifo <= "000001"
elsif DataAvlble(2) = '1' then
SelFifo <= "000010"
elsif DataAvlble(3) = '1' then
SelFifo <= "000100"
elsif DataAvlble(4) = '1' then
SelFifo <= "001000"
elsif DataAvlble(5) = '1' then
SelFifo <= "010000"
elsif DataAvlble(6) = '1' then
SelFifo <= "100000"
else
SelFifo <= (others=>'0');
end if;

end if;
end process;

thank for your help.

Olive
 
O

Olivier Dir

Le mardi 1 avril 2014 13:25:02 UTC+2, Brian Drummond a écrit :
pSelFifo : process(Clk, SRst)

begin

if SRst = '1' then

SelFifo <= (others=>'0');

elsif rising_edge(Clk) then

SelFifo <= (others=>'0');

for i in DataAvlble'low to DataAvlble'high loop

if DataAvlble(i) = '1' then

SelFifo(i) <= '1';

exit; -- prevent multiple bit set, as in original

end if;

end loop;

end if;

end process;

Thank you.
 
A

Andy

It is not clear from the example what is the index range on SelFifo, and ifthat range matches the range of DataAvlble. We do know that Selfifo has 6 bits. DataAvlble has at least 6 bits, indexed between 6 and 1 inclusive, but we do not know DataAvlble's index range direction.

The loop would only work if SelFifo'range is 6 downto 1.

The following would work if the index diretion of both DataAvlble and SelFifo is "downto", given the correct value for DaOffset:

pSelFifo : process(Clk, SRst)
constant DaOffset : integer := 1;
begin
if SRst = '1' then
SelFifo <= (others=>'0');
elsif rising_edge(Clk) then
SelFifo <= (others=>'0');
for i in SelFifo'reverse_range loop -- right to left in SelFifo
if DataAvlble(i + DaOffset) = '1' then
SelFifo(i) <= '1';
exit; -- prevent multiple bit set, as in original
end if;
end loop;
end if;
end process;

The sum (i + DaOffset) becomes a constant when synthesis unrolls the loop.

Andy
 
D

Daniel Kho

It is not clear from the example what is the index range on SelFifo, and if that range matches the range of DataAvlble. We do know that Selfifo has 6 bits. DataAvlble has at least 6 bits, indexed between 6 and 1 inclusive, but we do not know DataAvlble's index range direction.



The loop would only work if SelFifo'range is 6 downto 1.



The following would work if the index diretion of both DataAvlble and SelFifo is "downto", given the correct value for DaOffset:



pSelFifo : process(Clk, SRst)

constant DaOffset : integer := 1;

begin

if SRst = '1' then

SelFifo <= (others=>'0');

elsif rising_edge(Clk) then

SelFifo <= (others=>'0');

for i in SelFifo'reverse_range loop -- right to left in SelFifo

if DataAvlble(i + DaOffset) = '1' then

SelFifo(i) <= '1';

exit; -- prevent multiple bit set, as in original

end if;

end loop;

end if;

end process;



The sum (i + DaOffset) becomes a constant when synthesis unrolls the loop..



Andy


Something like this might just work (not tested):

signal n: positive;
....
pSelFifo : process(Clk, SRst) begin
if SRst = '1' then
SelFifo <= (others=>'0');
elsif Clk'event and Clk='1' then
if n>6 then SelFifo <= (others=>'0');
else
if DataAvlble(n) then SelFifo <= to_unsigned(2**(n-1),6); end if;
end if;
end if;
end process;

Not sure though if this will synthesise. Probably not, since the expression(2**(n-1)) is not a constant. However, this can be replaced by a shift-left operation for synthesis. We could try that as well.

-daniel
 

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

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top