Improved calibration function for Teensy 3.1 compatibility

Strengthened integer type defs to avoid spurrious results.