The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
Jul 16th, 2024, 8:15pm
Pages: 1
Send Topic Print
counter (Read 2955 times)
kamath
Junior Member
**
Offline



Posts: 16

counter
Oct 31st, 2007, 4:54am
 
hai,
i have coded a counter block ,could some one help me as i am not getting the required waveform at output:

// VerilogA for project, counter, veriloga

`include "constants.vams"
`include "disciplines.vams"

module counter(incnt,cntclk,cntout,rst);
input  incnt,cntclk,rst;
output cntout;
electrical incnt,cntclk,rst,cntout;
real step;
parameter real vtrans=0.3;
parameter real maxstep=15;
parameter real minstep=0;

analog begin

@(cross(V(cntclk)-vtrans,1))
       begin
               if((V(incnt)-vtrans)>0)
                       step=step+1;
               else
              step=step-1;
if(step>maxstep)
step=maxstep;
if(step<minstep)
step=minstep;
if(V(rst)>0)
step=0;
V(cntout)<+step;
end
end
endmodule

please help me as i am new to verilog-ams.
thank you
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: counter
Reply #1 - Oct 31st, 2007, 6:53am
 
Fix your begin/end blocks as indicated below.

kamath wrote on Oct 31st, 2007, 4:54am:
hai,
i have coded a counter block ,could some one help me as i am not getting the required waveform at output:

// VerilogA for project, counter, veriloga

`include "constants.vams"
`include "disciplines.vams"

module counter(incnt,cntclk,cntout,rst);
input  incnt,cntclk,rst;
output cntout;
electrical incnt,cntclk,rst,cntout;
real step;
parameter real vtrans=0.3;
parameter real maxstep=15;
parameter real minstep=0;

analog begin

@(cross(V(cntclk)-vtrans,1))
       begin
               if((V(incnt)-vtrans)>0)
                       step=step+1;
               else
              step=step-1;
               if(step>maxstep)
                 step=maxstep;
               if(step<minstep)
                 step=minstep;
       end // add this one
if(V(rst)>0)
step=0;
V(cntout)<+step;
//end -- remove this one
end
endmodule

please help me as i am new to verilog-ams.
thank you

Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1999
Massachusetts, USA
Re: counter
Reply #2 - Oct 31st, 2007, 6:58am
 
Actually, you may need the "end" to be added right before
V(cntout)<+step;
if you want the reset to only happen on clock edges.
Back to top
 
 

If at first you do succeed, STOP, raise your standards, and stop wasting your time.
View Profile WWW   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.