PIC32 MX230F064B USB POWERED
You can do what you are after with a regulator, a couple of capacitors, and two diodes:







simulate this circuit &ndash; Schematic created using CircuitLab

D1 and D2 act as a power "OR" gate - the power supply with the highest voltage wins and supplies the power to the regulator. The regulator then reduces that power (whatever it is - as long as it is above 3.3V + the regulator's dropout voltage) down to 3.3V to power the chip.

The diodes should have a low forward voltage drop (Schottky are good for that) and the sum of the drop + regulated voltages must be below 4.75V:

\$(V_{D1} + V_{DROP} + 3.3) &lt; 4.75\$

This is to ensure that the voltage at the input to the regulator when powered from USB (which can be as low as 4.75V and still be within specifications) is more than 3.3V plus the regulator dropout voltage. The lower the dropout voltage, and the lower the diode forward voltage drop, the easier your task will be.

USB is guaranteed to provide you (initially) with 100mA of current capacity. You request more by specifying the requirements of your circuit in your USB device descriptor within the USB stack you are using (e.g., Harmony or MLA).