I can't see any reason in this code, why the while(1)-loop should be left. Do you use more than 1 ball? Could you post your main-function?