Dmitry O. wrote:
> Where is the error? Tell me please
First: pls wrapp your VHDL code in the VHDL tags
1 | [vhdl]
|
2 | VHDL code
|
3 | [/vhdl]
|
Second: do not use comments when they tend to be wrong or completely
needless, such as this
1 | clk: in std_logic; -- clock input
|
2 | reset: in std_logic; -- reset input
|
3 | ce: in std_logic; -- enable input
|
4 | counter: out std_logic_vector(7 downto 0) -- output 4-bit counter
|
Of course "clk: in std_logic" is the "clock input" andsoforth. And then
(7 downto 0) is 8 bits, not 4 bits!
Third: forget what you know about loops from C or any other
programming language. A loop in VHDL ist somthing COMPLETELY
different.
Fourth: do not use the outdated std_logic_arith packages. Use the
numeric_std instead!
See the conversion chart there
http://www.lothar-miller.de/s9y/categories/16-Numeric_Std
Finally try this and think about it:
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.NUMERIC_STD.ALL;
|
4 |
|
5 | entity UP_COUNTER is
|
6 | Port ( clk: in std_logic;
|
7 | reset: in std_logic;
|
8 | ce: in std_logic;
|
9 | counter: out std_logic_vector(7 downto 0)
|
10 | );
|
11 | end UP_COUNTER;
|
12 |
|
13 | architecture Behavioral of UP_COUNTER is
|
14 | signal counter_up: integer range 0 to 19 := 0;
|
15 | begin
|
16 | -- up counter
|
17 | process(clk)
|
18 | begin
|
19 | if rising_edge(clk) then
|
20 | if reset = '1' then
|
21 | counter_up <= 0;
|
22 | elsif ce = '1' then
|
23 | if counter_up<19 then
|
24 | counter_up <= counter_up + i;
|
25 | else
|
26 | counter_up <= 0;
|
27 | end if;
|
28 | end if;
|
29 | end if;
|
30 | end process;
|
31 | counter <= std_logic_vector(to_unsigned(counter_up,8));
|
32 | end Behavioral;
|