Arduino disconnects from the computer after a few seconds

The problem is particular to this program. I used a PWM motor controller before adding PID control and it worked fine.

I got confused and somehow read that I should try a different board. Sorry.