Need advice

So my boyfriend and I are having a bit of a rough time in the sex department. We'll get going and everything will be great and then seemingly out of nowhere he'll go soft. The first couple of times it happened we powered through and eventually finished (well he did). Then it happened again...and again... And I got a little frustrated thinking maybe it was me or something I was doing, asked him about it he said that I wasn't doing anything and he was still really attracted to me. Last time, everything was going great and then same thing but I stopped everything because I felt so defeated. Has something like this ever happened to anyone else? Im not a super self conscious person but I can't help but wonder if it is me or something I'm doing... Thanks in advance for any help!