Optimal way of making timed code

how would you time between and limit the # of a fixed # of pulse?