In addition to Susan's answer, what you describe could be caused by over stimulating yourself. Nerves can get frazzled (slightly stressed). The brain sometimes interprets pleasure in guys as pain and begins shutting nerves down. Whenever we have a problem as you describe, we just work it more trying to get that feeling back...maybe just the opposite of what we need to do. This can be remedied by giving your penis some vacation.
You may be also bothered by a low semen supply often accompanied by prostate leakage or an over supply of emitted pre-cum, and if so, the penis "thinks" it has ejaculated"... so it begins the normal sequence of getting soft. Also vacation.
Another thing that can happen is that you are heat sensitive. After a penis gets so warm, it will shut down to cool itself off. This can be crutched by cooling it off with a washcloth and cool water. The next time you are with your girl, and it happens, try cooling it off.
The last thing is nerves...when you are with your girl, you want to make a good impression...and when you can't , it turns to frustration which frustrates her also trying hard to please you. Relax.