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.

8-bit binary counter cant count down

Status
Not open for further replies.

bhan1992

Member level 1
Joined
Feb 25, 2012
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,511
i have an 8-bit up/down counter code as below, the problem is it wont count down. everytime i have a count down input, it just remain as the previous state.

Code:

Code:
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity counter_code is
	port (
	output  :out std_logic_vector (7 downto 0);    
	up_down :in  std_logic;              
	clk     :in  std_logic;             
	reset   :in  std_logic         
			);
end counter_code;

architecture start of counter_code is
	signal count :std_logic_vector (7 downto 0);
	
	begin
		process (clk, reset, up_down)
		begin
		
			if (reset = '1' and rising_edge(clk)) then
			
				count <= (others=>'0');
				
			elsif (rising_edge(clk)) then -- rising edge
			
				if (up_down = '1') then
						count <= count + 1;
				elsif (up_down = '0' and count /= "00000000") then

						count <= count - 1;
				
				end if;
				

			end if;
			
		end process;
	output <= count;
end start;

waveform screenshot:
8 bit counter.png
up_down = 0 'count down', = 1 'count up'
 

i did not force any value into it thats y it is showing a red line
 

i did not force any value into it thats y it is showing a red line

What happens if you do force it? I got your code to simulate fine.

You should also make some modifications to you code it's kind of confusing

something more like:


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
process (clk, reset)
        begin
        
            if (reset = '1') then
            
                count <= (others=>'0');
                
            elsif (rising_edge(clk)) then -- rising edge
            
                if (up_down = '1') then
                
                        count <= count + 1;
                        
                elsif (up_down = '0' and count /= "00000000") then
 
                        count <= count - 1;
                
                end if;
                
 
            end if;
            
        end process;

 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top