Looks to me like this statement at the top of the loop()
dpm = 3 * tooth_spacing / threepulsetimecopy; // causing problem, due to multiplying diff types
will divide by zero (at least on the first loop)?
What is the output of your program - the debug statements?