Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] While loop usage in vhdl is giving logical error

Status
Not open for further replies.

emmagood

Member level 4
Joined
Feb 13, 2010
Messages
72
Helped
3
Reputation
6
Reaction score
1
Trophy points
1,288
Activity points
1,825
Hello,

I was trying to make a 4 bit gray to binary code converter using while loop. It was giving me logical error in the waveform. During the first 2-3 clock pulses, the output bits were uninitialized. What can be the reason for it pls.

The code is:

******************


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
 
entity gray2b is
    Port ( g : in  STD_LOGIC_VECTOR (3 downto 0);
           b : out  STD_LOGIC_VECTOR (3 downto 0));
end gtob1;
architecture Behavioral of gray2b is
signal  temp : std_logic_vector(3 downto 0);
begin
process(g)
variable i : integer ;
begin
i:=3;
temp(3) <= g(3);
while (i > 0) loop
temp(i-1) <= temp(i) xor g(i-1);
i:=i-1;
end loop;
--b<= temp;
end process;
b <= temp;
end Behavioral;


******************


gtob_waveform.JPG

Thanks,
Emma Good.
 
Last edited by a moderator:

You declared temp as a signal which will be updated after one delta cycle unlike variable .so declare temp as variable inside process and assign to output inside process.like this
Code:
architecture Behavioral of gray2b is



begin

process(g)

variable i : integer ;
variable temp : std_logic_vector(3 downto 0);
begin

i:=3;
temp(3) := g(3);

while (i > 0) loop

temp(i-1) := temp(i) xor g(i-1);
i:=i-1;

end loop;

b<= temp;

end process;


end Behavioral;
 
Your description of the problem is a little muddled. You talk about there being 3 clock pulses with unitialised signals, but I see no clocks in the design, and your code is not synchronous.

Also, although the code you have would be ok for synthesis, while loops are not recommended - you can only use them when the loop iterations are constant (as is the case here). You would be much better off sticking to for loops.
 

sorry for the messed up description... i meant 3 iterations only instead of 3 clk cycles....!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top