Don't put the "elapsed time" inside its own while loop. Just delete the small while loops and you should be OK.
If the bigger loop needs to repeat until the time has elapsed, you cannot prevent it from spinning by trapping execution in the small loop.
(Try to run your code with execution highlighting and you will see that the small inner loop will spin until the time has elapsed, at which point both loops stop.)
Of course instead of such a sequence worm, you should refactor your code as a compact state machine. You have an incredible amount of duplicate code for no apparent reason.