The fact that you can get erections in the morning or during other times is a big indicator that it is a mental rather than physical issue.
It happens far more often than you would think and most men encounter some issue with this at some point in their lives.
If you've tried other things, you can purchase (depending on applicable laws to your area) generic Viagra (Sildenafil) or Cialis (Tadalafil) which are far cheaper than the branded equivalent which would help with the anxiety aspect. Both require sexual arousal to work so bear that in mind. This can help put your mind at ease.
Sildenafil lasts for about 4 hours and Tadalafil has a longer lasting period up to 36 hours.
As always, it's best to consult a doctor or physician before taking any kind of medication.