LTSpice-Assign a voltage source variable as a node voltage in subcircuit

Thread Starter

M0Kamel

Joined May 16, 2022
3
Hello,
I would like to generate a signal within the subcircuit using the PWL command. One of the input variables is going to continuously change in the simulation. So, I am using an input "Vin" just to pass this information to the subcircuit. I wanted to generate a PWL command, where the voltage & time variables are needed. Is it possible to pass the node voltage as a variable using ".Param" command? Something like what I am showing in the picture? It does not work, so I am wondering if you have ideas or workarounds.

Capture.PNG
 

Attachments

Papabravo

Joined Feb 24, 2006
21,159
Here is the problem. All parameters and expressions that involve parameters are computed before the simulation begins. This means that you cannot have an expression that involves paramters that change during a simulation. The subcircuit can use the voltage at the input pin. Remember to guard against division by 0 in any expression; that is a surefire way to blow things up.
 

Thread Starter

M0Kamel

Joined May 16, 2022
3
Thanks a lot @Papabravo for your quick response. I did not know that at all. Is there a workaround to use the PWL variable dynamically then? Or at least the same function?
 

atferrari

Joined Jan 6, 2004
4,764
What about creating a PWL containing ALL your required variations in sequence?

My ex & her mother proved that I'am always wrong. Be aware.
 
Last edited:

Papabravo

Joined Feb 24, 2006
21,159
Thanks a lot @Papabravo for your quick response. I did not know that at all. Is there a workaround to use the PWL variable dynamically then? Or at least the same function?
I'm not sure exactly what you are trying to do, but you can use a PWL source in conjunction with a behavioral voltage source to do what I think you were attempting. As I mentioned earlier, you do have to avoid the divide by 0 problem. Certainly you can make a VCO from a behavioral voltage source.
 

eetech00

Joined Jun 8, 2013
3,859
Hello,
I would like to generate a signal within the subcircuit using the PWL command. One of the input variables is going to continuously change in the simulation. So, I am using an input "Vin" just to pass this information to the subcircuit. I wanted to generate a PWL command, where the voltage & time variables are needed. Is it possible to pass the node voltage as a variable using ".Param" command? Something like what I am showing in the picture? It does not work, so I am wondering if you have ideas or workarounds.
Your example is "out".
My solution is "ramp".
You can see the output is the same, but "ramp can be controlled using a dynamically changing voltage source (shown as v(freq) if desired.
1652973925769.png
 

Papabravo

Joined Feb 24, 2006
21,159
You can also use the "Modulate" special function to build a VCO. Here is the relevant hep page description:

A. Special Functions
The MODULATE device is a voltage controlled oscillator. See the example schematic .\examples\Educational\PLL.asc. The instantaneous oscillation frequency is set by the voltage on the FM input. The conversion from voltage to frequency is linear and set by the two instance parameters, mark and space. Mark is the frequency when the FM input is at 1V and space is the frequency when the input is at 0V. The amplitude is set by the voltage on the AM input and defaults to 1V if that input is unused(connected to the MODULATE common).


Here is an example of the usage. The FM input will smoothly interpolate between two frequencies defined by the parameters SPACE and MARK. The AM input will control the output voltage.

1652977165142.png

If you want a square wave output you can use a comparator with an adjustable threshold and offset to convert the sine wave to a square wave.
 
Top