Where is my error in this LTspice simulation? - Page 1
Forum section: electronics / projects

author: seamusdemora
author_rank: Regular Contributor
timestamp: November 03, 2020, 10:21:41 pm
content: I've created an LTspice model of a simple circuit. I'm not getting the correct answer, and I've been unable to find my mistake. I would appreciate it if someone could take a look at this, and tell me where I've gone wrong.The netlist:Code:*C1 Vac Vi 1.0µV1 Vi 0 PULSE(0 2 0 0 0 10.0u 20u)R1 Vac 0 4.7k.tran 0 50.0m 49.9m.backanno.endThe schematic and the result of the simulation run are attached. Looking at the simulation run, note that the output voltage is not a symmetric ac waveform of +/- 1V centered on the 0V line. I began to doubt myself, and so I built this circuit on a breadboard & looked at on my o'scope. The output voltage was what I thought it should be. Consequently, my conclusion is I've boinked my LTspice model... but I can find nothing wrong with it.

author: TimFox
author_rank: Super Contributor
timestamp: November 03, 2020, 10:31:05 pm
content: You haven't waited long enough for the initial transient insult to the capacitor to die away. The time constant for that voltage to go away is 4.7 msec, and you only simulated out to 0.1 msec.In SPICE .tran analysis, the voltage source is steady at zero from the beginning of time until that specified in your generator.

author: Ian.M
author_rank: Super Contributor
timestamp: November 03, 2020, 10:45:37 pm
content: Set realistic rise and fall times e.g.Code:PULSE(0 2 0 10n 10n 10.0u 20u)Quote from: TimFox on November 03, 2020, 10:31:05 pmNot so. Seamus is using:Code:.tran 0 50.0m 49.9mso it runs for more than ten time constants before it starts plotting and saving data. After five time constants, a RC circuit will have settled sufficiently for most applications (within 0.7% of its final value). After 10 time constants the remaining error due to the initial transient will be under 50 microvolts

author: sandalcandal
author_rank: Unknown
timestamp: November 03, 2020, 10:46:30 pm
content: Not sure what TimFox is talking about, you've set the sim up to record from 49.9ms to 50.0ms so initial DC through the capacitor should be gone.The signal looks like exactly what I'd expect given the input frequency and RC values, the capacitor should effectively be a short circuit i.e. non-existent. If you're expecting triangular RC decays then you'll need a much lower frequency input, smaller capacitor or smaller resistor. You sure the IRL test parameters are the same as your sim?Edit2: Never mind I was thinking the wrong thing not sure why the output has -0.1V offsetEdit: Editing rise/fall times like IanM suggest also isn't going to do anything apart from making the transition more sharp.If set to zero the rise fall times default to something like 10% the period.Resolved below

author: Ian.M
author_rank: Super Contributor
timestamp: November 03, 2020, 10:56:45 pm
content: The problem is the PULSE source rise time is *NOT* subtracted from the specified on time. If rise and fall times default to a total of 10% of the period, the off time becomes significantly shorter than the on time. See Seamus's waveform plot, where you can clearly see Vin is assymetric, high for 10us, and low for about 8us or look at the start of the falling edge, which should all be aligned with the 10us grid but aren't.My suggested PULSE command reduces the asymmetry to 0.1%, negligable for any practical circuit. If you want to do better and get an accurate 50% duty cycle, with greater rise and fall times, try:Code:PULSE(0 2 0 {Trise_fall} {Trise_fall} {Tperiod/2-Trise_fall} {Tperiod})and add the directives:Code:.param Trise_fall=1u.param Tperiod=20u

author: sandalcandal
author_rank: Unknown
timestamp: November 03, 2020, 11:05:50 pm
content: Quote from: Ian.M on November 03, 2020, 10:56:45 pmAh yep good call. Would have to set on time to 9us or extend period to ~22us or just make transitions fast enough to be negligible as you say. Completely explains the -0.1V offset.Edit: Not so much realistic rise/fall times, more setting up the pulse directive properly to get an actual 50-50 square input. Actually found I did something similar in my own previous models but Ian's suggestion will have less error.

author: Ian.M
author_rank: Super Contributor
timestamp: November 03, 2020, 11:19:46 pm
content: No real circuit can generate an idealHeaviside step function, so when you attempt to set the PULSE source rise and fall times to zero, (i.e. a value that's unrealistic in the sense of being physically impossible) you can bet you wont like what LTspice chooses to do instead.IIRC I first noticed this behavior when trying to use a pulse source as a triangle wave:Code:PULSE(0 2 0 10u 10u 0 20u)works and produced a temporally symmetric triangle wave, but note its 'on' time is set to zero. If you try the apparently obvious:Code:PULSE(0 2 0 10u 10u 10u 20u), you get an interrupted triangle wave with a 10us 'flat top' segment and 30us period, totally ignoring the 20us period set!

author: seamusdemora
author_rank: Regular Contributor
timestamp: November 04, 2020, 01:02:33 pm
content: Thanks to all - the original question has been answered, and several corrective actions provided. As a newbie with LTspice, this is most useful.And as is typical, answers lead to more questions. Please refer to the attached figure showing the 'Waveforms` tab on the dialog conjured by clicking the Control Panel (Hammer icon) on the waveform viewer. I was able to edit several aspects of my waveform, but couldn't discover how to make the traces anything other than solid lines (e.g. dashed or dotted lines). I suspected this was the point of the "Open Plot Defs" button, but clicking it yielded nothing at all - other than closing the Control Panel window. OTOH, clicking the "Configure Colors" button yields a dialog to control background, text & trace colors.Q: How do I get dashed lines in my waveform plots?Another question arises from @IanM's comment:QuoteQ: Isn't this considered a flaw in the LTspice software?Do you mean it's not "automatically" subtracted from theTontime in the dialog? And isn't 10% an unreasonably large default rise time - in many circumstances? Sorry - I think your comment is important; I just don't quite understand it.I have other questions, but this is enough for now

author: Ian.M
author_rank: Super Contributor
timestamp: November 05, 2020, 09:47:55 am
content: Quote from: seamusdemora on November 04, 2020, 01:02:33 pmYou don't. In frequency domain (.AC) plots signal amplitudes are shown as solid lines and their phases as dotted lines of the same colour. Dashed lines are reserved for cursors. N.B. unless you are debugging why your waveform is inaccurate or are plotting a sparse .STEPped data set, turn off 'MarkData Points' as at zoom levels where the waveform is realistic, it only adds clutter.Quote from: seamusdemora on November 04, 2020, 01:02:33 pmNo, its a badly documented feature. Berkeley SPICE 3 did it thesame way, so if L.T. had done it differently it would break SPICE 3 compatibility. However it would have been helpful if they'd put a diagram in the manual, like this one from a PSPICE tutorial:

author: Jay_Diddy_B
author_rank: Super Contributor
timestamp: November 05, 2020, 11:11:12 am
content: Hi,In addition to what has been said already.Setting Trise and Tfall equal to zero has special meaning in SPICE.Syntax: Vxxx n+ n- PULSE(V1 V2 Tdelay Trise Tfall Ton Tperiod Ncycles)If Trise or Tfall = 0 they are assumed to be 10% of Ton.Example:I don't believe that is an LTspice thing, I believe that it is a SPICE thing.Tfall = 0 and/or Trise = 0 is are special cases.In LTspice, the statement.option plotwinsize=0Turns off data compression on the plot waveform.So this meansPulse (0 1 0 0 0 1u 2u)This has an average value of 0.55Vnot 0.5VRegards,Jay_Diddy_B