Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
17235 Discussions

how to use `timescale in verilog!

Altera_Forum
Honored Contributor II
23,891 Views

Hi, I'm a beginner and I don't know how to use `timescale in verilog and what does it mean, why it used for... 

thanks in advanced!
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
17,247 Views

`timescale has the format of unit / precision. It has no effect in synthesis. It is used for simulation modeling. 

If not specified, it is "1s / 1s". A statement like "assign# 1 a = b;" means "a" is updated 1s later. 

Precision denotes a fraction of time unit allow in code.
0 Kudos
Altera_Forum
Honored Contributor II
17,247 Views

ok, now i know the struct of that format. 

but my problem is fraction of time unit allow in code, can you explain clearly. i don't know how to use it. 

can you explain clearly?
0 Kudos
Altera_Forum
Honored Contributor II
17,247 Views

`timescale 1ns/1ps means that all the delays that follow (like# 5.1234) are interpreted to be in nanoseconds and any fractions will be rounded to the nearest picosecond (5123ps). However, all delays are represented as integers. The simulator knows nothing about seconds or nanoseconds, only unit-less integers. 

 

It might help to understand that Verilog is defined with discrete event-driven simulation semantics. That means simulation time is defined as an integer, and all signal changes (events) scheduled for a later time are put into queues. A queue for a discrete time in the future is created as soon as an event needs to be scheduled for that time. As soon as all the events for the current time are finished, the simulator looks for the next time queue where an event is scheduled, advances the current time to that next time, and the process repeats until there is nothing left to do, or it executes a $finish. Time is discrete because the simulator only executes the times where events are scheduled, and skips over everything else. 

 

In order to synchronize the scheduling of events across different modules with different timescales and precisions, the simulator picks the smallest time precision across used in the entire design and assigns that the value of 1 time unit integer. If the smallest precision was 10ps, that becomes the global value of 1 time unit. So if there were a module with a timescale of 1ns/1ns and there was a delay of# 12.3, that would be rounded to 12ns and then scaled to an integer of 1200. (1200x10ps= 12ns)
Altera_Forum
Honored Contributor II
17,247 Views

now i know about this. thanks!

0 Kudos
Reply