Altera_Forum
Honored Contributor
17 years agoProblem with VHDL code
Hi I'm really really new to VHDL codes and I'm having this problem with a very simple program of mine. The code is as shown below:
library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity cc is port ( enter : in std_logic; reset : in std_logic; input : in signed (7 downto 0); output : out signed (7 downto 0) ); end cc; architecture cc_arch of cc is signal a : signed (7 downto 0); signal b : signed (7 downto 0); signal total: signed (7 downto 0); signal c : std_logic; signal d : std_logic; begin process (enter,reset) begin if (reset = '0' and enter = '1') then total <= "00000000"; end if; if (enter = '1' and reset = '1') then a <= input; b <= total; elsif (enter = '0' and reset = '1') then total <= a + b; end if; end process; output <= total; end cc_arch; The program is supposed to act as a simple calculator which calculates 2's complement. The buttons RESET and ENTER are active low buttons. "Input" is a 8 bit DIP switch. I intended the program to function as shown below: When RESET button is pressed, total is set to 0. Then "Input" is put into "a" and total is put into "b" when no button is pressed. When ENTER button is pressed the total is set to (a + b). When it is released, "Input" is put into "a" again and total is put into "b". When the ENTER button is pressed again and again, total is supposed to be incremented with whatever is at "Input". However when I simulated it, by setting Input to "00000002" as a simple example i get: http://img300.imageshack.us/img300/6630/waveformfd6.jpg (http://imageshack.us)http://img300.imageshack.us/img300/waveformfd6.jpg/1/w640.png (http://g.imageshack.us/img300/waveformfd6.jpg/1/) Please help I'm not exactly sure what's happening. http://img442.imageshack.us/img442/59536805yw2.jpg/1/w320.png (http://g.imageshack.us/img442/59536805yw2.jpg/1/)