VHDL & Zähler

OP #843128
Lesenswert?

Hallo ich hab zwei zähler in VHDL geschrieben:
1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5

6
---- Uncomment the following library declaration if instantiating
7
---- any Xilinx primitives in this code.
8
--library UNISIM;
9
--use UNISIM.VComponents.all;
10

11
entity ms_zaehler is
12

13
  port(  clk, reset   : in   std_logic;
14
      msek       : out std_logic_vector(9 downto 0)
15
      );
16

17
end ms_zaehler;
18

19
architecture Behavioral of ms_zaehler is
20

21
signal tmp_ms: std_logic_vector(9 downto 0);
22

23
begin
24
  process (clk, reset)
25
    begin
26
      
27
      if (reset='0') then
28
      tmp_ms <= "0000000000";
29
      
30
        elsif (clk'event and clk='1') then
31
        tmp_ms <= tmp_ms + 1;
32
      
33
          if (tmp_ms = "1111100111") then
34
          tmp_ms <= "0000000000";
35
          
36
          end if;
37
      
38
      end if;
39
  end process;
40
  
41
  msek <= tmp_ms;
42

43
end Behavioral;






1
library IEEE;
2
use IEEE.STD_LOGIC_1164.ALL;
3
use IEEE.STD_LOGIC_ARITH.ALL;
4
use IEEE.STD_LOGIC_UNSIGNED.ALL;
5

6
---- Uncomment the following library declaration if instantiating
7
---- any Xilinx primitives in this code.
8
--library UNISIM;
9
--use UNISIM.VComponents.all;
10

11
entity sek_einer_zaehler is
12

13
port(    reset       :   in   std_logic;
14
      ms_in       :   in   std_logic_vector(9 downto 0);
15
      sek_einer     :   out   std_logic_vector(3 downto 0)
16
      );
17

18

19
end sek_einer_zaehler;
20

21
architecture Behavioral of sek_einer_zaehler is
22

23
signal tmp_sek_einer  :  std_logic_vector(3 downto 0);
24

25
begin
26

27
  process (ms_in, reset)
28
    begin
29
      
30
      if (reset='0') then
31
      tmp_sek_einer <= "0000";
32
      
33
        elsif (ms_in = "1111100111") then
34
        tmp_sek_einer <= tmp_sek_einer + 1;
35
        
36
      
37
      
38
          if(tmp_sek_einer = "1001") then
39
          tmp_sek_einer <= "0000";
40
        
41
          end if;
42
          
43
      end if;
44
  end process;
45
  
46
  sek_einer <= tmp_sek_einer;
47

48
end Behavioral;

Mit dem ersten Zähler zähle ich bei einem 1KHz Takt, millisekunden.
Mit dem zweiten will ich dann Sekunden zählen.

Im Moment beginnt der Zweite zähler schon beim wechsel von 989 auf 999 
die Sekunden zu Zählen. Er ist also 1 ms zu früh dran. Ich weis warum 
das so ist aber leider nicht wie ich es ändern könnte.
Kann mir da bitte jemand auf die Sprünge helfen...

gruß  Andreas

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren