1

I'm trying to set the system clock this way:

`timescale 5 ns/1 ns 

and then:

initial begin forever #0.5 clk = ~clk; end 

But, I'm getting the error Unexpected char '5'? Why? What is the problem with '5'? 10 for instance worked.

Another way that worked but not elegant:

 `timescale 1 ns/1 ns 

and

initial begin forever #2.5 clk = ~clk; end 

Does someone have a better solution?

1
  • The way that you deem "not elegant" is the way that you should (and everyone does) do it. Except as @toolic says, you're actually going to get a 166MHz clock. Commented May 28, 2020 at 14:43

2 Answers 2

4

The problem with 5 ns in the `timescale directive is that it is illegal syntax according to the IEEE Std. Only 1, 10 and 100 are permitted.

However, there is also a problem with your other code example:

`timescale 1 ns/1 ns forever #2.5 clk = ~clk; 

That does not produce a 200MHz clock. It produces a 166MHz clock. You specified a time precision of 1ns, which means that fractional delays will be rounded. In this case. 2.5 is rounded up to 3, which means you end up with a period of 6ns, not 5ns. You can see this by adding the following code to your testbench:

initial $monitor($realtime, "\tclk=%b", clk); 

Then you will see the period of clk is 6ns:

0 clk=0 3 clk=1 6 clk=0 9 clk=1 12 clk=0 15 clk=1 

One way to achieve a 200MHz clock is to use a precision of 100ps:

`timescale 1 ns / 100 ps forever #2.5 clk = ~clk; 
Sign up to request clarification or add additional context in comments.

Comments

3

From IEEE 1800-2017, section 22.7:

The time_unit argument specifies the unit of measurement for times and delays. The time_precision argument specifies how delay values are rounded before being used in simulation. The time_precision argument shall be at least as precise as the time_unit argument; it cannot specify a longer unit of time than time_unit. The integers in these arguments specify an order of magnitude for the size of the value; the valid integers are 1, 10, and 100.

I think you are misunderstanding what the timescale directive is for. It is for specifying the time unit and time precision of your simulation, not for specifying your clock period.


By the way: you can download IEEE 1800-2017 for free from the IEEE. (Accelera pays.) I recommend you do. It's quite readable.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.