The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 6th, 2024, 5:24am
Pages: 1
Send Topic Print
Modelling of a simple counter in Verilog-A (Read 5986 times)
radius2
New Member
*
Offline



Posts: 9

Modelling of a simple counter in Verilog-A
Oct 02nd, 2012, 8:05am
 
Hi,

I'm trying to model a simple counter in Verilog-A. The counter should simply count the number of positive clock edges of the input signal Clk.
I wrote the following code to model the behaviour:

@(cross(V(Clk)-Vtreshold, +1)) begin
   count = count + 1;
   $strobe(count)  //prints the value of the count variable

I simulated the counter in spectre for 5 clock cycles and hoped to
see the variable count printed out 5 times and increased to 5. However, it increased to about 100. It seems as the statements inside the @cross are evaluated several times when the crossing is detected.
I guess that I missunderstood the crossing function. Is there a way to
only detect the clock edge only once when the crossing is detected?  

Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Modelling of a simple counter in Verilog-A
Reply #1 - Oct 2nd, 2012, 8:30am
 
The cross function works OK for me.

I would suggest you put
 $strobe("crossing detected at %g, count now %d", $abstime, count);
inside the cross event block, and see if you get the message multiple times for a particular $abstime -- and if the time values correspond to when you think the crossings should occur.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
radius2
New Member
*
Offline



Posts: 9

Re: Modelling of a simple counter in Verilog-A
Reply #2 - Oct 4th, 2012, 10:07am
 
Hi,

Thank you for your reply.
I've fixed it now.
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Modelling of a simple counter in Verilog-A
Reply #3 - Oct 10th, 2012, 2:42pm
 
It's usually nice to say what you fixed, for the benefit of other readers, or someone who searches the forum later and has the same problem.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
radius2
New Member
*
Offline



Posts: 9

Re: Modelling of a simple counter in Verilog-A
Reply #4 - Oct 11th, 2012, 5:43am
 
Off course,

I think the problem was that I first copied the code from another
cell and forgot to change the module declaration. The module declaration was

module CellX(In, Out, Clk)

instead of

module Counter(In, Out, Clk),

while the name of the cell is still Counter.

As the code refers to another already existing module it will
cause strange behaviour. An advice is therefore to always check this
when finnished with the code.
Back to top
 
 
View Profile   IP Logged
Pages: 1
Send Topic Print
Copyright 2002-2024 Designer’s Guide Consulting, Inc. Designer’s Guide® is a registered trademark of Designer’s Guide Consulting, Inc. All rights reserved. Send comments or questions to editor@designers-guide.org. Consider submitting a paper or model.