# LTspice: plotting the integral of a waveform

Discussion in 'Homework Help' started by mikewax, Nov 9, 2016.

1. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles
THANX guys for ur assistance with my spice problems

now i've made and plotted a working circuit, a DC buck convertor, with LTspice and started tweaking it around. But one of the traces on my plot shows a math function that is not producing the right #s and i can't figure out why. The current thru R1 is supposed to be equal to the instantaneous average of the current through V2.
The equation for V is the integral of the (green) current thru V2, summed over a Δt of 22u, divided by 22u. So the white trace at the top is supposed to be parallel with the green one underneath. And at the beginning, it is. But the deviation looks very linear, like there's some kind of bias goin on in B1. I have zoomed in systematically at each 10ms interval and compared the average of the two traces. the top one is definitely deviating and has the wrong slope. anyone know what the problem could be?

File size:
1.4 KB
Views:
93
2. ### alec_tWell-Known MemberMost Helpful Member

Joined:
Jul 10, 2011
Messages:
9,291
Likes:
1,224
Location:
Cardiff, Wales
Your formula for B1 is incorrect. Try this instead:
v=-idt(i(v2)+delay(i(v2),22u))/44u

3. ### Les JonesWell-Known Member

Joined:
May 15, 2015
Messages:
1,456
Likes:
190
Location:
Lancashire UK
A 10 mF (10000 uf) capacitor looks a very large value on the output of a switching regulator.

Les.

• Informative x 1
• Agree x 1

Joined:
Jan 12, 1997
Messages:
-
Likes:
0

5. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles

no that didn't work either. it just gave the same results divided by 2. something must be wrong with my equation but god knows what.

6. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles
yeah that's because the purpose of the circuit is to charge a supercap.

7. ### alec_tWell-Known MemberMost Helpful Member

Joined:
Jul 10, 2011
Messages:
9,291
Likes:
1,224
Location:
Cardiff, Wales
It works for me. Did you notice the sign change?

8. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles
well i don't know what i'm not seeing, because when i use the formula for B1, V = -idt(I(V2) + delay(I(V2), 10u))/20u, what i'm getting is this:

and the numbers show the same thing:
avi1: AVG(i(v2))=-0.00927139 FROM 0.01 TO 0.0101 <--- 10ms
avr1: i(r1)=23.9429 at 0.01 <-----V = -idt(I(V2) + delay(I(V2), 10u))/20u
avi2: AVG(i(v2))=-0.00904411 FROM 0.02 TO 0.0201 <--- 20ms
avr2: i(r1)=33.2628 at 0.02
avi3: AVG(i(v2))=-0.00918508 FROM 0.03 TO 0.0301 <--- 30ms
avr3: i(r1)=42.5975 at 0.03

when i use this formula for B1, V = idt(I(V2) - delay(I(V2), 10u))/10u, i get this:

which looks fairly accurate at a scale of 40ms, but at 400ms, it looks like this:

so neither formula seems to be giving the average of the curve for the current I(V2) which is what i need to be able to do the circuit. it seems like such a simple thing, a basic integral. but it just ain't workin.
thanx alec

9. ### ericgibbsWell-Known MemberMost Helpful Member

Joined:
Jan 4, 2007
Messages:
21,223
Likes:
644
Location:
Ex Yorks' Hants UK
hi Mike,
Its an accumulation of transient tolerance errors in the LTS maths, to demonstrate the effect of these tolerances try changing Trtol [ Transient error tolerance] in LTS Tools.

The Default value is 1, try 7, you will see that I(R1) curve error is an an artefact of the LTS maths.

Why are you charging a super cap in this way.?

E

10. ### alec_tWell-Known MemberMost Helpful Member

Joined:
Jul 10, 2011
Messages:
9,291
Likes:
1,224
Location:
Cardiff, Wales
That's what fooled me. I didn't have the patience to run the sim beyond 40mS .

• Funny x 1
11. ### alec_tWell-Known MemberMost Helpful Member

Joined:
Jul 10, 2011
Messages:
9,291
Likes:
1,224
Location:
Cardiff, Wales
I note that the average obtained using your formula gives wildly different results depending on the value chosen for the sample interval. (Not surprising, since the samples are being taken at non-random instants related to the switching of V1). Change the '10u' to '40u', for example, and see. For a true average value I reckon the formula would be V=idt(I(V2))/time.

12. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles
ok i had to google that. so these transient errors are coming out of my integral equation? and they accumulate? in spite of the fact that the data that i'm integrating over remains essentially constant? when i changed the Trtol to 7 i got this:
the red line is holding pretty constant at about .009, while my equation just walks away. this **** is over my head.

i work for a rich tinkerer. He grabbed a webcam, stuck it on a motorized gimbal, and said "this thing plugs into the usb port. every 60 seconds the motor has to run for 1 second at 5v, 800mA. And put limit switches to make it reverse every 200 degrees of rotation"
right away sir....

13. ### mikewaxMember

Joined:
Nov 6, 2016
Messages:
49
Likes:
2
Location:
los angeles
WOW. you're really on to something. cause when i changed Δt to 40, i got this:

that's WAY better.

OK i'm gonna keep tweakin the numbers. increasing Δt and Trtol brought the error way down. i don't really understand this, but i'm gonna keep workin n maybe i will.
THANX fellas. now i can make progress again. )))))