E
electrin
Guest
Hello boys,
I have got a small problem with my finite state machine which I hav
written in VHDL recently. I tried to create "intelligent" counte
triggered by clock with frequency 2 Hz.
This counter is built in one state of FSM and is started by pushing
button on DE2 board.
Firstly, whole system is in IDLE state and if I push this button, state i
changed to COUNTING and counter begin to be incremented and his curren
value is shown on LED display. After it reach value of modulo, the stat
COUNTING is left back to IDLE and the counter is set up to zero.
My problem is that the counter doesn´t work correctly - the countin
value was too great. So I tried to solve it with this construction: i
(clk_tick´event and clk_tick = 1) then.... , there are some errors b
synthesis:
Error (10822): HDL error at Citac_FSM.vhd(57): couldn't implemen
registers for assignments on this clock edge
Error (10821): HDL error at Citac_FSM.vhd(62): can't infer register fo
"AUTOMAT:flg" because its behavior does not match any supported registe
model
Please, does somebody have an idea to solve it? And what is it correct wa
to write clock triggered FSM with two (or more) clock sources?
-----------------------------------------------------------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
-- Entita
ENTITY Counter_FSM IS
GENERIC (
REGSIZE : integer := 8; -- range of counter
MODULO : natural := 50 -- modulo value
);
PORT (
CLK : IN STD_LOGIC; -- puls 50 MHz
CLK_tick : IN STD_LOGIC; -- puls 2 Hz
RESET : IN STD_LOGIC; -- reset
READY : OUT STD_LOGIC; -- counter is ready to start
START_C : IN STD_LOGIC; -- start of counting
DOUT : OUT STD_LOGIC_VECTOR(REGSIZE - 1 downto 0) -- output
);
END Counter_FSM;
--------------------------------------------------------------------------
--
-- Architecture of FSM
--
ARCHITECTURE Behavior OF Counter_FSM is
type counterState is (IDLE, COUNTING); -- states of FSM
signal currCounterState : counterState; -- current state
signal nextCounterState : counterState; -- next state
signal cnt : std_logic_vector(REGSIZE - 1 downto 0); -- data registe
for counter
begin
--------------------------------------------------------------------------
--
-- State update
UPDATE: process(RESET, CLK)
begin
if (RESET = '0') then
currCounterState <= IDLE;
elsif (CLK'event and CLK = '1') then
currCounterState <= nextCounterState;
end if;
end process;
--------------------------------------------------------------------------
--
-- Combi part
COMBI: process (clk_tick, start_c, currCounterState)
variable flg : std_logic := '0';
begin
if (clk_tick'event and clk_tick = '1') then
flg := '1';
end if;
case currCounterState is
when IDLE =>
cnt <= (others => '0'); -- counter value = zero
READY <= '1'; -- we can start
if (start_c = '1') then -- if button is pushed
nextCounterState <= COUNTING; -- then go to COUNTING state
end if;
when COUNTING =>
READY <= '0';
if (flg = '1') then -- Was there impuls of 2 Hz?
cnt <= cnt + 1; -- yes -> incrementing
flg := '0';
if (cnt = MODULO) then -- if value of cnt = MODULO
cnt <= (others => '0'); -- then cnt = zero
nextCounterState <= IDLE; -- and next state is IDLE
end if;
end if;
when others =>
nextCounterState <= IDLE;
end case;
-- OUTPUT
douT <= cnt;
end process;
--------------------------------------------------------------------------
end Behavior;
-----------------------------------------------------------------------------------
Thank you very much.
Mirek
P.S.: I am sorry my English is not so good
--------------------------------------
Posted through http://www.FPGARelated.com
I have got a small problem with my finite state machine which I hav
written in VHDL recently. I tried to create "intelligent" counte
triggered by clock with frequency 2 Hz.
This counter is built in one state of FSM and is started by pushing
button on DE2 board.
Firstly, whole system is in IDLE state and if I push this button, state i
changed to COUNTING and counter begin to be incremented and his curren
value is shown on LED display. After it reach value of modulo, the stat
COUNTING is left back to IDLE and the counter is set up to zero.
My problem is that the counter doesn´t work correctly - the countin
value was too great. So I tried to solve it with this construction: i
(clk_tick´event and clk_tick = 1) then.... , there are some errors b
synthesis:
Error (10822): HDL error at Citac_FSM.vhd(57): couldn't implemen
registers for assignments on this clock edge
Error (10821): HDL error at Citac_FSM.vhd(62): can't infer register fo
"AUTOMAT:flg" because its behavior does not match any supported registe
model
Please, does somebody have an idea to solve it? And what is it correct wa
to write clock triggered FSM with two (or more) clock sources?
-----------------------------------------------------------------------------------------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use ieee.std_logic_unsigned.all;
-- Entita
ENTITY Counter_FSM IS
GENERIC (
REGSIZE : integer := 8; -- range of counter
MODULO : natural := 50 -- modulo value
);
PORT (
CLK : IN STD_LOGIC; -- puls 50 MHz
CLK_tick : IN STD_LOGIC; -- puls 2 Hz
RESET : IN STD_LOGIC; -- reset
READY : OUT STD_LOGIC; -- counter is ready to start
START_C : IN STD_LOGIC; -- start of counting
DOUT : OUT STD_LOGIC_VECTOR(REGSIZE - 1 downto 0) -- output
);
END Counter_FSM;
--------------------------------------------------------------------------
--
-- Architecture of FSM
--
ARCHITECTURE Behavior OF Counter_FSM is
type counterState is (IDLE, COUNTING); -- states of FSM
signal currCounterState : counterState; -- current state
signal nextCounterState : counterState; -- next state
signal cnt : std_logic_vector(REGSIZE - 1 downto 0); -- data registe
for counter
begin
--------------------------------------------------------------------------
--
-- State update
UPDATE: process(RESET, CLK)
begin
if (RESET = '0') then
currCounterState <= IDLE;
elsif (CLK'event and CLK = '1') then
currCounterState <= nextCounterState;
end if;
end process;
--------------------------------------------------------------------------
--
-- Combi part
COMBI: process (clk_tick, start_c, currCounterState)
variable flg : std_logic := '0';
begin
if (clk_tick'event and clk_tick = '1') then
flg := '1';
end if;
case currCounterState is
when IDLE =>
cnt <= (others => '0'); -- counter value = zero
READY <= '1'; -- we can start
if (start_c = '1') then -- if button is pushed
nextCounterState <= COUNTING; -- then go to COUNTING state
end if;
when COUNTING =>
READY <= '0';
if (flg = '1') then -- Was there impuls of 2 Hz?
cnt <= cnt + 1; -- yes -> incrementing
flg := '0';
if (cnt = MODULO) then -- if value of cnt = MODULO
cnt <= (others => '0'); -- then cnt = zero
nextCounterState <= IDLE; -- and next state is IDLE
end if;
end if;
when others =>
nextCounterState <= IDLE;
end case;
-- OUTPUT
douT <= cnt;
end process;
--------------------------------------------------------------------------
end Behavior;
-----------------------------------------------------------------------------------
Thank you very much.
Mirek
P.S.: I am sorry my English is not so good
--------------------------------------
Posted through http://www.FPGARelated.com