# LTspice: plotting the integral of a waveform

Discussion in 'Electronics Homework Help' started by mike wax, Nov 10, 2016.

1. ### mike wax

34
2
Oct 10, 2016
Hello,
i have this circuit that i did with LTspice, a DC buck voltage convertor. When I did the simulation, 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. See Bellow. The picture shows the current coming out of V2, the green part.
on the bottom right, the equation for V is the integral of the (green) current thru V2, summed over a Δt of 22u seconds, divided by 22u. So the current thru the resistor (the top trace) is supposed to be equal to the instantaneous average of the current through V2.
Therefore the top trace 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:
77
2. ### Harald KappModeratorModerator

11,997
2,813
Nov 17, 2011
THe lines are very parallel in my simulation:

I'm using LTSPICE XVII. Could this make a difference?

3. ### mike wax

34
2
Oct 10, 2016
looking at the picture i can't tell. could you try this one for me and see what the numbers are?

thanx, mike

File size:
1.7 KB
Views:
76
4. ### Alec_t

3,060
834
Jul 7, 2015
I think your problem is that you haven't allowed for the current through the zener.
Here's a mod of your sim, with B2 added to monitor the inductor current rather than V1 current. The two curves now coincide.

File size:
2.1 KB
Views:
74
5. ### mike wax

34
2
Oct 10, 2016
yeah i see what you mean but what i have to do is see the average current in V2. this is because V2 represents a usb port. i'm trying to charge a supercap off the usb line, so the point is to control how much current the circuit is drawing at V2.

Last edited: Nov 11, 2016

11,997
2,813
Nov 17, 2011
Here you go:

7. ### mike wax

34
2
Oct 10, 2016
yeah that's what i thought. the first #, avr1, is pretty close, but the 2nd and 3rd #s are way off. my equation just doesn't work. gotta find a different way to do this.

thanx Harald

11,997
2,813
Nov 17, 2011

9. ### mike wax

34
2
Oct 10, 2016
THAT'S IT!!! it's PERFECT, ZERO ERROR! it never occured to me to integrate it with a cap! now i'm gonna proceed with my design. what a relief.
but i don't quite get it. how did you figure the size of the cap?

10. ### Harald KappModeratorModerator

11,997
2,813
Nov 17, 2011
Easy as pie:
In your original post the integration is over 22µs. 1 kΩ*22 nF = 22 µs

11. ### mike wax

34
2
Oct 10, 2016
thanx Harald i gotta dust the cobwebs in my head