# I am not getting output I want in ModelSim - Altera (perhaps something related to timing requirements not being met?)

I am writing some basic verilog code that blinks an LED at some frequency. The code is the following:

module FPGA_Testing( input clk, output wire LED);

reg [32:0] counter;
reg state;

always @ (posedge clk) begin
counter <= counter + 1;
state <= counter[20];

end

assign LED =  state;

endmodule


and the testbench is here

timescale 1ns/1ns

module FPGA_Testing_tb;

reg clk;
wire LED;

FPGA_Testing test(.clk(clk), .LED(LED));

initial
begin
clk = 0;
end

always
#5 clk = ~ clk;

endmodule


When I compile, I don't get any errors, but I do get the following warnings

Warning (18236): Number of processors has not been specified which may cause overloading on shared machines.  Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance.
Warning (18236): Number of processors has not been specified which may cause overloading on shared machines.  Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance.
Warning (292013): Feature LogicLock is only available with a valid subscription license. You can purchase a software subscription to gain full access to this feature.
Warning (15714): Some pins have incomplete I/O assignments. Refer to the I/O Assignment Warnings report for details
Critical Warning (169085): No exact pin location assignment(s) for 2 pins of 2 total pins. For the list of pins please refer to the I/O Assignment Warnings table in the fitter report.
Critical Warning (332012): Synopsys Design Constraints File file not found: 'FPGA_Testing.sdc'. A Synopsys Design Constraints File is required by the TimeQuest Timing Analyzer to get proper timing constraints. Without it, the Compiler will not properly optimize the design.
Warning (18236): Number of processors has not been specified which may cause overloading on shared machines.  Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance.
Warning (18236): Number of processors has not been specified which may cause overloading on shared machines.  Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance.
Critical Warning (332012): Synopsys Design Constraints File file not found: 'FPGA_Testing.sdc'. A Synopsys Design Constraints File is required by the TimeQuest Timing Analyzer to get proper timing constraints. Without it, the Compiler will not properly optimize the design.
Critical Warning (332148): Timing requirements not met
Info (11105): For recommendations on closing timing, run Report Timing Closure Recommendations in the TimeQuest Timing Analyzer.
Critical Warning (332148): Timing requirements not met
Info (11105): For recommendations on closing timing, run Report Timing Closure Recommendations in the TimeQuest Timing Analyzer.
Critical Warning (332148): Timing requirements not met
Info (11105): For recommendations on closing timing, run Report Timing Closure Recommendations in the TimeQuest Timing Analyzer.
Warning (18236): Number of processors has not been specified which may cause overloading on shared machines.  Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance.
Warning: Warning: File FPGA_Testing_run_msim_rtl_verilog.do already exists - backing up current file as FPGA_Testing_run_msim_rtl_verilog.do.bak7
Warning: Warning: File FPGA_Testing_run_msim_gate_verilog.do already exists - backing up current file as FPGA_Testing_run_msim_gate_verilog.do.bak11


Afterwards, when I run modelsim, I see the clk in the testbench oscillate, but all the other variables remain low or high the entire time:

I don't know why the waveform is showing the other variables change. I don't know why I am getting a timing requirements not met warning. And I don't know whether or not the two are related.

The output of your simulation doesn't make much sense because it is a gate level netlist (post fitter stage).

What you are seeing in your simulation is a gate level simulation on the optimised netlist. This is where all of the strange named signals have appeared from. The counter value added in ModelSim is dead because it is pre-synthesis signal which doesn't exist in your gate-level netlist.

I assume you are intending to run an RTL simulation rather than a Gate-Level simulation.

Lets have a look at what signals you have.

Because you are only using up to bit 20 of the counter, bits 21 through 32 (its a 33-bit counter) have absolutely no bearing on the design. It doesn't matter what value these bits take, so the tools optimise them away (notice how there are no strange named signals for these bits?).

The remaining bits are converted to fitter generated gate-level signals (*~50_comb, etc.), which do appear to have values, however I can't tell if these are counting because you haven't shown the LSBs of these signals, and the values of these may not make any sense without seeing the post-fitting netlist.

EDIT: I've just run your code through gate level simulation, and the various post fitting signals do count as expected:

If you were to run an RTL simulation, the resulting output would be a whole lot of unknown (x) values, because the design has no starting point.

Synchronous logic should almost always have a reset signal, this reset drives all registers in the design section into a known state. Any stateful logic requires some known initial state in order to know what state to go to next. If this were an RTL simulation (which I guess is what you intended to run), you would simply see the counter value stuck at xxxxxx because it has no initial value, so adding 1 to an unknown value results in another unknown value.

In this case you would add to your counter as signal called reset (or whatever), which when high sets the value of the counter and state variables to zero using an if-else statement in your always block.

As to why your design is failing timing, Quartus is telling you why:

Critical Warning (332012): Synopsys Design Constraints File file not found: 'FPGA_Testing.sdc'. A Synopsys Design Constraints File is required by the TimeQuest Timing Analyzer to get proper timing constraints. Without it, the Compiler will not properly optimize the design.

You do not have a Synopsys Design Constraints file. This is a file which tells TimeQuest how fast the various clocks are functioning in your system. Without such a file, TQ simply assumes all clocks run at some default frequency (1GHz if memory serves), and as such the design will undoubtedly fail timing requirements - because you haven't specified any.

Create a file called FPGA_Testing.sdc and add it to your Quartus project. Then add at the very least the lines below. This will get you valid information from TimeQuest.

##############################################################################
# Set resolution and units for timing file:
set_time_format -unit ns -decimal_places 3

##############################################################################
# Create a clock called "yourClockNameHere" (can be whatever you want)
# set its period in nanoseconds, set the waveform as { rise fall },
# and set which port in the design it is.
# The example below describes a 50MHz clock with 50% duty cycle
# (rise at 0ns, then fall at 10ns) driving the 'clk' top level port
create_clock -name yourClockNameHere -period 20.000 -waveform { 0.000  10.000 } [get_ports { clk }]

# You can make more than one clock if needed.

##############################################################################
# Now that we have created the custom clocks which will be base clocks,
# derive_pll_clock is used to calculate all remaining clocks for PLLs (if any)
# and clock uncertainties.
derive_pll_clocks -create_base_clocks
derive_clock_uncertainty
`