Friday, June 19, 2009

SPICE: Part 2

<< [Part 1 2 3 4 5] >>

Last we left off, I wanted to use SPICE to model my fan driver circuit and help me find ways to improve it. The motor was intended to run on 9V but the Orangutan LV168 driving it was only delivering a 5V logic high signal. The circuit I threw together at the last minute only delivered a fraction of the 9V supply voltage to the motor.

Here's the circuit diagram, drafted in CadSoft Eagle on the Mac. I've edited it with a graphic editor to add a couple of SPICE elements and node label numbers (in green) to each of the nodes to make it easy to create the SPICE file.

Also, adding onto what we talked about in the first article, Part 1, our new SPICE model will include three new circuit elements we haven't talked about yet.
  • BJT transistors and transistor models (Q1, Q2)
  • A special "pulse" voltage supply (VR) to simulate 5V signal pulses from the MCU
  • A zero-volt power supply (VM) used to measure current through the "motor"
Transistors and Models

First let's talk about transistors and models. Using SPICE you can model semiconductors--diodes and transistors--of various types, the properties of which you specify in a model statement. These models are usually available from manufacturers as well as online for more common parts.

In the diagram you can see I am using an 2N2222A and a TIP3055 transistor. I searched the web and found a model for a 2N2222 (close enough; we could try to find a 2222A if we really needed to) and the TIP3055. Here they are. The "+" character is a line continuation so you can put the model statements on more than one line.

.model 2n2222 npn (is=19f bf=150 vaf=100 ikf=0.18 ise=50p
+ ne=2.5 br=7.5 var=6.4 ikr=12m isc=8.7p nc=1.2 rb=50 re=0.4
+ rc=0.3 cje=26p tf=0.5n cjc=11p tr=7n xtb=1.5 kf=0.032f af=1)

*.model TIP3055 ako:NSC_4A NPN() ; case TO-220 (s)
.MODEL TIP3055 NPN(Is=457.5f Xti=3 Eg=1.11 Vaf=50 Bf=156.7 Ise=1.346p Ne=1.34
+ Ikf=3.296 Nk=.5961 Xtb=2.2 Br=7.639 Isc=604.1f Nc=2.168
+ Ikr=8.131m Rc=91.29m Cjc=278.7p Mjc=.385 Vjc=.75 Fc=.5 Cje=433p
+ Mje=.5 Vje=.75 Tr=1.412u Tf=37.34n Itf=35.68 Xtf=1.163 Vtf=10
+ Rb=.1)


(For whatever reason, MacSpice didn't recognize the Nk parameter, in red above, and ignored it). When you add a BJT circuit element, you specify it as:
     Qname NC NB NE Mname
where Qname is the name of the transistor (Q1, Q2, QA, etc), NC is the Collector node, NB is the Base node, and NE is the Emitter node. Mname is the model name, like TIP3055 if you're using that model from above.

You can model BJTs, either NPNs or PNPs. You can model other transistors too. MacSpice lets you specify a number of BJT parameters in your model, such as:
  • BF: Ideal maximum forward beta
  • VAF: Forward early voltage
  • ISE: B-E leakage saturation current
  • NE: B-E leakage emission coefficient
  • RB: Zero bias base resistance
  • RE: Emitter resistance
  • RC: Collector resistance
  • TF: Ideal forward transit time
  • And much more...
A complete list of parameters for transistors and diodes can be found in the MacSpice (or any SPICE) user guide. That way, if you cannot find a SPICE model ready-made to cut-n-paste for your transistor, but you can find these parameters in the data sheet, you can create a model from scratch. But probably most of the time you will just use a model already created for a standard component that you're using.

Measuring Current

Now, as to the two new voltage supplies, the easy one is the 0V supply. In SPICE the only way to measure current is at/with a voltage supply; you cannot measure it through a resistor, for example. When I say measure, what I really mean is to have SPICE print or plot the values. We'll get into how to do that shortly.

Simulating MCU Signals

SPICE provides a PULSE type of voltage supply that allows you to specify a supply that has repeating output pulses. You do this by using the PULSE parameter when describing the value of a voltage supply:
     VIN 3 0 PULSE(-1 1 2NS 2NS 2NS 50NS 100NS)
The first two values are the initial and pulsed (high) values of the supply. In our case the LV168 spits out 5V signals so I used 0.0 and 5.0 here.

The next two parameters specify the rise and fall time of the pulse. I could go look that up but for now I just used 1 nanosecond, specified as 1ns.

The final two parameters are the pulse width and the period. I arbitrarily picked 100ms for the pulse width and doubled that for the period to get a nice square wave output. Depending on how the simulation looks I may extend that time.

The SPICE Deck So Far

SPICE files containing circuit specifications are called "decks". Anyway, once you enter in the transistors and voltage supplies, in addition to the resistors and capacitors, here's what you have so far.

Crappy fan motor driver
* Fan power supply
V1 1 0 9.0
* Simulates MCU FAN_ENABLE signal
VR 5 0 PULSE( 0.0 5.0 5ms 1ns 1ns 100ms 200ms )
* 0 volt for measuring motor current
VM 2 6 0
Q1 1 4 3 2N2222
Q2 1 3 2 TIP3055
RM 6 0 2
C1 1 0 100U
R1 5 4 47
* model for a 2n2222 transistor
.model 2n2222 npn (is=19f bf=150 vaf=100 ikf=0.18 ise=50p
+ ne=2.5 br=7.5 var=6.4 ikr=12m isc=8.7p nc=1.2 rb=50 re=0.4
+ rc=0.3 cje=26p tf=0.5n cjc=11p tr=7n xtb=1.5 kf=0.032f af=1)
*.model TIP3055 ako:NSC_4A NPN() ; case TO-220 (s)
.MODEL TIP3055 NPN(Is=457.5f Xti=3 Eg=1.11 Vaf=50 Bf=156.7 Ise=1.346p Ne=1.34
+ Ikf=3.296 Nk=.5961 Xtb=2.2 Br=7.639 Isc=604.1f Nc=2.168
+ Ikr=8.131m Rc=91.29m Cjc=278.7p Mjc=.385 Vjc=.75 Fc=.5 Cje=433p
+ Mje=.5 Vje=.75 Tr=1.412u Tf=37.34n Itf=35.68 Xtf=1.163 Vtf=10
+ Rb=.1)

Transient and Operating Point Analysis

Now that we have a circuit to analyze, how do we analyze it? I mentioned last time that you can do Operating Point (steady state) analysis or you can do Transient analysis. You can print out voltage and current values, or you can plot them graphically.

At the end of the deck, you can tell SPICE what to do with the circuit. Use the command .OP for operating point analysis or the .TRAN command for transient analysis. For transient analysis you specify, at a minimum, the time step (TSTEP) and stop time (TSTOP) parameters, like .TRAN 100ms 1000ms for a 100ms step time stopping after 1 second.

To get SPICE to plot the results graphically when you load the file, your deck needs to include interactive controls, bracketed by .CONTROL and .ENDC statements. In our case we want to plot the voltage at node 2 and the current through our 0V measurement supply VM:

.control
plot v(2) i(vm)
.endc

The Finished Deck

Finally every deck should have a .END statement at the ... well... end. Putting it all together, here is our deck for the crappy fan motor driver.

Crappy fan motor driver
* Fan power supply
V1 1 0 9.0
* Simulates MCU FAN_ENABLE signal
VR 5 0 PULSE( 0.0 5.0 5ms 1ns 1ns 100ms 200ms )
* 0 volt for measuring motor current
VM 2 6 0
Q1 1 4 3 2N2222
Q2 1 3 2 TIP3055
RM 6 0 2
C1 1 0 100U
R1 5 4 47
* model for a 2n2222 transistor
.model 2n2222 npn (is=19f bf=150 vaf=100 ikf=0.18 ise=50p
+ ne=2.5 br=7.5 var=6.4 ikr=12m isc=8.7p nc=1.2 rb=50 re=0.4
+ rc=0.3 cje=26p tf=0.5n cjc=11p tr=7n xtb=1.5 kf=0.032f af=1)
*.model TIP3055 ako:NSC_4A NPN() ; case TO-220 (s)
.MODEL TIP3055 NPN(Is=457.5f Xti=3 Eg=1.11 Vaf=50 Bf=156.7 Ise=1.346p Ne=1.34
+ Ikf=3.296 Xtb=2.2 Br=7.639 Isc=604.1f Nc=2.168
+ Ikr=8.131m Rc=91.29m Cjc=278.7p Mjc=.385 Vjc=.75 Fc=.5 Cje=433p
+ Mje=.5 Vje=.75 Tr=1.412u Tf=37.34n Itf=35.68 Xtf=1.163 Vtf=10
+ Rb=.1)
.tran 10ms 1000ms
.control
plot v(2) i(vm)
.endc
.end

The Results!

And here is the graphical plot, showing the motor is only seeing 3.5V (red) and drawing a little over 1.5A (green). Remember that we are just representing the motor with a resistor, 2Ω in this case. We'll add a more complex, realistic motor model soon.

Next time I'll see if I can't use modeling to help improve upon the original design. We can try a few things in SPICE without having to breadboard them first.

<< [Part 1 2 3 4 5] >>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.