# Need help with simulation

Discussion in 'Electronic Basics' started by bench, May 8, 2004.

1. ### benchGuest

Hi everyone,

I am having trouble simulating an astable multivibrator and
I was wondering if anyone can help me. I am using
a package called Circuit Maker 6 and the circuit has
the file http://www.geocities.com/benchdocs/astable.CKT.txt
; rename it without the .txt extension (as it is a .ckt file) and
see if you can get it to oscillate. I am not sure what is wrong
with the circuit, maybee the resistors or capacitors have been
assigned wrong values. I initially used generic npn transistors,
but then I tried the 2n2222, but nothing seems to help.
tia.

2. ### Terry PinnellGuest

You need to add a .IC (Initial Conditions) device/command to at least
one of the capacitors, to get oscillation started. I've shown it here,

http://www.terrypin.dial.pipex.com/Images/MultivibratorCM6.gif

3. ### Robert C MonsenGuest

CM6 has an example circuit which is almost exactly the circuit you
posted... Look for 'Astable.ckt' amongst the examples.

With regards to your circuit, your timing values are pretty big. If
3.5Hz, which would be much too slow to see with the simulation values
you have set. Also, you may need initial conditions for some of the
nodes to get the oscillation going in the first place. I got your
circuit going by changing the cap values to C1=500pF and C2=1nF,
R2=R3=47k, and putting initial conditions on the collectors of the
transistors as 0V (on the left) and 9V (on the right). Also, go to the
transient setup, and change the stop time to 500us, and the step time
and max step to 1us.

the oscillator.

The oscillation frequency is near -ln(.5) * (R1*C1 + R2*C2). Thats
because the fall in the collector on one side (when the transitor
turns on) drags the base of the other side down 9V through the
capacitor, so it has to increase back to 0.7 to turn on again. It does
this by charging through the cap/resistor pair. The equation governing
the time of recharge of a cap C through a resistor R can be shown to
be

Vx -Vs = (Vt - Vs) exp(-t/RC)

Where Vs is the starting voltage, Vx is the 'target' voltage, Vt is
the voltage at the other side of the resistor, t is the time required,
and R and C are of course the values for those components. Since the
voltage is dragged down from 0.7 to -8.3, and has to climb back up to
0.7 again to turn on the transistor and complete that part of the
cycle, you have

Vs = -8.3V
Vx - Vs = 0.7 - (-8.3) = 9
Vt - Vs = 9 - (-8.3) = 17.3V
C1 = 500pF, R2 = 47k
C2 = 1nF, R3 = 47k

So (solving the above for t, and noting that there are two RC
oscillators going, one after the other...)

t = -ln(9/17.3) * (500pF * 47k + 1nF * 47k)
= 0.653 * (70.5u)
= 46u

Therefore, the frequency of the oscillator with the values given above
is

f = 1/46u = 21kHz

This matches pretty well with the simulated value, which is around
20kHz. It doesn't match exactly, because the Vs above isn't
really -8.3; its something a bit less negative, because of various
effects, so it doesn't go down 9V, more like 7.5V... We could take
that into account, but these values are close enough, given that the
caps and resistors you'll use are probably 5% to 10% tolerance.

By the equations above, its easy to see that you can control the 'duty
cycle' of the oscillator by simply changing cap or resistor values. By
keeping the sum constant, the frequency will be kept constant.

Regards,
Bob Monsen

4. ### Robert C MonsenGuest

You beat me, Terry... Actually, I found that it oscillates without the
initial condition. I guess circuitmaker is putting in some randomness
to get things started.

The OPs problem was the time scale of his simulation. The default of
5us won't show much change. However, if you scope the collectors of
both transistors, you see divergence almost immediately.

One thing I found really interesting was zooming in on the startup of
this circuit. If you set the transient parameters to a stop time of
10ms, and scope the collectors, you see the startup quite clearly.

Regards,
Bob Monsen

5. ### Terry PinnellGuest

I should have added that, although the circuit I used was unchanged, I
too immediately changed the time scale from the default to 1 s, as you
see from the screenshot.

That also roughly shows the interesting startup effect you mentioned.

6. ### benchGuest

My waveform is for some reason a bit erratic comapared
to your results, here is my snapshot.
http://www.geocities.com/benchdocs/ast-sim.jpg
I took a 10 seconds range because the waveform seems to
change and 10 seconds are required to see this.
My simulation step is 20mS and max
step is 200mS (not sure what this max value is for).
B.t.w. thanks for all the formulas, I shall have
a look at them after I can sort this issue first.

7. ### Robert C MonsenGuest

50ms is much too big. Doing this kind of numerical integration is
approximate, and so errors creep in after a bit. In a real system,
this won't happen.

If you decrease the timestep and max to 100u/100u, you will get better
results.

Regards,
Bob Monsen

8. ### Terry PinnellGuest

That's the reason for your strange results. Nothing changes much after
about 50 ms. That's why I used a Stop Time of 1 s. Certainly no need
for 10 s! And my choice for Step and Max. Step of 1 ms wasn't
arbitrary.
From CM6 Help (which I suggest you study):
"Step Time is the suggested computing increment, but the timestep will
be varied automatically by XSpice in order to properly converge. Max.
Step limits the varying size of the timestep that XSpice can use when
calculating the transient data; by default, the program chooses either
Step Time or (Stop Time - Start Time)/50, whichever is smaller.
Typically, Step Time and Max. Step would be the same value."

Robert: Following your post, I too subsequently re-ran it OK *without*
the .IC command. Not entirely sure why that didn't appear to work
first time I tried. May have been my carelessness. But I do recall
oscillators like this needing an initial condition. 555 astables seem
particularly fussy!

9. ### Robert C MonsenGuest

If you look at the sample (Astable.ckt) it has a note describing the
usage of .IC. It even works when everything is equal (like in the OP's
circuit.) I've had this kind of thing fail in other spices before, but
circuitmaker seems to be ok with it. They appear to factor in some
thermal noise which gets things going properly.

Regards

10. ### benchGuest

Thanks to all !!!!!!!