Run if (or similar) statement once

jtw11:

  rpm = ((mdpm / 1000000) * 60000) / 360; // converts degrees per micro to rpm

In addition to the valid issues that PaulS pointed out, calculations like the one above are begging for trouble with overflow or rounding issues in the intermediate values of your expression. You need to be aware of the type and range of values at each expression in your calculation and actively look to see whether you have any overflow or rounding issues at each step. In this case, for example, what is the smallest possible value of (mdpm / 1000000)? Any danger that it is so small that you get significant rounding? What is the type of that intermediate value? What is the largest value? Any danger of overflowing the type it's held in? Now multiple the largest value * 60000: what type is that and is there any danger of that overflowing?

Any time you scale a value up or down a lot you increase the size of the type needed to hold the full range of possible values. This is why multiplyingh and dividing by large numbers as above are a bad idea. Far better to calculate what the end result of multiplying and dividing by all those constants is, and do that in one step.

I think it is equivalent to this:

  rpm = mdpm / 60000UL;

I could be wrong so you need to check that I've canceled the terms out correctly, but I'm sure you can see how that's far less likely to cause overflow or rounding errors.