Register - count up and remember value

Joined
Apr 30, 2009
Messages
6
Reaction score
0
Hey

First I want to say hello to everybody since it is my first post in here :)


I am trying to create a counter which counts up every time you push a specific button as a part of a bigger project.

I have created this register to remember the value:

Code:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;


entity TCC is
		port ( kr, reset, clock : in STD_LOGIC;
				 tempkr : out STD_LOGIC_VECTOR(3 downto 0)
			  );
end TCC;

architecture Behavioral of TCC is

	SIGNAL oldvalue : STD_LOGIC_VECTOR(3 downto 0);

begin

	run : process(clock)
	begin
		if clock'event and clock = '1' then
			if reset = '1' then
				oldvalue <= "0000";
			elsif kr = '1' then
				oldvalue <= oldvalue + "0001";
			end if;
		end if;
	end process;
	
	tempkr <= oldvalue;
		
end Behavioral;


kr is connected to the count up button, reset to a reset button, and temp is the number of times the button is pressed.

I guess that it should work, but when I use modelSim it seems that the other components which get the out from this will "fail" because it has a non intstatiated input. it means that i get output from these components that is for example XXXX.


So how do I instantiate my value the first time it runs?


I apriciate your help. And please ask if you don't understand my question.

Regards
 
Joined
Apr 30, 2009
Messages
6
Reaction score
0
Lets say I do like this:

Code:
	run : process(clock)
	
	VARIABLE oldvalue : STD_LOGIC_VECTOR(3 downto 0) := "0000";
	
	begin
		if clock'event and clock = '1' then
			if reset = '1' then
				oldvalue := "0000";
			elsif kr = '1' then
				oldvalue := oldvalue + "0001";
			end if;
		end if;
		
		tempkr <= oldvalue;
		
	end process;

does the variable then become "0000" everytime or just the first time?.
if only the first time then its might the solution to my problem?
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top