Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Valued Contributor III
2,387 Views

gate lev sim not working as expected

hello everybody 

im quite new in developing for FPGA. 

I have started wih DE0-nano board.  

im learning just programming an easy FSM that performs elementary operations. 

i have followed the tutorial for simulating the circuit with Modelsim-Altera. 

no problem with the flow of functional simulation. the operations are simulated in the sequence as expected. 

While trying to create timing simulation with the same Modelsim (gate level simulation) 

my FSM does not work as expected. The state of FSM is update in not controlled way. 

I have made several tries and i have the suspect to have wrong code the two process statement that concurrency run. 

The source code is in VHDL. 

So same code in VHD work in functional simulation and worngly work in gate level simulation. 

i would like to fix this issue to learn more about FPGA.  

 

Thank you
0 Kudos
21 Replies
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

without the code, we cant really tell what the problem is. Is the design fully syncrhonous?

0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

without the code, we cant really tell what the problem is. Is the design fully syncrhonous? 

--- Quote End ---  

 

can i post the code here? 

 

the project is simple FSM with asyncrohous input and one clock to trigger all the transiction inside
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

sorry for the alert, 

but it's safe to post code here?
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

sorry for the alert, 

but it's safe to post code here? 

--- Quote End ---  

 

 

Yes. Post the code so we can try and work out whats wrong.
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

following the code that works in RTL simulation but not in gate level simulation. 

IN particular, in gate level sim, the counter is not increasing and the state jumps directly into '11' that is not correct. 

 

Thanks for the help 

 

 

LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.all; ENTITY somma_FSM IS GENERIC ( WAIT_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"00"; WORK_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"01"; END_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"11" ); PORT ( ingressoA : IN STD_LOGIC; ingressoB : IN STD_LOGIC; inizia : IN STD_LOGIC; resetn :IN STD_LOGIC; clock : IN STD_LOGIC; finito : OUT STD_LOGIC; somma : OUT STD_LOGIC; resto : OUT STD_LOGIC ); END somma_FSM; ARCHITECTURE somma_FSM_architecture OF somma_FSM IS SIGNAL current_state :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"00"; SIGNAL next_state :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"00"; SIGNAL counter :STD_LOGIC_VECTOR(2 DOWNTO 0) := B"000"; SIGNAL resto_in :STD_LOGIC := '0'; SIGNAL resto_out :STD_LOGIC := '0'; BEGIN PROCESS(inizia, current_state, counter) BEGIN CASE(current_state) IS WHEN B"00" => IF (inizia = '1') THEN next_state <= B"01"; ELSE next_state <= B"00"; END IF; WHEN B"01" => IF (counter = B"111") THEN next_state <= B"11"; -- finito <= '1'; END IF; WHEN B"11" => next_state <= B"00"; WHEN OTHERS => END CASE; END PROCESS; PROCESS(clock) BEGIN IF (resetn = '0') THEN current_state <= WAIT_STATE; counter <= (OTHERS => '0'); ELSE IF ((clock'EVENT) AND (clock = '0')) THEN current_state <= next_state; IF (current_state = B"00") THEN counter <= (OTHERS => '0'); ELSE IF (current_state = B"01") THEN counter <= counter + '1'; resto_in <= resto_out; END IF; END IF; END IF; END IF; END PROCESS; somma <= ingressoA XOR ingressoB XOR resto_in; resto_out <= (ingressoA AND ingressoB) OR (ingressoA AND resto_in) OR (ingressoB AND resto_in); resto <= resto_out; finito <= '1' WHEN current_state =B"11"; END somma_FSM_architecture;
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

I do notice that reset is not in the sensitivity list of the 2nd process. 

 

But can you post your testbench? 

 

Did you provide any timing specifications to the design?
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

I do notice that reset is not in the sensitivity list of the 2nd process. 

 

But can you post your testbench? 

 

Did you provide any timing specifications to the design? 

--- Quote End ---  

 

 

 

reset signal is not used. 

 

test bench is the following: 

 

http://www.alteraforum.com/forum/attachment.php?attachmentid=13078&stc=1
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

reset is no used. 

any time specification provided  

 

test bench is the following: 

 

https://www.alteraforum.com/forum/attachment.php?attachmentid=13079
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

That is not a testbench - that ios the waveform output from the design.  

What code are you using to test your design?
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

That is not a testbench - that ios the waveform output from the design.  

What code are you using to test your design? 

--- Quote End ---  

 

 

synthesis code is VHDL 

ModelSim code is converted in Verilog
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

I Notice the next_state and finito signal is not assigned in all branches, so it will create latches. This might be what is causing the problems.

0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

I Notice the next_state and finito signal is not assigned in all branches, so it will create latches. This might be what is causing the problems. 

--- Quote End ---  

 

 

what do you mean for .. is not assigned in all branches?
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

In an asynchronous process, all signals must be assigned in all cases, otherwise latchea will be created. 

 

For example, when current state is 01, next state is only assigned when the counter gets to 7, otherwise it holds its state. This creates a latch. You must at least assign it to current state to avoid the latch.  

 

The same for finito. It is only assigned here. This creates a latch.
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

im going literally crazy .. 

i have modified the code in this way 

LIBRARY ieee; USE ieee.std_logic_1164.all; USE ieee.std_logic_unsigned.all; USE ieee.numeric_std.all; ENTITY somma_FSM IS GENERIC ( WAIT_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"00"; WORK_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"01"; END_STATE :STD_LOGIC_VECTOR(1 DOWNTO 0) := B"11" ); PORT ( ingressoA : IN STD_LOGIC; ingressoB : IN STD_LOGIC; inizia : IN STD_LOGIC; resetn :IN STD_LOGIC; clock : IN STD_LOGIC; finito : OUT STD_LOGIC; somma : OUT STD_LOGIC; resto : OUT STD_LOGIC ); END somma_FSM; ARCHITECTURE somma_FSM_architecture OF somma_FSM IS SIGNAL current_state :STD_LOGIC_VECTOR(1 DOWNTO 0); SIGNAL next_state :STD_LOGIC_VECTOR(1 DOWNTO 0); SIGNAL counter :STD_LOGIC_VECTOR(2 DOWNTO 0); SIGNAL resto_in :STD_LOGIC := '0'; SIGNAL resto_out :STD_LOGIC := '0'; BEGIN PROCESS(inizia, current_state, counter) BEGIN CASE(current_state) IS WHEN B"00" => IF (inizia = '1') THEN next_state <= B"01"; finito <= '0'; ELSE next_state <= B"00"; finito <= '0'; END IF; WHEN B"01" => IF (counter = B"111") THEN next_state <= B"11"; finito <= '1'; ELSE next_state <= B"01"; finito <= '0'; END IF; WHEN B"11" => next_state <= B"00"; finito <= '0'; WHEN OTHERS => END CASE; END PROCESS; PROCESS(resetn,clock) BEGIN IF (resetn = '0') THEN current_state <= WAIT_STATE; counter <= (OTHERS => '0'); ELSE IF ((clock'EVENT) AND (clock = '0')) THEN current_state <= next_state; IF (current_state = B"00") THEN counter <= (OTHERS => '0'); ELSE IF (current_state = B"01") THEN counter <= counter + '1'; resto_in <= resto_out; END IF; END IF; END IF; END IF; END PROCESS; somma <= ingressoA XOR ingressoB XOR resto_in; resto_out <= (ingressoA AND ingressoB) OR (ingressoA AND resto_in) OR (ingressoB AND resto_in); resto <= resto_out; --finito <= '1' WHEN current_state =B"11"; END somma_FSM_architecture;  

 

 

i got these waveforms ...  

 

https://www.alteraforum.com/forum/attachment.php?attachmentid=13083
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

Please post your test bench code, without it we cannot test your code.

0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

That is not a testbench - that ios the waveform output from the design.  

What code are you using to test your design? 

--- Quote End ---  

 

 

Sorry for the ignorance, 

For test bench code you mean eda netlist file in verilog generated for modelsim?
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

Sorry for the ignorance, 

For test bench code you mean eda netlist file in verilog generated for modelsim? 

--- Quote End ---  

 

 

No - the testbench is the code you use to test your code - you have to generate inputs for the design somehow...
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

 

--- Quote Start ---  

No - the testbench is the code you use to test your code - you have to generate inputs for the design somehow... 

--- Quote End ---  

 

 

Sorry, i do not use test bench. 

I perform compilation in quartus, open modelsim, run the simulation and using modelsim Waveforms editors to provide input to dut. 

In wave window i add output waveforms to see what happens
0 Kudos
Highlighted
Valued Contributor III
2 Views

Re: gate lev sim not working as expected

What code are you using to test your design?

0 Kudos