2 mosfet circuit not simualting as expected (I'm new)

Thread Starter

bmbouter

Joined May 29, 2021
75
Hi all, I'm attempting to model this Fig 1 circuit. I've attached a diagram of my kicad model (so I'll use the built in ngspice modeling). I'm attempting to just model what happens just after the power is applied, so the switch isn't involved and is not modeled. The circuit has a jumper in it and I've modeled it both ways; I've attached images of both of those.

As suggested by the website with the original circuit diagram (at the bottom), I've configured the PMOS as a IRF7317P and the NMOS as an IRF7317N and I've using those spice models from the manufacturer. I've taken care to ensure those models match the pins of the schematic. I'm using a 1N4002RL for the diode (I'm not sure how to check the pin order of this). See the zip file attached which has the whole kicad project including these simulation libraries.

When I run the simulation and measure V(/POUT) I expect it to be reach a steady state of 4.2V in the auto_on schematic and 0V in the auto_off schematic, but in both cases it converges to 4.2V. As you can see from the labels I'm using the transient analysis with a variety of initial conditions set. I also tried a piecewise-linear DC model which applies 4.2V at 100ms and it also shows V(/POUT) converge to 4.2V.

I really don't know what I'm doing with the initial conditions section. With each one I set, I get very different results. What would you do for the initial conditions?

An ideas why this doesn't model the way the description on the reference page suggests it should?

Do you expect the auto_on schematic to converge at 4.2V? A bit of explanation of what you expect the auto_off to do just after power is applied from someone more experienced would be really nice.

Any advice, or questions is welcome. Thank you!
 

Attachments

Last edited:

Thread Starter

bmbouter

Joined May 29, 2021
75
hi bmb,
Please post your LTS asc file.
E
Super noob here. Is this what you want? Also added a zip file to the original post that has the lib files.

.title KiCad schematic
.include "/home/bmbouter/kicad/simulation_learning/press_on_hold_off/1N4002RL.LIB"
.include "/home/bmbouter/kicad/simulation_learning/press_on_hold_off/irf7317n.spi"
.include "/home/bmbouter/kicad/simulation_learning/press_on_hold_off/irf7317p.spi"
R1 /VC2 /VC1 10k
C1 /VC1 /VC4 1uF
R2 /VC2 /VC4 100k
V1 /VC2 0 dc 4.2
C2 /VC2 /VC4 0.1uF
XQ1 /POUT /VC4 /VC2 irf7317p
R4 /POUT Net-_D1-Pad1_ 100k
C3 /VC5 /POUT 10uF
XQ2 /VC4 /VC5 0 irf7317n
D1 Net-_D1-Pad1_ /VC1 D1n4002rl
R3 /VC5 Net-_D1-Pad1_ 300k
.save @r1
.save @c1
.save @r2
.save @v1
.save @c2
.save @r4
.save @c3
.save @d1[id]
.save @r3
.save V(/POUT)
.save V(/VC1)
.save V(/VC2)
.save V(/VC4)
.save V(/VC5)
.save V(Net-_D1-Pad1_)
.ic V(/VC1)=0
.ic V(/VC2)=0
.ic V(/VC3)=0
.ic V(/VC4)=0
.ic V(/VC5)=0
.tran 1us 100ms

.end
 

dcbingaman

Joined Jun 30, 2021
1,065
Hi all, I'm attempting to model this Fig 1 circuit. I've attached a diagram of my kicad model (so I'll use the built in ngspice modeling). I'm attempting to just model what happens just after the power is applied, so the switch isn't involved and is not modeled. The circuit has a jumper in it and I've modeled it both ways; I've attached images of both of those.

As suggested by the website with the original circuit diagram (at the bottom), I've configured the PMOS as a IRF7317P and the NMOS as an IRF7317N and I've using those spice models from the manufacturer. I've taken care to ensure those models match the pins of the schematic. I'm using a 1N4002RL for the diode (I'm not sure how to check the pin order of this). See the zip file attached which has the whole kicad project including these simulation libraries.

When I run the simulation and measure V(/POUT) I expect it to be reach a steady state of 4.2V in the auto_on schematic and 0V in the auto_off schematic, but in both cases it converges to 4.2V. As you can see from the labels I'm using the transient analysis with a variety of initial conditions set. I also tried a piecewise-linear DC model which applies 4.2V at 100ms and it also shows V(/POUT) converge to 4.2V.

I really don't know what I'm doing with the initial conditions section. With each one I set, I get very different results. What would you do for the initial conditions?

An ideas why this doesn't model the way the description on the reference page suggests it should?

Do you expect the auto_on schematic to converge at 4.2V? A bit of explanation of what you expect the auto_off to do just after power is applied from someone more experienced would be really nice.

Any advice, or questions is welcome. Thank you!
Current through Q1 has no path back to the voltage source. It appears there is at least one or more places that need to have a path back to the supply voltage for the circuit.

Per your link:

1662403782277.png

Add missing wire or Normally Open button as shown here:

1662404119193.png
 
Last edited:

dcbingaman

Joined Jun 30, 2021
1,065
Here is an LTSpice of the circuit, if you are interested. Along with the schematic:

1662407138620.png

Notes:

The normally open on/off push button is replaced with M3 and V2 to simulate button pushes.
The left side of C2 can be grounded for 'Auto-On' operation.
The left side of C2 can be connected to the 4V supply for 'Auto-Off' operation.

Basic operation:
In Auto-On Mode. switch open
- C2 starts to charge up via R1 and R2 this turn on M1
- M2 turns on via R3 and R4 and stays on, this latches M1 on.
- C2 discharges, we stay in the on state until the button is pressed
- When 'button' (M3) turns on, D1 turns on allowing C3 to start charging
- When C3 has charged up enough, the voltage across R3 drops to within 1 diode drop of ground
- This turns of M2, allows C2 to charge up and turns off M1
- The circuit remains off

It appears the primary time constant for this circuit is via C3, R3 and R4 and is a few seconds from the simulation.
 

Attachments

dcbingaman

Joined Jun 30, 2021
1,065
I have KiCad installed and use it for Schematic/PCB board design. I never tried using the Spice capabilities? Maybe you can tell me a little more about KiCad's spice abilities? Do you have to load special 'additional software' etc?
 

Thread Starter

bmbouter

Joined May 29, 2021
75
Thank you all for the replies. I've added the 100Ω load to the output, which did cause V(/POUT) to converge to 0, but something still isn't right because now the auto-on feature also only produces a 0 output. When I modify the .ic statements it then shows it only turning on, so I believe I'm not using the .ic statements correctly.

I think I'm going to try LTSpice as I've noticed many more folks here are using it, instead of the ngspice which comes built-in for kicad. With kicad 5+ (I use 6) you can use simulation without any additional software as it vendors ngspice with it. I followed videos like this for example, which also point out the importance of the .ic statements. One of the reasons I've avoiding LTspice is that I don't think it's natively available for linux, but I can figure out how to run it with wine.

@dcbingaman thanks for sharing the LTspice version of this. It seems that is working correctly. I read the .asc file and I had a few questions:

1) Did you have to specify any initial conditions at all?
2) How did you load the component types, e.g. Si7336ADP into your model? Is it just in the inventory already somehow?

The modeling of the NO switch to ground in the way you have is a nice solution too. Thanks for that and the explanation, those both make sense!
 

dcbingaman

Joined Jun 30, 2021
1,065
Thank you all for the replies. I've added the 100Ω load to the output, which did cause V(/POUT) to converge to 0, but something still isn't right because now the auto-on feature also only produces a 0 output. When I modify the .ic statements it then shows it only turning on, so I believe I'm not using the .ic statements correctly.

I think I'm going to try LTSpice as I've noticed many more folks here are using it, instead of the ngspice which comes built-in for kicad. With kicad 5+ (I use 6) you can use simulation without any additional software as it vendors ngspice with it. I followed videos like this for example, which also point out the importance of the .ic statements. One of the reasons I've avoiding LTspice is that I don't think it's natively available for linux, but I can figure out how to run it with wine.

@dcbingaman thanks for sharing the LTspice version of this. It seems that is working correctly. I read the .asc file and I had a few questions:

1) Did you have to specify any initial conditions at all?
2) How did you load the component types, e.g. Si7336ADP into your model? Is it just in the inventory already somehow?

The modeling of the NO switch to ground in the way you have is a nice solution too. Thanks for that and the explanation, those both make sense!
For LTSpice, you do not have to specify initial conditions. I sometimes check this option:

1662497879449.png
That is Start external DC Supply voltage at 0V. But I have found it works fine with the default using Transient mode.
I typically just use the basics of LTSpice. There is a lot of people on this forum that use the more advanced features. I usually just use the basic features. All of the components I choose where in the library. The easiest way to say add a PMOS is to first add the generic PMOS, right click it and then you can select one from the default LTSpice libraries. I choose the PMOS and NMOS at random for this application, one that basically meets the power and current requirements. If you want to add a new part you may ask for some help on this forum. There is a lot of experts on this forum that understand how to do that.

To select any standard parts use this tool bar:

1662498185901.png

The And gate is for IC chips, transistors, etc. The others have pretty much what the pictures show.

Hope that helps and thanks for the info on KiCad spice. The one thing nice about KiCad; you don't have to learn another schematic drawing tool. One size fits for sim/schematic and layout. But I still like LTSpice for quick and simple simulations, it is very easy to use. Again thanks for the info on KiCad simulations. I probably should install 6.0. I currently have 5.1 installed.
 

Thread Starter

bmbouter

Joined May 29, 2021
75
I got LTSpice running and it's output is just as the website with the original schematic predicted. All aspects of this work very well. LTSpice is a wonderful tool, and I'm going to continue with that for my simulations. Thank you for teaching me! This is great!
 
Top