I'm a fpga & vhdl newbie..
My development environment is as follows.
FPGA :Spartan 6 XC6SLX9
Compiler : ISE 14.04
Simulator : Isim
I'm making a simple counter, but there are some things I can't understand.
The following code is what I wrote. What I expected was w_count
increased every falling edge of the clock, and reset to 0 when w_count
reach to N_data
during rising edge of the clock. There was no problem in the compilation process, and simulation also works well as I expected. But when applied to real fpga, w_count
was incremented for each trigger, but was not initialized to zero when reached to N_data
..
w_state_proc : process(r_clk, reset_n_clean)
begin
if(reset_n_clean = '0') then
w_count <= 0;
elsif(r_clk'event and r_clk = '0') then
if(state = write_state and w_proc = '1') then
w_count <= w_count + 1;
end if;
elsif(r_clk'event and r_clk = '1') then
if(w_count = N_data) then
w_count <= 0;
end if;
end if;
end process w_state_proc;
When I changed the position of two elsif
statements, w_count
didn't increase at all..
w_state_proc : process(r_clk, reset_n_clean)
begin
if(reset_n_clean = '0') then
w_count <= 0;
elsif(r_clk'event and r_clk = '1') then
if(w_count = N_data) then
w_count <= 0;
end if;
elsif(r_clk'event and r_clk = '0') then
if(state = write_state and w_proc = '1') then
w_count <= w_count + 1;
end if;
end if;
end process w_state_proc;
I could see a lot of feedback that these statements are not recommended, but I don't understand why these statements cause this problems..