Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LTSpice - Use Resistor value in plot expression?

Status
Not open for further replies.

eTech

Well-Known Member
I have a user defined variable statement in my schematic:

.param R = 10

I use this variable to set a resistor value for resistor R1.

R1
vs--|---|--Gnd
{R}

The variable works as expected in the schematic. Now I want to reference this
variable in a plot expression.

I tried this:

V(vs)/R1(R)

and this

V(vs)/R1{R}

But it does not work.

Can anyone explain how to reference a user defined variable in a plot
expression?


Thanks
 
How about this?


The independent variable is R1. Two Dependent expressions are plotted. One is current thru R1; the other is the Resistance of R1 (R=E/I). Note that LTSpice knows what you are plotting, and it labels the plot axis automatically.

This feature in LTSpice is called a "Plot Expression".
 

Attachments

  • D2.jpg
    D2.jpg
    111 KB · Views: 2,069
Last edited:
If you need to make a resistor vary during simulation, you can do this:



Here R2 is set to 2*R1 during the simulation run. R1 is the independent variable of the simulation. R2 is determined as a function of the voltage and current through R1. The plots show that the (dependent) current through R2 is one-half of the current through R1.

Plotting the expression I(R2)/I(R1) shows that it is 0.5 (500m) for all values of R1 and R2.
 

Attachments

  • D2a.jpg
    D2a.jpg
    166.3 KB · Views: 1,957
Last edited:
Wow...thats pretty cool Mike!

My question probably wasn't very clear. But I found out later that I had to create functions in the polt.def file to get the plot I wanted.
My problem was...I couldn't use a resistor variable directly in a plot expression. I kept getting a error "undefined param" or something
like that.

I was exploring the use of a PGIA with different gain resistor values set by a analog switch.
What I needed was a plot showing the effect of different values of resistors with certain analog switch contacts.

By adding these functions in the plot.def file:

.func R1ohms() {V(vref)/I(R2)}
.func Ron() (V(Vno_h)-(R1ohms()*I(R1)))/I(R1)

and adding a .param RX = {10k} statement on the schematic, I was able to add a plot expression defined simply as Ron()

Thanks for your help..

eT
 
That's a solution I haven't used before. My way just requires you to "do it on the fly" by adding a trace to a plot pane containing the term ((V2-V1)/I12), where V2 and V1 are the voltages at the ends of the "resistor", and I12 is the current through the "resistor". Those node voltages and branch currents exist in the .RAW file by default. My method can be done after the sim run.

Your way actually adds a new column of data to the .RAW file. It must be done before the sim run.
 
Last edited:
That's a solution I haven't used before. My way just requires you to "do it on the fly" by adding a trace to a plot pane containing the term ((V2-V1)/I12), where V2 and V1 are the voltages at the ends of the "resistor", and I12 is the current through the "resistor". Those node voltages and branch currents exist in the .WAV file by default. My method can be done after the sim run.

Your way actually adds a new column of data to the .WAV file. It must be done before the sim run.

Yup..
Here's the asc file.

I couldn't upload the .raw file. The site says "invalid file".
 

Attachments

  • ADG1211-RonTest.asc
    2.9 KB · Views: 618
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top