The Designer's Guide Community
Forum
Welcome, Guest. Please Login or Register. Please follow the Forum guidelines.
May 1st, 2024, 4:21pm
Pages: 1
Send Topic Print
Current sense (Read 6456 times)
noreng
Junior Member
**
Offline



Posts: 20

Current sense
Jul 19th, 2005, 2:56am
 
How do I make a current sense in Verilog-A?
Back to top
 
 
View Profile   IP Logged
Eugene
Senior Member
****
Offline



Posts: 262

Re: Current sense
Reply #1 - Jul 19th, 2005, 9:00am
 
If you simply want to sense a current so you can use it in the same module, simply use I(p,n). You may need to add a node for the current sensor. For example, suppose you want to sense the current flowing into an input pin, "in". Try:

electrical inx; //defines an internal node
...
LHS variable = ...I(in,inx)...;//uses sensed current

You would then use inx inside your module in place of in. Beware that the current sensor shorts the nodes "in" and "inx" together. The current sensor is like a voltage source that has zero volts across it.
Back to top
 
 
View Profile   IP Logged
Geoffrey_Coram
Senior Fellow
******
Offline



Posts: 1998
Massachusetts, USA
Re: Current sense
Reply #2 - Jul 19th, 2005, 9:12am
 
Eugene -
I think the recommended way to sense a port (terminal) current is with

LHS = ... I(<in>) ... ;


-Geoffrey
Back to top
 
 

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



Posts: 262

Re: Current sense
Reply #3 - Jul 19th, 2005, 10:27pm
 
Thanks Geoffrey.  Am I correct in assuming the single node current sensor only works for ports?
Back to top
 
 
View Profile   IP Logged
noreng
Junior Member
**
Offline



Posts: 20

Re: Current sense
Reply #4 - Jul 20th, 2005, 12:19am
 
Thanks for your reply.

Yes, I want to sense a port current and I've noticed that I(in) short circuits in to ground.

However, I've tried your advice, but it didn't work. I get the following error messages:

In file src/switch_sense.vla line     52:
        LHS sense=I(p);
            ^
[Failure] Syntax error : received IDENTIFIER
         while expecting '('
                      or '[' or '='

and

In file src/switch_sense.vla line     52:
        LHS=I(p);
        ^
[Error] Symbol LHS has not been defined
Error: (valog) Compilation: Analysis failed.
Back to top
 
 
View Profile   IP Logged
Andrew Beckett
Senior Fellow
******
Offline

Life, don't talk to
me about Life...

Posts: 1742
Bracknell, UK
Re: Current sense
Reply #5 - Jul 20th, 2005, 3:53am
 
It wasn't something to use literally. LHS meant "Left Hand Side" and was a placeholder for some left-hand-side expression (e.g. some variable, or a contribution statement, or something like that).

Try reading Ken and Olaf's book on Verilog-AMS.

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



Posts: 1998
Massachusetts, USA
Re: Current sense
Reply #6 - Jul 20th, 2005, 4:21am
 
Eugene - Yes, that is special syntax only for ports (aka terminals).

One typical use of a current sensor is a controlled source:

Code:
module ccvs(in, out);
  inout in, out;
  electrical in, out;
  parameter real gain = 1;

  analog begin
    V(out) <+ gain * I(in); // shorts "in" to ground
  end
endmodule 



As noted before, this shorts "in" to ground, and then measures the current flowing through this shorted branch to generate the output voltage.

One might use the I(<port>) syntax in a more complicated module
Code:
module bjt(c,b,e);
  inout c,b,e;
  electrical c,b,e;

  real ic, ib, ie;

  analog begin
    // put BJT equations here

    ic = I(<c>);
    ib = I(<b>);
    ie = I(<e>);

    $strobe("Terminal currents: i(c)=", ic, " i(b)=", ib, " i(e)=", ie);
  end
endmodule 


     
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.