EmbDev.net

Forum: FPGA, VHDL & Verilog Counter up/down


von John (Guest)


Rate this post
useful
not useful
I will use seven segment display to show the numbers, but I also must be 
able to set a specific time by increasing/decreasing and then once it is 
set, with another button the clock will start to go down.

signal lock is for preventing the count increases at the speed of the

manual is a button,

I guess the count up is okay, but the problem is when I want it to go 
down. In the simulation when I put the sentido HIGH then I do not get 
anything and does not work.
1
library ieee;
2
use ieee.std_logic_1164.all;
3
use IEEE.STD_LOGIC_UNSIGNED.ALL;
4
entity counter is
5
port(   clck, reset : in std_logic;
6
        limit   : in integer range 0 to 10;
7
        manual: inout std_logic;
8
        sentido: in std_logic;
9
        bitcount : out std_logic_vector(3 downto 0);
10
        clckout : out std_logic);
11
end counter;
12
13
architecture behavior of counter is
14
signal Cs : std_logic_vector(3 downto 0):="0000";
15
signal lock: std_logic;
16
begin   
17
Count : process(clck,reset,manual,lock,sentido)
18
    begin
19
20
            if(rising_edge(clck))then
21
             if (manual='0' and lock ='0') then
22
                      Cs<=Cs+1;
23
                       lock<='1';
24
             elsif(manual='1' and lock='1' ) then        
25
                     lock<='1';
26
             else
27
                     lock<='0';
28
29
                    end if; 
30
                    end if;
31
32
    if sentido = '1' then
33
                 Cs<=Cs-1;
34
                    end if;
35
36
            if (reset = '1') then
37
                    Cs <="0000";
38
                end if;
39
                if (Cs = "1010") then
40
                      Cs <= "0000";
41
                end if;
42
end process Count;
43
bitcount <=Cs;
44
45
end behavior;

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
John wrote:
> In the simulation when I put the sentido HIGH then I do not get anything
Absolutely NOTHING?
> and does not work.
What does your simulation show instead of the desired reaction?


What you built there is a combinatorial loop, because the Cs<=Cs-1 
path has no clock!!11one!eleven!11
Where did you find this very strange way of a synchronous process? How 
do it all the others around the world?

Try this and think about it:
1
-- only the clock and (if absolutely necessary) the reset in the sensitivity list of a synchronous process!
2
Count : process(clck,reset) 
3
    begin
4
      -- the reset path (is it really necessary?)
5
      if (reset = '1') then
6
              Cs <="0000";
7
      -- the one and only clock for the synchronous path
8
      elsif rising_edge(clck) then
9
             if (manual='0' and lock ='0') then
10
                      Cs<=Cs+1;
11
                       lock<='1';
12
             elsif(manual='1' and lock='1' ) then        
13
                     lock<='1';
14
             else
15
                     lock<='0';
16
             end if; 
17
18
             if sentido = '1' then      
19
                  Cs<=Cs-1;
20
             end if;
21
22
             if Cs = "1010" then
23
                      Cs <= "0000";
24
             end if;
25
      end if;
26
end process Count;

BTW: pls use the [vhdl] tags to wrap your VHDL code.

: Edited by Moderator
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.