The re-ordering above will break for values of (a) less than 1000 and so no good as other parts of the core depend on this working.
Yes that makes sense. I made that code change just to get past the problem to see how pulseIn() worked.
A simple fix might be to divide timeout by 16 prior to calling microsecondsToClockCycles as in the following:
unsigned long maxloops = microsecondsToClockCycles(timeout / 16);
Then you should be good up to about 4 seconds. Adding a note on this limitation to the pulseIn page wouldn't hurt either.
Good suggestion-it gets divided by 16 afterwards anyway.
If the CPU speed are all integral number of Mhz could also divide by 1M and multiply by timeout but i think your solution is better.
So how does this work to get the fix implemented ? I am completely new to arduino and I want to make sure I am using the "official" fixed code .