electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

how to get system time in verilog


Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing -> how to get system time in verilog
Author Message
starone



Joined: 22 Apr 2006
Posts: 1


Post16 Sep 2006 8:17   

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
Back to top
Google
AdSense
Google Adsense




Post16 Sep 2006 8:17   

Ads




Back to top
laxdad8992



Joined: 12 Nov 2008
Posts: 2


Post16 Oct 2009 16:52   

Re: how to get system time in verilog


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.
Back to top
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing -> how to get system time in verilog
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
how to aquire system time in verilog? (1)
How to get a figure: Freq. vs Time in HSpice? (5)
How to get verilog simulation library? (2)
Please help me: How to get a short settling time (7)
how can I get the document in verilog-a (2)
How to get group delay time report for HFSS_9? (2)
How to understand and get the response time of a filter? (2)
how to get precise time with pic - help needed (24)
how to get an Nx64k clock divider using verilog ???? (7)
TetraMax help.. How to get Verilog Model libraries (2)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS