The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl
Design Languages >> Verilog-AMS >> "Static" variable in VerilogA
https://designers-guide.org/forum/YaBB.pl?num=1170146863

Message started by VerilogANovice on Jan 30th, 2007, 12:47am

Title: "Static" variable in VerilogA
Post by VerilogANovice on Jan 30th, 2007, 12:47am

Can there be "static" variable (like those in C) in Verilog A? I want my device model to behave differently when I sweep voltage from 0 to 5V and from 5V to 0V, so I want the device model to kinda *remember* what has happened to it before. Is there any way to do so?

Thanks!

Title: Re: "Static" variable in VerilogA
Post by Geoffrey_Coram on Jan 30th, 2007, 4:28am

A variable that does what you're talking about is often called a "hidden state" variable (and causes trouble for some analysis types in some simulators).


Code:
`include "disciplines.h"
module hyst(in, out);
inout in, out;
electrical in, out;
real hyst_state;

analog begin
 if (V(in) < 2) hyst_state = 0;
 if (V(in) > 4) hyst_state = 1;

 V(out) <+ hyst_state;
end
endmodule


This should demonstrate what you want; try it both in a dc sweep of the voltage driving "in" and also with a transient -- say sine wave -- that goes from 0 to 5.

Title: Re: "Static" variable in VerilogA
Post by VerilogANovice on Jan 30th, 2007, 4:49pm

Thanks a lot! It's exactly how I want it to behave. Would you please explain how it works? Thanks!

Title: Re: "Static" variable in VerilogA
Post by Geoffrey_Coram on Jan 31st, 2007, 3:55am

The language specifies that all variables are initialized to zero at the start of the simulation.  Each time the module is evaluated (for the time=0 dc solution and at each timepoint) the voltage V(in) is compared to the threshold, and if it meets one of the conditions, the appropriate value is assigned to hyst_state.  The value of hyst_state is otherwise persistent across timepoints.

Title: Re: "Static" variable in VerilogA
Post by Ken Kundert on Jan 31st, 2007, 10:01am

Verilog modules are conceptually quite different than the functions you will find in a traditional programming language like c or c++. Modules are intended to model a piece of hardware, and as such are not 'called', but rather 'instantiated'. Thus, the module always exists and is active, meaning that it is constantly monitoring its inputs and producing outputs. In addition, the local variables in a module retain their values over time. As such they are considered state variables and are similar to the 'static variables' you will find in c or c++. There is no equivalent to the 'automatic variables' of c or c++ within a Verilog module.

Here when I say Verilog I mean all forms of Verilog, including Verilog-A and Verilog-AMS.

-Ken

The Designer's Guide Community Forum » Powered by YaBB 2.2.2!
YaBB © 2000-2008. All Rights Reserved.