Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to get system time in verilog

Status
Not open for further replies.

starone

Newbie level 1
Newbie level 1
Joined
Apr 22, 2006
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,287
verilog system time

Hi all,

i want to generate a random number in verilog with the system time as the seed.
the normal $random() generates a random value by taking the $time (simulation time) as its seed.
so, how do i get the "system time" in verilog (or) how do i generate random value with system time as its seed.

Thanks,
jala
 

I could not find an elegant way, but here's how I did it - a system call to write the current time into a file, then read the file to get the info into verilog. The system call to "date" only works on *NIX - if you are on windows, you'll have to change that. Anyway, here's the code:

Code:
integer FP;
integer fgetsResult;
integer sscanfResult;
integer NowInSeconds;
reg [8*10:1] str;

// call "date" and put out time in seconds since Jan 1, 1970 (when time began, no doubt)
// and put the results in a file called "now_in_seconds"
$system("date +%s > now_in_seconds");                                                   

// open the file for reading
FP = $fopen("now_in_seconds","r");

// get a string from the open file - "fgetsResult" should be a 1 - you can test 
// that for completeness if you'd like
fgetsResult = $fgets(str,FP);

// convert the string to an integer - "sscanfResult" should also be a 1, and
// you can test that, too, 
sscanfResult = $sscanf(str,"%d",NowInSeconds);

// close the file...
$fclose(FP);  // closes the file

// use the number as a seed...
process::self.srandom(NowInSeconds);


I have run this in "ncverilog" and confirmed it on both Solaris and Linux systems.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top