# Capture time between two events for multiple cycle

**URL:** <https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, realtime\
**Created:** [March 1, 2018, 6:41pm UTC](https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149 "2018-03-01T18:41:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spriyada29](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@Spriyada29](https://verificationacademy.com/forums/u/Spriyada29)\
**Post date:** [March 1, 2018, 6:41pm UTC](https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149/1 "2018-03-01T18:41:24Z")

</div>

I need to calculate the average time to complete a write/read activity. Lets say there is a bus signal,hwrite. hwrite high-\>Write, hwrite Low-\>Read. Certain write/read operation can take 3 cycle,other takes 2,other maybe 10 and so on. I would like to calculate what’s the average latency of a write/read cycle.  
So I need to calculate the time between hwrite-high and the next hwrite low, add to a queue or some other array and repeat the same for all the write/read .

At the end of all the cycle,I’ll calculate the time taken by all the writes/read divided by number of write/read. Can someone please suggest me a way to achieve it. I am not able to capture the time correctly. Any suggestion would be great.

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [March 1, 2018, 11:06pm UTC](https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149/2 "2018-03-01T23:06:56Z")

</div>

_In reply to [Spriyada29](https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149):_  
You can use assertions with function calls (or just tasks) to update read and write counters.  
Basically, you update a read\_count and write\_count with the number of cycles it took to complete the transaction, and do a sample. See my paper on tasks and assertions.  
[https://verificationacademy.com/forums/systemverilog/vf-horizonspaper-sva-alternative-complex-assertions#reply-66770](https://verificationacademy.com/forums/systemverilog/vf-horizonspaper-sva-alternative-complex-assertions#reply-66770)

You can also consider the use of **covergroup** and binning for your statistics. From my [SVA Handbook, 4th Edition](http://goo.gl/JOfuEB) the example may give you ideas.

- [http://SystemVerilog.us/fv/binning.pdf](http://SystemVerilog.us/fv/binning.pdf) // concept
- [http://SystemVerilog.us/fv/bining.sv](http://SystemVerilog.us/fv/bining.sv) // code example
- [http://SystemVerilog.us/fv/bining.JPG](http://SystemVerilog.us/fv/bining.JPG) // results
- [http://SystemVerilog.us/fv/BINING2.JPG](http://SystemVerilog.us/fv/BINING2.JPG) // results

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)  
For training, consulting, services: contact [Home - My cvcblr](http://cvcblr.com/home)

- [SVA Handbook 4th Edition, 2016 ISBN 978-1518681448](http://goo.gl/JOfuEB)
- [Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712](https://goo.gl/d10QHh)
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

---

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [March 2, 2018, 1:39am UTC](https://verificationacademy.com/forums/t/capture-time-between-two-events-for-multiple-cycle/34149/3 "2018-03-02T01:39:51Z")

</div>

Of course, you can use queues to push the values of the counts, and and end of test pop and add, then divide by the queue depth as you suggested.  
Ben [systemverilog.us](http://systemverilog.us)
