Issues in a simple comparator

Hi I am in the process of creating a PWM generator for a Buck converter.
I am starting off with a simple comarator for timing purposes. The idea is to use a sawtooth wave and using different voltages on the ramp to create timing events. However, a simple sircuit as shown below has many issue which i am unable to solve.

  1. Saw tooth waveform

upon closer inspection:

The ramp value doesn’t reach all the way to the final value at some time. Also the fall time for the second cycle is non zero.

.SUBCKT COMPARATOR 1 2 3 4 5

ECOMP 3 0 TABLE {V(1,2)} = (-1mV 0V) ((10mV, 3.3V)

.ENDS COMPARATOR

Why does the comparator output goes down when the input voltage clearly has not gone below -1mv??

Looks like a limit in your simulation resolution. Also look at the fall time of your flanks. Sometimes it is “zero”, and other times it is “significant”. If you increase the time resolution these effects will become less.

Don’t use a fall time of 0. This is unphysical and will lead to errors. Give it a small fall time instead.

Don’t run a comparator at its edge of the detection window. Choose a robust value in the middle of the ramp instead.

There is an integrated code model for a PWM, which I have used in a Regulated boost converter, see More simulation examples for KiCad/Eeschema/ngspice .

Hi Paul,

Thanks. That actually worked. Initially it was:

.tran  1u 1m 0 
.options chgtol=1e-11 reltol=0.01 rshunt=1G rseries=0.00005 cshunt=0.1p

Then I changed to:

.tran  1n 1m 0 
.options chgtol=1e-11 reltol=0.01 rshunt=1G rseries=0.00005 cshunt=0.1p

Regards,
Sam

Hi Holger,
I changed fall time to 1fs. I am actually looking for a PWM resolution of 100ps. So these fall times has to be very short.
Thanks a lot for the examples. I will check them out.

Regards,
Sanatan

So i am new to the whole NGspice thing, and i just upgraded to Kicad 8.

It seems like the Current vectors are missing. I am sure I am missing somethings, but not sure what.

Circuit has a resistor R1 but current vector doesn’t exist.

Error: vector I(R1) not found!
Error: vector I(R1) not found!
Error: vector I(R1) not found!
Error: vector I(R1) not found!
Error: vector I(R1) not found!

I can post this on a separate thread if necessary.

This topic was automatically closed after 90 days. New replies are no longer allowed.