Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ddt function not working as expected

Status
Not open for further replies.

mr_mosfet

Newbie level 3
Joined
Nov 26, 2016
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
38
Hello,

Hopefully this is posted in the right area. I'm trying to model the current of the device which is captured by one of the last lines of this code:

(I(p,n) <+ ddt(polar);)

Code:
// VerilogA for tech_support3, test, veriloga

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

`define M_PI 3.14159

module test(p,n);

	inout p,n;
	electrical p,n;

	real v_prev;
	real v_present;
	real v_c_pos;//positive coercive voltage
	real v_c_neg;//negative coercive voltage
	real v_tp_pos;//positive turning point
	real v_tp_neg;//negative turning point

	real polar;
	real polar_r;
	real polar_tp_pos;
	real polar_tp_neg;
	real polar_temp;

	analog function real f;
		real v; real v_c;//v_c is coercive voltagle
		input v; input v_c;
		f = (2/`M_PI)*atan((v-v_c));
    	endfunction

	analog begin
		@(initial_step) begin
        	v_prev = 0;
        	v_present = 0;
		v_c_pos = 5;
		v_c_neg = -5;
		v_tp_pos = 5;
		v_tp_neg = -5;
		
		polar = 0;
		polar_r = 1;
		polar_tp_pos = 0;//positive coercive voltage
		polar_tp_neg = 0;//negative coercive voltage absolute value

        	end
		
		if ((v_present > v_prev) && (v_present > 0)) begin
			
			polar_temp = polar_tp_neg + 0.5*polar_r*(1 + f(v_present, v_c_pos))*(1 + f(-1*v_tp_neg, -1*v_c_neg));


			if(polar_temp > polar)
				polar = polar_temp;

			if (v_present > v_tp_pos)
				v_tp_pos = v_present;
				polar_tp_pos = polar_tp_neg + 0.5*polar_r*(1 + f(v_present, v_c_pos))*(1 + f(-1*v_tp_neg, -1*v_c_neg));
				

		end

		if ((v_present < v_prev) && (v_present < 0)) begin
			
			polar_temp = polar_tp_pos - 0.5*polar_r*(1 + f(v_tp_pos, v_c_pos))*(1 + f(-1*v_present, -1*v_c_neg));

			if(polar_temp < polar)
				polar = polar_temp;
			
			if (v_present < v_tp_neg)
				v_tp_neg = v_present;
				polar_tp_neg = polar_tp_pos - 0.5*polar_r*(1+ f(v_tp_pos, v_c_pos))*(1 + f(-1*v_present, -1*v_c_neg));


		end

		v_prev = v_present;
		v_present = V(p,n);
		
		I(p,n) <+ ddt(polar);//current equation currently not working

	end

endmodule

When I implement the code as above I get a flat line for the current (brown curve in the first pic named "ddt_polar"). However I think it should be nonzero in places. I ran the same simulation with the current set to:

I(p,n) <+ polar;

and got the curve as seen in the second pic named "polar". Clearly the polar variable is changing so ddt(polar) should give me a nonzero current but its not. Why is this so?

Thank you.
 

Attachments

  • ddt_polar.jpg
    ddt_polar.jpg
    505.1 KB · Views: 114
  • polar.jpg
    polar.jpg
    500.9 KB · Views: 116

I should clarify the problem because there were some mistakes in my previous post. The first pic shows the current response across the p and n inout terminals (shown as a brown line) from a voltage applied across the same p and n inout terminals (shown as a red line). The current equation is:

I(p,n) <+ polar;

When I change the above line in the code to:

I(p,n) <+ ddt(polar);

I obtain the second pic; again the red line is the applied input voltage across the inout terminals p and n and the brown line is the current response across the same inout terminals p and n. In the first pic the current:

I(p,n) <+ polar;

is clearly not constant so when I take the derivative:

I(p,n) <+ ddt(polar);

I would expect a nonzero current but the current I get is 0 for all time. Why is this the case?

Thank you
 

"polar" is declared as a "real", but not an "electrical".
I think maybe ddt() only works on "live" stuff? What
happens if you force "polar" value onto an electrical
node, and take ddt of that? Do docs say anything
about what classes the ddt function operates on?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top