این دو تا لینک رو بخون
counting pulses per second

An another delay and counter question