Register - count up and remember value

Discussion in 'VHDL' started by VHDLstudent, Apr 30, 2009.

  1. VHDLstudent

    VHDLstudent

    Joined:
    Apr 30, 2009
    Messages:
    6
    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
    VHDLstudent, Apr 30, 2009
    #1
    1. Advertising

  2. VHDLstudent

    VHDLstudent

    Joined:
    Apr 30, 2009
    Messages:
    6
    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?
    VHDLstudent, Apr 30, 2009
    #2
    1. Advertising

  3. VHDLstudent

    VHDLstudent

    Joined:
    Apr 30, 2009
    Messages:
    6
    I have solved the problem by my self! :D thanks
    VHDLstudent, Apr 30, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Frank Miverk
    Replies:
    0
    Views:
    655
    Frank Miverk
    Apr 18, 2007
  2. Govinda
    Replies:
    0
    Views:
    476
    Govinda
    Aug 15, 2007
  3. zephyrtronium

    Register bit count

    zephyrtronium, May 31, 2010, in forum: C Programming
    Replies:
    3
    Views:
    868
    bart.c
    May 31, 2010
  4. efelnavarro09
    Replies:
    2
    Views:
    917
    efelnavarro09
    Jan 26, 2011
  5. rharmonster@gmail.com

    back button doesn't remember new value

    rharmonster@gmail.com, Jul 31, 2006, in forum: ASP General
    Replies:
    1
    Views:
    179
    Mike Brind
    Aug 1, 2006
Loading...

Share This Page