2
\$\begingroup\$

I am trying to simulate a load in two different instances. In first instance i want the load to have a constant dc value of 2A, and in the second instance PULSE(2 11 1.06 100n 100n 0.30 0.8 1). I know that using the command .step param X 1 2 1, i would be able to run the simulation twice. I want to know how to write the command to run both the load instances..

schematic

simulate this circuit – Schematic created using CircuitLab

\$\endgroup\$
0
\$\begingroup\$

Noting a 0A current source doesn't do anything as load, a more elegant (but harder to read) solution would be using variable IT (which stands for iteration) using .step param IT list 1 2 3 and use conditions to set the current to non-zero for the iteration it should be activated.
So,if in iteration 3 the value should be 2A and 0A otherwise, use: if(IT<3,0,if(IT>3,0,2))}

Example
in iteration 1, the current source should behave like
PULSE(2 11 1 100n Tfall Ton Tperiod Ncycles)
and in iteration 2 current source should behave like (a 2A DC source)
2
and in iteration 3, current source should behave like
SINE(2 1 10)

you could do the following:

enter image description here

where current source I1 is activated in iteration 1, current source I2 is activated in iteration 2 and current source I3 is activated in iteration 3.

I1: PULSE({if(IT<1,0,if(IT>1,0,4))} {if(IT<1,0,if(IT>1,0,11))} 1.06 100n 100n 0.30 0.8 1)
I2: {if(IT<2,0,if(IT>2,0,2))}
I3: SINE({if(IT<3,0,if(IT>3,0,2))} {if(IT>3,0,if(IT>3,0,1))} 10)

\$\endgroup\$
1
\$\begingroup\$

The problem with spice is it doesn't work this way, there isn't a good way to change text statements from simulation to simulation (that I know of anyway, I would love for someone to prove me wrong, as it would make my life a little simpler)

There is a way this can be done, is it elegant? Heck no. If you really want to change the way a source behaves, a b-source is the way this is to be done, you can use if statements in b-source blocks.

You create a parameter that defines the simulation, in this case sim is -1 for the first run and 1 for the second.

So you say, if first simulation, use a constant 2A (or whatever), on the second simulation, use a different value for current.

The problem is, you can't insert a PWL statement in an if statement.

I=if(sim>0,2,PWL(0 5 2 0)) <= does not work

but you can insert a different time varying node (either a voltage or current)

I=if(sim>0,2,V(node))

So then you create a voltage pwl and use it's node as the varying current for the second simulation

And there you have it (as pictured below), the red line is the constant 2A (through the R3 resistor) and the pink from the varying PWL in two simulations. You could do this for more than two simulations with nested if statements

enter image description here

I thought about using variable resistors with if statements, but this will not work with current sources, as they can still source current through any amount of resistance. An approach below would work with voltage sources however.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ You should change R3 to 100 ohm, I think. \$\endgroup\$
    – Huisman
    Oct 11 '19 at 18:45
0
\$\begingroup\$

Since both loads start at the same current, you can manipulate this by using a huge time delay for the load of 2A.

Change the value of I1 to:
PULSE(2 11 {Tdelay} 100n 100n 0.30 0.8 1)

and use

.step param Tdelay LIST 1.06 10G

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ I want to run both the load conditions independently in different iteration! \$\endgroup\$
    – seeker
    Oct 11 '19 at 18:48
  • \$\begingroup\$ @seeker I think it does exactly that. It does 1 simulation with 2 iterations (paramter steps): first iteration (parameter step 1) I1 = PULSE(2 11 1.06 100n 100n 0.30 0.8 1) , second iteration (parameter step 2) source I1=2A for about 10G seconds (ok, and then (316 years later), it starts pulsing...) \$\endgroup\$
    – Huisman
    Oct 11 '19 at 18:56
  • \$\begingroup\$ @seeker If I'm misunderstanding and you don't want 1 simulation with 2 instances/iterations, could you please give an example what you want instead? \$\endgroup\$
    – Huisman
    Oct 11 '19 at 19:08
0
\$\begingroup\$

You can simply step one parameter in the same PULSE source. You have PULSE (2 11 ...), so simply assign it like this: PULSE (2 {x} ...), and step x to have the values 2 and 11. If the values for Vinitial and Von in the PULSE() source are equal, the source outputs a continuous value.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.