Erectile dysfunction has multiple causes.
From what you have written, it seems like you might be getting nervous during intercourse.
It is completely understandable and normal to happen.
But if it keeps happening, it is proper to take a proper consultation and therapy to help decrease the anxiety.
30-40% males suffer from these issues, nothing to worry about. We have to work on it together with medicines and therapy to ease your mind during intercourse.
Next Steps
take proper consultation to further understand the cause behind the problem.
Health Tips
do not self-medicate