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;
|