Measure current/voltage inside sub-circuit ?

2012-11-27
2013-06-12
  • Amal Banerjee

    Amal Banerjee - 2012-11-27

    Could some Ngspice guru plase help ?
    The standard procedure to measure current is to
    have a voltage source with zero AC/DC voltage,
    and measure current through it.
    Ex:
    VSENSE <node+> <node-> DC 0.0 AC 0.0
    and then
    .PRINT TRAN I(VSENSE)

    Now suppose VSENSE is inside a sub-circuit
    as:
    .SUBCKT 1 2 3
    ….

    VSENSE 1 0 DC 0.0 AC 0.0
    …..
    .ENDS

    Now how do I measure current through VSENSE ?
    One way to do it would be to place a similar
    zero voltage external voltage source in series with
    the internal voltage source and measure the current
    through the external one.

    I was wondering if there is anything wrong with this.
    Any hints/suggestions are welcome. Thanks in
    advance.

     
  • marcel hendrix

    marcel hendrix - 2012-11-27

    First, make a listing for your (working) circuit by interactively typing "listing e." Use the renamed nodes and sources found in this listing to request output.

    The renaming process is not arbitrary. As all simulators do it differently, I can never remember the exact rules, sorry. (Example: a voltage source E1 inside a subcircuit X1 gets called E.X1.E1).

    -marcel

     
  • Amal Banerjee

    Amal Banerjee - 2012-11-28

    Hello,
    The batch mode provides the subcircuit information as:
    v.xmot.vsense2#branch                        0
    h.xmot.h_torq#branch                         0
    v.xmot.vsense1#branch                        0
    h.xmot.h_emf#branch                          0
    l.xmot.l0#branch                             0
    l.xmot.larm#branch                           0
    v_amp#branch

    However, the current can still not be measured,
    because even if I have:
    .PRINT TRAN I(v.xmot.vsense1) I(v.xmot.vsense2)
    The output is:
    Index   time            v.xmot.vsense1# v.xmot.vsense2#


    0 6.080000e-02 0.000000e+00 0.000000e+00
    1 1.120000e-01 0.000000e+00 0.000000e+00
    2 1.730000e-01 0.000000e+00 0.000000e+00
    3 2.340000e-01 0.000000e+00 0.000000e+00
    4 2.950000e-01 0.000000e+00 0.000000e+00
    ……
    ……

    Only the voltage gets correctly printed out.

     
  • marcel hendrix

    marcel hendrix - 2012-11-28

    Please provide the full circuit file.

     
  • Amal Banerjee

    Amal Banerjee - 2012-11-29

    Two forms of the circuit are provided, one in sub-circuit form,
    the other without sub-circuit. Please note that the transient
    response results, once plotted, look very different in the
    two cases.

    A: SUB CIRCUIT FORM
    MOTOR

    *SIMPLE BRUSHED DC MOTOR

    .SUBCKT SIMBRDCMOT 1   
    * 1 VIN
    * MOTOR VOLTAGE
    RARM 1 4 0.5
    LARM 4 5 0.0015
    H_EMF 5 6 VSENSE2 0.5
    VSENSE1 6 0 DC 0.0 AC 0.0
    *MOTOR TORQUE - INERTIA/FRICTION
    H_TORQ 7 0 VSENSE1 0.5
    L0 7 8 0.00025
    R0 8 9 0.0001
    VSENSE2 9 3 DC 0.0
    *MOTOR POSITION
    F_POS 0 8 VSENSE2 1
    C_POS 8 0 1.0
    R_POS 8 0 1.0MEG
    .ENDS

    V_AMP 1 0 DC 0.0 AC 1 PWL(0MS 0V 5MS 5V 10MS 20V  1000MS 20V  1010MS 5V 1020MS 0V 1050MS 0V 1060MS 5V 1070MS 20V 2000MS 20V 2010MS 5V 2020MS 0V 2050MS 0V 2060MS 5V 2070MS 20V 3050MS 20V 3060MS 5V 3070MS 0V)
    XMOT 1 SIMBRDCMOT

    * ANALYSIS
    .OPTIONS NOPAGE METHOD=GEAR
    .IC
    .PROBE V(*) 
    .TRAN 100ms 3100ms 50ms UIC
    .PRINT TRAN I(v.xmot.vsense1) I(v.xmot.vsense2)
    .END

    B: NON SUB-CIRCUIT FORM:
    * MOTOR VOLTAGE
    V_AMP 1 0 DC 0.0 AC 1 PWL(0MS 0V 5MS 5V 10MS 20V  1000MS 20V  1010MS 5V 1020MS 0V 1050MS 0V 1060MS 5V 1070MS 20V 2000MS 20V 2010MS 5V 2020MS 0V 2050MS 0V 2060MS 5V 2070MS 20V 3050MS 20V 3060MS 5V 3070MS 0V)

    RA 1 2 0.5
    LA 2 3 0.0015
    H_EMF 3 4 VSENSE2 0.05
    VSENSE1 4 0 DC 0V

    * MOTOR TORQUE BASED ON INERTIA AND FRICTION
    H_TORQ 6 0 VSENSE1 0.05
    LJ 6 7 0.00025
    RB 7 8 0.0001
    VSENSE2 8 0 DC 0V

    * MOTOR POSITION
    FPOS 0 11 VSENSE2 1
    CPOS 11 0 1
    RPOS 11 0 1MEG

    .OPTIONS NOPAGE METHOD=GEAR
    .IC V(2)=0.0 V(3)=0.0 V(4)=0.0 V(6)=0.0 V(7)=0.0 V(11)=0.0
    .PROBE V(*)
    .TRAN 100ms 3100ms 50ms UIC
    .PRINT TRAN I(VSENSE1) I(VSENSE2)
    .END

     
  • marcel hendrix

    marcel hendrix - 2012-11-29

    Do not use .PROBE V(*), it blocks getting results.

    I do not (yet) know why you get different output when that line is removed from both circuits. Maybe it is better to open a separate ticket for that problem.

    -marcel

     
  • Robert Larice

    Robert Larice - 2012-11-29

    Hello dakuu,

      your two circuits "A" and "B" have different parameters
        for at least two circuit elements

      H_EMV  0.05 versus 0.5
      H_TORQ 0.05 versus 0.5

      furthermore you have obviously not tried to
        achieve best possible similarity of these
        two description, because I see quite some more
        unneccessairy but distracting differences.

    Robert

     
  • Amal Banerjee

    Amal Banerjee - 2012-11-30

    I admit/understand that when I was experimenting with
    both the non-subcircuit and subcircuit versions of the
    design, some parameters got changed.
    However, the thing that has puzzled me, and I do not
    have an answer why the output should fundamentally
    change when I go from the non subcircuit form to the
    subcircuit form.
    For example, given that a simple brushed DC motor
    is being analysed, the non-subcircuit version correctly
    shows the upward and downward going spikes in the
    armature current when connection via the commutator
    changes. OTOH, the sub0circuit version shows very
    small(magnitude) downward going current spikes
    ONLY. Also, in this case, the other current is totally
    zero, unlike the case of the non-subcircuit design.
    As this is a DC motor design, the current spikes
    are expected to be high, e.g., 30 - 40 Ampere
    range.
     
    spikes.  

     
  • Robert Larice

    Robert Larice - 2012-11-30

    dakuu,

       not only the parameters differ.
       the connectivity of the two circuits differs as well.
       vsens is dangling free in mid air,
         and the integrator is shorted with another node in the network.

    Robert

     
  • marcel hendrix

    marcel hendrix - 2012-12-01

    To get equal results, the subcircuit should be modified (2 values changed, some nodes renamed) as follows:

    * SUB CIRCUIT FORM - MOTOR

    *SIMPLE BRUSHED DC MOTOR

    .SUBCKT SIMBRDCMOT 1
    * 1 VIN
    * MOTOR VOLTAGE
    RARM 1 4 0.5
    LARM 4 5 0.0015
    H_EMF 5 6 VSENSE2 0.05
    VSENSE1 6 0 DC 0.0 AC 0.0
    *MOTOR TORQUE - INERTIA/FRICTION
    H_TORQ 7 0 VSENSE1 0.05
    L0 7 8 0.00025
    R0 8 9 0.0001
    VSENSE2 9 0 DC 0.0
    *MOTOR POSITION
    F_POS 0 11 VSENSE2 1
    C_POS 11 0 1.0
    R_POS 11 0 1.0MEG
    .ENDS

    V_AMP 1 0 DC 0.0 AC 1 PWL(0MS 0V 5MS 5V 10MS 20V  1000MS 20V  1010MS 5V 1020MS 0V 1050MS 0V 1060MS 5V 1070MS 20V 2000MS 20V 2010MS 5V 2020MS 0V 2050MS 0V 2060MS 5V 2070MS 20V 3050MS 20V 3060MS 5V 3070MS 0V)
    XMOT 1 SIMBRDCMOT

    * ANALYSIS
    .OPTIONS METHOD=GEAR
    .IC
    *.PROBE V(*)
    .TRAN 100ms 3100ms 50ms UIC
    .PRINT TRAN I(v.xmot.vsense1) I(v.xmot.vsense2)
    .END

    -marcel

     
  • Amal Banerjee

    Amal Banerjee - 2012-12-04

    Thank you very much for the modifications.
    They work just fine.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks