Curious to know if this approach has any merit:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//#define DEBUG 1 //uncomment to stop time-consuming serial printing
//microseconds per half-pulse lookup table
const unsigned long uSPerHalfPulse[141] =
{
4687, 4261, 3906, 3605, 3348, 3125, 2929, 2757, 2604, 2467, 2343, 2232, 2130, 2038,
1953, 1875, 1802, 1736, 1674, 1616, 1562, 1512, 1464, 1420, 1378, 1339, 1302, 1266,
1233, 1201, 1171, 1143, 1116, 1090, 1065, 1041, 1019,
997, 976, 956, 937, 919, 901, 884, 868, 852, 837, 822, 808, 794, 781, 768, 756, 744,
732, 721, 710, 699, 689, 679, 669, 660, 651, 642, 633, 625, 616, 608, 600, 593, 585,
578, 571, 564, 558, 551, 545, 538, 532, 526, 520, 515, 509, 504, 498, 493, 488, 483,
478, 473, 468, 464, 459, 455, 450, 446, 442, 438, 434, 430, 426, 422, 418, 414, 411,
407, 404, 400, 397, 393, 390, 387, 384, 381, 378, 375, 372, 369, 366, 363, 360, 357,
355, 352, 349, 347, 344, 342, 339, 337, 334, 332, 330, 327, 325, 323, 321, 318, 316,
314, 312
};
const int stepsPerRevolution = 6400;
const int sPin = 9;
const int dirpin = 8;
const int pinPot = A4;
//use globals to avoid time-consuming stack accesses
unsigned long
timeNow,
timeMotor = 0,
uSecDelay = 0;
int
potVal = 0,
lastidx = -1,
whole, //whole part of RPM figure
frac, //tenths part of RPM figure
idx;
bool
bpinLevel = 0;
void setup()
{
pinMode( pinPot, INPUT );
pinMode( sPin, OUTPUT );
pinMode( dirpin, OUTPUT );
digitalWrite( dirpin, HIGH );
lcd.setCursor( 0,0 );
lcd.print( "RPM:" );
Serial.begin(9600);
}//setup
void StepControl( void )
{
timeNow = micros();
if( (timeNow - timeMotor) < uSecDelay )
return;
timeMotor = timeNow;
bpinLevel ^= 1;
digitalWrite( sPin, (bpinLevel)?HIGH:LOW );
//time-consuming analog is read is placed where we think/know it will
//do no harm (right at the beginning of a pulse half-period period...)
potVal = analogRead(pinPot);
}//StepControl
void loop()
{
//call step control to keep tight control on pin timing
StepControl();
idx = map( potVal, 0, 1023, 0, 140 );
StepControl();
if( idx != lastidx )
{
//update things only if different from last update
uSecDelay = uSPerHalfPulse[idx];
whole = (idx+10)/10;
frac = idx - ((whole-1)*10);
StepControl();
lcd.setCursor(0,5);
StepControl();
lcd.print(whole);
StepControl();
lcd.print(".");
StepControl();
lcd.print(frac);
StepControl();
lcd.print( " " );
StepControl();
#ifdef DEBUG
//debug
StepControl();
Serial.println( uSecDelay );
StepControl();
#endif
lastidx = idx;
}//if
}//loop