• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LTspice: plotting the integral of a waveform

Status
Not open for further replies.

mikewax

Member
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?

buck.jpg
 

Attachments

alec_t

Well-Known Member
Most Helpful Member
Your formula for B1 is incorrect. Try this instead:
v=-idt(i(v2)+delay(i(v2),22u))/44u
 

Les Jones

Well-Known Member
Most Helpful Member
A 10 mF (10000 uf) capacitor looks a very large value on the output of a switching regulator.

Les.
 

alec_t

Well-Known Member
Most Helpful Member

mikewax

Member
It works for me. Did you notice the sign change?
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:
buck.jpg
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:
buck.jpg
which looks fairly accurate at a scale of 40ms, but at 400ms, it looks like this:
buck.jpg

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
 

ericgibbs

Well-Known Member
Most Helpful Member
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
 

alec_t

Well-Known Member
Most Helpful Member
looks fairly accurate at a scale of 40ms, but at 400ms, it looks like this:
That's what fooled me. I didn't have the patience to run the sim beyond 40mS :).
 

alec_t

Well-Known Member
Most Helpful Member
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.
 

mikewax

Member
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
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:
buck.jpg 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....
 

mikewax

Member
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.
WOW. you're really on to something. cause when i changed Δt to 40, i got this:
buck.jpg
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. :))))))
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top