Sometimes it's due to lack of readily available energy (when it's not psychological, or other underlying problems like goodsamaritan has written), those muscles need quite some energy to keep constantly contracted.
I've noticed loading up on sugar beforehand (sugar = fruits, watermelon sounds about right), and avoiding fat which slows down metabolism, will lead to harder, longer erection and much better sex overall.