Impotence can be due to a lot of things and having it occasionally is normal. I don't believe it's genetic or a disease, I really think it comes from misunderstanding how the body and the mind function. You're very likely doing a bunch of things that are putting you in trouble. So stay away from Cialis or Viagra because you would be adding one more thing and spending $$$ with a whole lot of risks when all you have to do is fix your lifestyle. All I say here is from personal experience, it just work, wouldn't waste my time here otherwise.
PSYCHOLOGY, STRESS, CONFIDENCE: It can be due to some kind of stress. make sure you relax before you have sex. Massages can help, hot showers, music, setting the mood, a walk outside, going to the gym, whatever relaxes You. And in the long run do fix whatever is worrying you or downing your confidence.
Impotence can be very specific to the partner you have. Some partners I've been hard as steel for, others, soft as jellyfish. The nature of the relationship you have with the people, and the chemistry can affect the relationship a lot. I tend to need to know and find the PERSONALITY attractive of my partners attractive before I can be very hard for them.
PORN & MASTURBATION:
When you are too used to porn or to masturbation: For SOME people, porn can put the bar very high in terms of what you need to be normally aroused. It's like drugs, you end up need needing them to just be normally happy. I say SOME people because for OTHER people it's the opposite, when they watch too much porn in bed they are very horny and they ejaculate prematurely. Over masturbation can also desensitize your penis and make it under-stimulated during sex. If that's the case for you, masturbate less often and try different ways to make the masturbation very soft so that penetration is a more intense experience for you.
FOREPLAY FOREPLAY FOREPLAY: There's no point rushing things. If you're not hard don't attempt to penetrate her, she would find it frustrating and it would only aggravate your concern. Make sure you get enough foreplay for your partner and are hard enough to do it. If you're not, it's cool, IT HAPPENS. Women also have their dry days and their days when sex is not appealing to them at all. Foreplay can and should go beyond physical stimulation, it is a 'play' time with your partner, act, let go, be crazy, be intense, be loving, be soft, or be rough, do dirty talk, whatever arouses you psychologically and makes you enjoy each other as persons, regardless of the physical body.
LISTEN TO YOUR BODY: An erection is not automatic, so before you meet your partner or engage into sex, make sure you're wanting it. Your body is your friend, don't force to do things when it doesn't really want to. Keep your hands away from your stick and do it when you badly want it.
HOW YOUR PARTNER CAN HELP: If your impotence happens during the act, and f that happens too often (because otherwise once in a while it's normal) then you can ask your partner to be more tight. Women can control their PC muscles and both will appreciate a tighter experience. If you're gay, men also have muscles around their anus and in the rectum that they can control to be more tight.
LIFESTYLE AND FOOD: Smoking and junk food are definitely in the first line of physical troublemakers of your hard times. Whatever drugs, medicinal or not, can also affect your body. SALT is also a no-no, it messes up with your blood pressure, which is exactly what erections are 'all' about. Reduce salt, and sugar too. Do more exercise: at the gym do FULL BODY in one session (takes me 20 minuts, one set to failure per exercise) the testosterone response is higher this way. Eat whole eggs (cholesterol is used to make testosterone) and nuts because they contain parent essential fatty acids, basically unprocessed fats which are the building blocks of hormones and lots of other good things. Do cardio exercising, on a bike, running, whatever works for you just try open outdoors as they will also relax you more than indoors. A good heart and clean pipes is what makes it pumping.
GET SOME SUN!!!! I am never as aroused as when I get a decent amount of sun daily, about an hour a day avoiding around noon. It does relax me, and I suspect it fixes a Vitamin D deficiency I could be having.
LAST SOLUTION: SAMPLE YOUR BLOOD, and look for mineral and vitamin deficiencies, you might want to test your hormones too, beyond just testosterone if possible. Fix any deficiency with natural foods instead of supplements.