USBVCC switching components on Mega2560?

Hi, please can someone clarify the purpose of the circuit that's at the bottom of the reference design page for the Mega2560?

It appears to be an LMV358 op-amp (IC7B) driving a FDN340 MOSFET (T1) to switch a 5v supply, "USBVCC".

A 50% potential divider feeds the non-inverting terminal of the op-amp. It halves the voltage of "VIN" to make "CMP". It looks to me as if USBVCC will be switched to the 5v rail, as long as VIN is over 6.6v. Am I right? What's this to achieve, exactly? My guess is that it disables USB comms unless VIN is high enough to run everything.

I'm asking all this as I'm in the process of making a PCB using the minimum necessary components, to further an Arduino based design project. It will have its own constant voltage supply, and only require USB comms occasionally.

Many thanks, Matt.

The opamp detects if there is an external supply connected to the DC socket (or Vin).

If Vin is >6.6volt, or DC-in is 7.3volt (reverse protection diode), USB supply is disconnected.

Gremlin: The mosfet's reverse protection diode. Leo..

Ok many thanks Leo for responding.

So I wonder how necessary this circuit would be, where the application will no longer be an experimental Arduino board, but a custom PCB with constant power available?

i.e. Is there any reason to keep this switching circuit, if the 5v and 3.3v rails are normally going to be on all the time?

Thanks Matt

Whenever you allow to attach multiple power sources (USB is such a source!), you have to prevent shorts. E.g. the Pro Mini can be powered directly by an external source (up to 5V Vin), or via on-board 3.3V regulator. Not all 3.3V regulators survive 5V on their output.

Thanks DrDiettrich. I get it now: the circuit takes 5v from the USB socket, unless VIN is present, so that the two supplies don't fight each other when both are connected.

I found the following detailed article quite helpful:

So for my application, I think I'll just isolate the 5v supply pin on the USB connector, as constant power will be provided by the on-board regulators.