Per my doctor, erection problems are most often caused by smoking, or anything which clogs arteries (like constantly eating fatty foods). I think the bad fats that clog arteries are called "trans fats".
Other than that, my doc said they don't know why it happens in healthy people who do not smoke and who eat right.
Your problems may be caused by stress or feelings of guilt due to the miscarriage. Sorry to hear that BTW.
I have a long time interest in psychology, specializing in relationship dynamics for 30 years.
(Please note, we give the best advice we can based on the information given in a post. For better advice, please include the age of all romantic partners.)