# How to simulate a comparator in Simetrix/SIMPLIS

I am trying to generate a square wave using a comparator and I am trying to simulate the whole circuit using the software Simetrix/SIMPLIS. This is the circuit I am using:

The first part uses a resistor and a capacitor to get an exponential from the square wave source, as we can see in this simulation result:

Now, with voltage divider on the inverting input of the comparator, it should take that exponential voltage, and generate a square wave that goes to 5V when the exponential is higher than 2.5V, and that goes to 0V when it is less than 2.5V.

However, the simulation does not show this on the output of the comparator. Some big spikes in the order of kilovolts arise, as we can see here:

I thought that something was wrong with the simulation itself, so I tried to fix it placing a resistor at the output, just like this:

And it looked like it worked because now the spikes disappear. However, the output never saturates to 5V as it should do, although it has the squared shape I was looking for but it is too tiny:

Does anyone know why is this happening? Is it something related to the components or the simulation/schematic itself?

The LP339 is a comparator with an open-collector output. You need a pull up resistor, not a pull down. Try using 30k$$\\Omega\$$ from the output to +5V.