+ Post New Thread
Results 1 to 4 of 4
-
4th July 2014, 02:47 #1
- Join Date
- Feb 2010
- Posts
- 72
- Helped
- 3 / 3
- Points
- 1,738
- Level
- 9
While loop usage in vhdl is giving logical error
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;
Thanks,
Emma Good.Last edited by andre_teprom; 4th July 2014 at 12:20. Reason: added VHDL syntax formatting
-
Advertisement
-
4th July 2014, 05:51 #2
- Join Date
- Feb 2014
- Location
- India
- Posts
- 71
- Helped
- 13 / 13
- Points
- 1,298
- Level
- 8
Re: While loop usage in vhdl is giving logical error
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;
1 members found this post helpful.
-
Advertisement
-
4th July 2014, 08:22 #3
- Join Date
- Jun 2010
- Posts
- 6,893
- Helped
- 2026 / 2026
- Points
- 38,044
- Level
- 47
Re: While loop usage in vhdl is giving logical error
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.
-
Advertisement
-
4th July 2014, 14:53 #4
- Join Date
- Feb 2010
- Posts
- 72
- Helped
- 3 / 3
- Points
- 1,738
- Level
- 9
Re: While loop usage in vhdl is giving logical error
sorry for the messed up description... i meant 3 iterations only instead of 3 clk cycles....!
+ Post New Thread
Please login