The Designer's Guide Community Forum
https://designers-guide.org/forum/YaBB.pl Design Languages >> Verilog-AMS >> Electrical Vs Real https://designers-guide.org/forum/YaBB.pl?num=1225693458 Message started by gandhi_gaurav on Nov 2nd, 2008, 10:24pm |
Title: Electrical Vs Real Post by gandhi_gaurav on Nov 2nd, 2008, 10:24pm I am designing a block with three inputs v1,v2,v3, one internal node v4 and the one output v5. Now v4 = 1 if (v1+v2+v3) > 3; V4 =0 if (v1+v2+v3) lies between 1 and 2 and V4 = -1 if (v1+v2+v3) <1. V5 = sin(omega) * v4 where omega is externally specified. Can anyone help me as how to model these mathematical functions in Verilog-AMS ? Mainly I am stuck at which to define electrical and which net is real. Thanks, -Gaurav |
Title: Re: Electrical Vs Real Post by Geoffrey_Coram on Nov 3rd, 2008, 5:36am Are v1,v2,v3 digital inputs? You don't specify what v4 is if (v1+v2+v3) is, say, 2.5 (nor, actually, if it's exactly == 1 or == 3), yet clearly v5 is a real-valued output. |
Title: Re: Electrical Vs Real Post by jbdavid on Nov 3rd, 2008, 2:28pm If this is an osc, you'll need to integrate omega over time to get Phase (phi) and then take sin(phi) .. this sounds like a variation on a voltage to frequency converter.. ? -- my rule of thumb is this.. if the variable needs the spice-like integration (& numerical error) control handled well, make it electrical (or other continuous/conservative discipline). g'luck! |
Title: Re: Electrical Vs Real Post by gandhi_gaurav on Nov 4th, 2008, 11:20pm Thanks for the reply. Let me explain the problem again. Just trying to realize spice statements like the following into veriloga .FUNC Q(v1,v2,v3,v4) { (Cg1*v3+Cg2*v4+C1*v1+C2*v2)/E } .FUNC VN(v) { CSUM*v/E } .FUNC GAMMA(u) { IF(T==0,IF(u<0,-u,0),IF(u==0,T,u/(EXP(u/T)-1)))} .FUNC ALPHA(v1,v2,v3,v4) { ROUND(-Q(v1,v2,v3,v4)+(CSUM/E)*(v1*RN2+v2*RN1)) } In the above statements the function N_OPT calls Function Q, CSUM. .FUNC R1L(n,v1,v2,v3,v4) {GAMMA(0.5 - n - Q(v1,v2,v3,v4) + VN(v1))/RN1} In the above statement the function R1L calls GAMMA. Now my query is regarding > best modeling practice regarding function calling functions the > number of values that can be returned If declarations in functions are real and these cant take values which are defined electrical? For example:- `include "constants.vams" `include "disciplines.vams" module setmod2(v1, v2, v3, v4,v5); inout v1, v2, v3, v4,v5; electrical v1, v2 ,v3, v4,v5; parameter real C1=1 ; parameter real C2=1 ; parameter real R1=1 ; parameter real R2=1 ; parameter real Cg1=1 ; parameter real Cg2=0.1 ; parameter real C0=0 ; parameter real Q0=0 ; parameter real TEMP=4.2 ; parameter real PI=3.14 ; parameter real E=1.5 ; parameter real KB=1.3 ; parameter real CSUM={C1+ C2+ Cg1+ Cg2+ C0} ; parameter real T={TEMP*CSUM*5.3785467E14} ; parameter real RN1={R1/(R1+ R2)} ; parameter real RN2={R2/(R1+ R2)} ; analog function real Q1; input v_1, v_2, v_3, v_4; real v_1,v_2, v_3,v_4; Q1 = (Cg1*V(v_1)+Cg2*V(v_2)+C1*V(v_3)+C2*V(v_4))/(E+Q0) ; endfunction analog begin V(v5) <= Q1(v1,v2,v3,v4); endmodule |
Title: Re: Electrical Vs Real Post by Geoffrey_Coram on Nov 5th, 2008, 5:15am A couple quick points: gandhi_gaurav wrote on Nov 4th, 2008, 11:20pm:
Ugh! If you're including constants.vams, why not use `M_PI? Quote:
Note that the LRM forbids you from using access function references in a function; you should change this to Q1 = (Cg1*v_1+Cg2*v_2+C1*v_3+C2*v_4)/(E+Q0) ; endfunction ... V(v5) <+ Q(V(v1), V(v2), V(v3), V(v4)); -Geoffrey |
Title: Re: Electrical Vs Real Post by Geoffrey_Coram on Nov 5th, 2008, 5:17am gandhi_gaurav wrote on Nov 4th, 2008, 11:20pm:
There's no N_OPT in what you posted ... Quote:
also no R1L ... |
The Designer's Guide Community Forum » Powered by YaBB 2.2.2! YaBB © 2000-2008. All Rights Reserved. |