Hallo zusammen,
hab da ein kleines Problem mit einem Zähler. Der sollte hochzählen
sobald der Eingang ErrorIn bei rising_edge(clock) und CountEna = 1 high
ist. Das funktioniert bei einzelnen bits aber bei drei hintereinander
folgenden eins zählt er nur einmal hoch. Bin bis jetzt bei der
Fehlersuche nicht fündig geworden. Könnte mir jemand helfen ?
Danke im Voraus.
Hier die quellcode:
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity ErrorCounter is
generic( n : natural := 4 );
port( clock : in std_logic;
reset : in std_logic;
CountEna : in std_logic; -- is 1 when synchronity is given
ErrorIn : in std_logic; -- Error detected
CarryOut : out std_logic; -- Triggers incrementation of Cnt
No2
ErrorCount : out std_logic_vector(n-1 downto 0) );
end entity ;
architecture ErrorCounter_arch of ErrorCounter is
type state_type is (s0,s1,s2,s3,s4,s5,s6,s7,s8,s9);
signal curr_state,next_state : state_type;
signal s_counter : std_logic_vector(n-1 downto 0);
constant tdelay : time := 50 ns;
constant tperiod : time := 15000 ns;
begin
Sync_proc : process(clock,reset,CountEna)
begin
if reset = '1' then
curr_state <= s0;
else
if rising_edge(clock) and CountEna = '1' then
curr_state <= next_state;
end if;
end if;
end process;
state_proc: process(next_state,ErrorIn)
begin
CarryOut <='0';
case curr_state is
when s0 =>
ErrorCount <= "0000";
if (ErrorIn = '1') then
next_state <= s1;
else
next_state <= s0;
end if;
when s1 =>
ErrorCount <= "0001";
if (ErrorIn = '1') then
next_state <= s2;
else
next_state <= s1;
end if;
when s2 =>
ErrorCount <= "0010";
if (ErrorIn = '1') then
next_state <= s3;
else
next_state <= s2;
end if;
when s3 =>
ErrorCount <= "0011";
if (ErrorIn = '1') then
next_state <= s4;
else
next_state <= s3;
end if;
when s4 =>
ErrorCount <= "0100";
if (ErrorIn = '1') then
next_state <= s5;
else
next_state <= s4;
end if;
when s5 =>
ErrorCount <= "0101";
if (ErrorIn = '1') then
next_state <= s6;
else
next_state <= s5;
end if;
when s6 =>
ErrorCount <= "0110";
if (ErrorIn = '1') then
next_state <= s7;
else
next_state <= s6;
end if;
when s7 =>
ErrorCount <= "0111";
if (ErrorIn = '1') then
next_state <= s8;
else
next_state <= s7;
end if;
when s8 =>
ErrorCount <= "1000";
if (ErrorIn = '1') then
next_state <= s9;
else
next_state <= s8;
end if;
when s9 =>
ErrorCount <= "1001";
if (ErrorIn = '1') then
next_state <= s0;
CarryOut <= '1';
else
next_state <= s9;
end if;
end case;
end process;
end architecture ;
curr_state noch mit in die Sensitvity Liste aufnehmen.
1 | state_proc: process(next_state,ErrorIn,curr_state) |
In die erste Liste gehört vor allem nur clock und reset. Außerdem das count enable dann nicht per "and" verknüpfen sondern nach rising_edge eine neue if-Anweisung einführen. In die zweite Liste gehört alles wovon du liest. Also curr_state aber dafür fliegt next_state raus, denn das schreibst du nur.
Mir kommt das Ganze irgendwie zu kompliziert vor. Ist das nicht so einfacher?
1 | process (clock) |
2 | if (rising_edge(clock)) then |
3 | if (countEna = '1' and ErrorIn = '1') then |
4 | ErrorCount <= ErrorCount + 1; |
5 | CarryOut <= '0'; |
6 | if (ErrorCount = "1001") then |
7 | CarryOut <= '1'; |
8 | ErrorCount <= "0000"; |
9 | end if; |
10 | end if; |
11 | end if; |
12 | end process; |
Ist jetzt nur so schnell geschrieben, aber so ähnlich sollte es gehen.
Danke für die hilfreichen antworten, in der verzweifelte Suche nach dem Problem hatte ich weiteren Fehlern eingebaut. jetzt geht alles. Besten Dank.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.
