I am trying to use LMH6642MAX op amplifier in the non-inverting closed-loop configuration (gain 3.5) for a periodic square input signal 20 kHz (2 Volts High, 0 Volts Low).

The problem comes when I measure the voltage at the output, the signal swings between 6 an 7 volts. I would expect to oscillate between 0 and 7V (3.5 \* 2). Any clue why this is happening? It is a rail to rail op amp so it should be able to output 0V.

[![enter image description here](https://i.stack.imgur.com/HTOFF.png)](https://i.stack.imgur.com/HTOFF.png)

[![enter image description here](https://i.stack.imgur.com/9HeDG.png)](https://i.stack.imgur.com/9HeDG.png)

[![enter image description here](https://i.stack.imgur.com/kvwLw.png)](https://i.stack.imgur.com/kvwLw.png)

Edit:

As some of you have clearly mentioned the pin numbers in the schematics are not correct. The package that I have used is the SOIC, so the non-inverting pin is the 3 and the inverting is the pin 2 and this configuration is what I have in the PCB.

Yesterday I finally realized that IC was malfunctioning so I have replaced it. Now it works as expected but when the output is high the op-amp oscillates as shown in the image:

[![enter image description here](https://i.stack.imgur.com/bHxba.png)](https://i.stack.imgur.com/bHxba.png)

However, after reading this document (<https://www.ti.com/lit/an/snoa367c/snoa367c.pdf?ts=1635793735182>) I realized that small capacitance in the output could make the op-amp oscillate. So I thought that the capacitance of the oscilloscope probe could be sufficient to make the op-amp oscillate. So I attached a 1k Ohm resistor and the reading as displayed in the image is correct.

[![enter image description here](https://i.stack.imgur.com/n64O9.png)](https://i.stack.imgur.com/n64O9.png)

I am not sure if this was the root cause or just was a coincidence because I have tried to emulate the circuit using LTspice but I do not achieve the same result. With such small capacitance, I am not able to get the same results

[![enter image description here](https://i.stack.imgur.com/IgGIl.png)](https://i.stack.imgur.com/IgGIl.png)