I have a Moto G running 4.4.4. 

When it's connected to a PC, it will only charge if the screen is locked: as soon as it's unlocked it will stop charging. In this situation, even if I lock the screen again it will not go back to charging.

When it's connected to the charger, it charges normally regardless of being unlocked or not.

What can be causing this problem and how to solve it?