Here is how I would do it using bash special parameter SECONDS:
#!/bin/bash
SECONDS=0
# script is here
sleep $"$(( 500 > SECONDS ? 500 - SECONDS : 1 ))"
Normally SECONDS returns time (in seconds) since the script has started, but one can assign any value to (re)set the timer.