Comparator with hysteresis

Papabravo

Joined Feb 24, 2006
22,083
Marvellous! Got all the parameters in the right place, and now it's been sat there doing N-R iterations and fill-ins for the last half hour.
In the help pages it is documented that the SCHMITT devices do not have any time information associated with them. The parameter "tripdt" is used to specify the largest amount of time across a state change. Something like tripdt=10n means that all state changes must happen within a 10 nsec window. That is there must be a pair of timesteps, with a Δt of 10 ns or less, on either side of the state change. The value you choose for tripdt, should consider clock frequency along with rise and fall times. This may or may not be the last problem you could encounter.

A. Special functions.
The gates and Schmitt trigger devices supply no timestep information to the simulation engine by default. That is, they don't look when they are about to change state and make sure there's a timestep close to either side of the state change. The instance parameter tripdt can be set to stipulate a maximum timestep size the simulator takes across state changes.
 
Last edited:

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
In the help pages it is documented that the SCHMITT devices do not have any time information associated with them. The parameter "tripdt" is used to specify the largest amount of time across a state change. Something like tripdt=10n means that all state changes must happen within a 10 nsec window. That is there must be a pair of timesteps, with a Δt of 10 ns or less, on either side of the state change. This may or may not be the last problem you could encounter.

A. Special functions.
The gates and Schmitt trigger devices supply no timestep information to the simulation engine by default. That is, they don't look when they are about to change state and make sure there's a timestep close to either side of the state change. The instance parameter tripdt can be set to stipulate a maximum timestep size the simulator takes across state changes.
Still won't work with tripdt=1u
I'm beginning to wish I'd just built it - but it's for an MPPT and one doesn't get much chance to test an MPPT when it's getting dark at half past three.
 

Papabravo

Joined Feb 24, 2006
22,083
Still won't work with tripdt=1u
I'm beginning to wish I'd just built it - but it's for an MPPT and one doesn't get much chance to test an MPPT when it's getting dark at half past three.
OK. It might take a closer look at your simulation file (*.asc), and the (.ini) file you are using for your LTspice installation.
In addition if you could post the netlist generated by LTspice that would also be helpful.
 
Last edited:

Alec_t

Joined Sep 17, 2013
15,119
In past simulations using the A devices I've found that the sim will sometimes hang unless the tripdt or tau parameter in one or more devices is given a small non-zero value to fix the hang. Deciding which device(s) seems somewhat hit and miss to me (but probably not to an LTS expert), as the error log can point to the cause of a hang being a device different from the one which actually needs the fix.
 

eetech00

Joined Jun 8, 2013
4,705
I'm trying to simulate a comparator in LTSpice. I'm actually trying to simulate the comparator in an LPC15xx microcontroller. It has programmable hysteresis of 5mV, 10mV or 20mV.
Obviously, I could make the hysteresis by a feedback resistor from output to non-inverting input, but the amount of hysteresis then changes when I vary any of the other resistor values.
I'm thinking that I could put a SPICE Voltage source in series with one of the inputs, then use the state of the output to toggle the value of the voltage source between two different values, but I don't know how to do that. Could someone please help me out?
It would be better if you provided a schematic so we have context as to use of the A device.
 

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
OK. It might take a closer look at your simulation file (*.asc), and the (.ini) file you are using for your LTspice installation.
In addition if you could post the netlist generated by LTspice that would also be helpful.
Code:
D1 N016 0 Dpv
I1 0 N016 {imax}
R1 N016 N015 {Rseries}
R2 0 N015 {Rshunt}
C1 N001 0 47µ
M1 N009 N014 0 0 IPB320N20N3
D5 N009 N001 RF1501TF3S
C2 N001 N010 100µ
R10 N001 N013 50k
R11 N013 0 1K
R16 N014 N011 33
V2 N001 N010 48
V1 N002 0 15
V3 N008 0 3.5
D2 N012 N015 Dpv
I2 N015 N012 {imax}
R7 N012 N007 {Rseries}
R8 N015 N007 {Rshunt}
D3 N005 N007 Dpv
I3 N007 N005 {imax}
R12 N005 N004 {Rseries}
R13 N007 N004 {Rshunt}
D4 N003 N004 Dpv
I4 N004 N003 {imax}
R14 N003 N001 {Rseries}
R15 N004 N001 {Rshunt}
Q1 N002 N006 N011 0 BC817
Q2 0 N006 N011 0 BC807-40
A1 N008 N013 0 0 0 N006 0 0 SCHMITT vhigh=15 vlow=0 vt=1 vh=10m tau=10n
L1 N010 N009 56µ
.model D D
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.dio
.model NPN NPN
.model PNP PNP
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.bjt
.model NMOS NMOS
.model PMOS PMOS
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.mos
.model dpv d(Is={Is} 11 N={n})
.param Is=1e-11 Imax=3.3 Vmax=40 n=Vmax*38.6/log(Imax/Is) Rseries=0.5 Rshunt=1meg
.tran 0 5m 0 100n
.opt plotwinsize=0
.backanno
.end
Code:
[Recent File List]
file0=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\PVcell.asc
file1=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\SICJFET.asc
file2=Z:\home\ian\Downloads\NormalVsCascode.asc
file3=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondmos.asc
file4=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\currentmirrormos.asc
file5=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondfetvas.asc
file6=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondfetvas.asc
file7=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\lateralmosreduced.asc
file8=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240.asc
file9=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\quasicompreduced.asc
file10=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\lateralmos.asc
file11=C:\users\ian\My Documents\LTspiceXVII\Draft12.asc
file12=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240bipolarVAS.asc
file13=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240jfetinput.asc
file14=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\Draft10.asc
file15=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\inductorloadedamplifier.asc
[Options]
Solver=0
ShowCheckSum=false
WorkingDirectory=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated
SymbolSearchPath=
LibrarySearchPath=
SymbolSearchPathDisabled=false
LibrarySearchPathDisabled=false
SpicePriority=1
PlotPriority=1
LastFileTypeOpened=0
Tabstopwidth=4
grid=on
GenerateExpandedListing=false
DefaultTrtol=1
DefaultTrapIntegration=true
DefaultDoAntiTrapRinging=true
TSKbypass=false
Accept_3k4_Notation=true
NoJFETtempAdjIsr=false
SaveDeviceCurrents=true
SaveSubcircuitNodeVoltages=false
SaveSubcircuitDeviceCurrents=false
saveOneCurrentPerDevice=false
ShowSchematicGrid=false
OrthogonalDrag=false
AutoPan=true
 

eetech00

Joined Jun 8, 2013
4,705
Code:
D1 N016 0 Dpv
I1 0 N016 {imax}
R1 N016 N015 {Rseries}
R2 0 N015 {Rshunt}
C1 N001 0 47µ
M1 N009 N014 0 0 IPB320N20N3
D5 N009 N001 RF1501TF3S
C2 N001 N010 100µ
R10 N001 N013 50k
R11 N013 0 1K
R16 N014 N011 33
V2 N001 N010 48
V1 N002 0 15
V3 N008 0 3.5
D2 N012 N015 Dpv
I2 N015 N012 {imax}
R7 N012 N007 {Rseries}
R8 N015 N007 {Rshunt}
D3 N005 N007 Dpv
I3 N007 N005 {imax}
R12 N005 N004 {Rseries}
R13 N007 N004 {Rshunt}
D4 N003 N004 Dpv
I4 N004 N003 {imax}
R14 N003 N001 {Rseries}
R15 N004 N001 {Rshunt}
Q1 N002 N006 N011 0 BC817
Q2 0 N006 N011 0 BC807-40
A1 N008 N013 0 0 0 N006 0 0 SCHMITT vhigh=15 vlow=0 vt=1 vh=10m tau=10n
L1 N010 N009 56µ
.model D D
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.dio
.model NPN NPN
.model PNP PNP
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.bjt
.model NMOS NMOS
.model PMOS PMOS
.lib C:\users\ian\My Documents\LTspiceXVII\lib\cmp\standard.mos
.model dpv d(Is={Is} 11 N={n})
.param Is=1e-11 Imax=3.3 Vmax=40 n=Vmax*38.6/log(Imax/Is) Rseries=0.5 Rshunt=1meg
.tran 0 5m 0 100n
.opt plotwinsize=0
.backanno
.end
Code:
[Recent File List]
file0=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\PVcell.asc
file1=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\SICJFET.asc
file2=Z:\home\ian\Downloads\NormalVsCascode.asc
file3=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondmos.asc
file4=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\currentmirrormos.asc
file5=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondfetvas.asc
file6=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\diamondfetvas.asc
file7=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\lateralmosreduced.asc
file8=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240.asc
file9=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\quasicompreduced.asc
file10=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated\lateralmos.asc
file11=C:\users\ian\My Documents\LTspiceXVII\Draft12.asc
file12=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240bipolarVAS.asc
file13=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\AllNchannelIRFP240jfetinput.asc
file14=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\Draft10.asc
file15=Z:\home\ian\Documents\LTspiceXVII\lib\sym\AutoGenerated\inductorloadedamplifier.asc
[Options]
Solver=0
ShowCheckSum=false
WorkingDirectory=C:\users\ian\My Documents\LTspiceXVII\lib\sym\AutoGenerated
SymbolSearchPath=
LibrarySearchPath=
SymbolSearchPathDisabled=false
LibrarySearchPathDisabled=false
SpicePriority=1
PlotPriority=1
LastFileTypeOpened=0
Tabstopwidth=4
grid=on
GenerateExpandedListing=false
DefaultTrtol=1
DefaultTrapIntegration=true
DefaultDoAntiTrapRinging=true
TSKbypass=false
Accept_3k4_Notation=true
NoJFETtempAdjIsr=false
SaveDeviceCurrents=true
SaveSubcircuitNodeVoltages=false
SaveSubcircuitDeviceCurrents=false
saveOneCurrentPerDevice=false
ShowSchematicGrid=false
OrthogonalDrag=false
AutoPan=true
That's not helpful....

:(
 

eetech00

Joined Jun 8, 2013
4,705
One thing I see immediatley is that there is an infinite amount of current flowing to the base of the BJTs when the comparator output goes to 15v. There should be a current limiting resistor or use "ROUT" parameter. Actually, I believe the default is 1 ohm.
 

Papabravo

Joined Feb 24, 2006
22,083
If I evaluate the expression for n from left to right I get a nonsensical value of 134.04, for the semiconductor ideality factor. The value should be in the neighborhood of 1 to 2. A 1 is pure diffusion current and 2 is entirely recombination or high injection effects.

n=Vmax*38.6/log(Imax/Is)
Vmax = 40
Imax=3.3
Is = 1e-11

Imax/Is = 3.3 / 1e-11 = 3.3e11
log(3.3e11) = 11.518
40*38.6/11.518 = 134.04

That seems to be a ridiculous semiconductor you got there.
 

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
If I evaluate the expression for n from left to right I get a nonsensical value of 134.04, for the semiconductor ideality factor. The value should be in the neighborhood of 1 to 2. A 1 is pure diffusion current and 2 is entirely recombination or high injection effects.

n=Vmax*38.6/log(Imax/Is)
Vmax = 40
Imax=3.3
Is = 1e-11

Imax/Is = 3.3 / 1e-11 = 3.3e11
log(3.3e11) = 11.518
40*38.6/11.518 = 134.04

That seems to be a ridiculous semiconductor you got there.
It was donated by @ericgibbs .
I was planning on using a current source in parallel with a series combination of 60-odd 10 Amp diodes I was wondering how to model a solar panel without having to join up all the series diodes. The model appeared to work for a few resistive loads that I tried.
 

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
One thing I see immediatley is that there is an infinite amount of current flowing to the base of the BJTs when the comparator output goes to 15v. There should be a current limiting resistor or use "ROUT" parameter. Actually, I believe the default is 1 ohm.
So where is that current going? - it's just a complementary emitter follower driving a MOSFET gate. In reality, a complementary emitter follower would work with a negligible source impedance driving it, and I would expect the model of the BC817/807 to have an appropriate amount of base series resistance.
 

Papabravo

Joined Feb 24, 2006
22,083
It was donated by @ericgibbs .
I was planning on using a current source in parallel with a series combination of 60-odd 10 Amp diodes I was wondering how to model a solar panel without having to join up all the series diodes. The model appeared to work for a few resistive loads that I tried.
I guess you guys need to work that out. GIGO!
 

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
Rather than make assumptions, can you explain what the circuit is supposed to do?
Hysterectic buck regulator, charging a battery. The 48V voltage source is (for now) the battery. I'll add an appropriate amount of series resistance later, when I've got the rest of it to work.
 

Papabravo

Joined Feb 24, 2006
22,083
So, if I take a random 10A silicon diode, is there a neat or easy way of making it into a series combination of sixty of the same thing?
Do you for some reason think that a series connection of diodes have a value of n that is the sum of the individual n's? That is ridiculous on its's face and tells me you have no clue what N is about. That said, there is a feature that allows capacitors to have a multiplicity factor, but I'm not sure it extends to all components.

N is an ideality factor which tells the simulator the relative importance of diffusion currents and recombination currents. I have no idea what such a large value of N will do. Among other things it probably says the is no diffusion current at all. I have seen values close to zero (e.g. ~0.1) used to represent extreme ideal diodes, but the large value of N would probably not look like a diode at all.

From the LTspice HELP file on the Capacitor

C. Capacitor
Syntax: Cnnn n1 n2 Q=<expression> [ic=<value>] [m=<value>]

The m value is the number of parallel units. The default is 1.

EDIT: the multiplicity factor applies to inductors. It is the number of parallel units.

EDIT2: Oh Crap!
Apparently Diodes have two things called "N" going on with them

Thing 1: Is an "N" called the "emission coefficient" and what I have been calling the ideality factor. This value is inside the model card for the diode.

Thing 2: Is a "N" for the number of series connected devices which is outside of the model definition. Talk about an obscure scope rule!

I'm sorry and I apologize for the confusion. Unfortunately for you the expression you computed for N ended up inside the model card.

Your netlist should look like:

D1 N016 0 Dpv N=60​
If you want 60 copies of diode D1 in series. There is the N inside and the N outside and they are totally different. BTW, the outside N should be an integer or if computed you should use the floor and/or ceiling function to convert a real to an integer.

EDIT 3: Turns out the N inside the model card ONLY applies if you are using the Berkeley SPICE mode. It does NOT apply if you are using the conduction region-wise linear model. (See LTspice Help file for details).
 
Last edited:

Thread Starter

Ian0

Joined Aug 7, 2020
13,132
Do you for some reason think that a series connection of diodes have a value of n that is the sum of the individual n's? That is ridiculous on its's face and tells me you have no clue what N is about. That said, there is a feature that allows capacitors to have a multiplicity factor, but I'm not sure it extends to all components.

N is an ideality factor which tells the simulator the relative importance of diffusion currents and recombination currents. I have no idea what such a large value of N will do. among other things it probably says the is no diffusion current at all. I have seen values close to zero (e.g. ~0.1) used to represent extreme ideal diodes, but the large value would probably not look like a diode at all.

From the LTspice HELP file on the Capacitor

C. Capacitor
Syntax: Cnnn n1 n2 Q=<expression> [ic=<value>] [m=<value>]

The m value is the number of parallel units. The default is 1.
No, I wasn't confusing N=quantity with N=ideality-factor. I was simply wondering if there was an easy way of making multiple devices.
 

Papabravo

Joined Feb 24, 2006
22,083
No, I wasn't confusing N=quantity with N=ideality-factor. I was simply wondering if there was an easy way of making multiple devices.
Apparently there is. See final edit to post #38 above. Which brings us back to the parametric impact of the computed N to the problem(s) with the simulation.
 
Top