Problems with trigger input code

New to Arduino, Mega 2560. I'm having a lot of trouble just trying to get a basic ISR code written to calculate the period between trigger inputs. At each iteration I am using a micro second time stamp, saving it as previous, then calculating the difference to get the period. I'm printing out the results as they happen just to see if I am doing things right, but something is very wrong. I am monitoring the inputs with a digital signal analyzer and the signal looks just fine, but the results seem to get screwed up and I have no idea why. Any help would be greatly appreciated.
Here's my code:


// ************************ Program constants **************************:
// - Pin numbers -:
const byte triggerPin = 19;         // Trigger  input on pin 19

// ************************ Global Variables ***************************:
volatile unsigned long curTimeStampUS;   // Current microsecond time stamp
volatile unsigned long prevTimeStampUS;  // Previous microsecond time stamp
volatile unsigned long periodUS;         // Period between time stamps
volatile unsigned long iteration;        // Iteration counter

// ************************ Program Functions **************************:

// -------------------------------------------------:
// ISR Function to calculate period between trigger inputs.
void triggerInput()
{ // Start of triggerInput ISR
// Subtract the current microsecond time stamp from the previous microsecond time stamp to get the microsecond period between trigger inputs
  iteration++;                                   // Increment iteration (For program developement)
  Serial.println("iteration");                   // For program developement
  Serial.println(iteration);                     // For program developement
  Serial.println("prevTimeStampUS");             // For program developement
  Serial.println(prevTimeStampUS);               // For program developement 
  curTimeStampUS = micros();                     // Get the current microsecond time stamp
  Serial.println("curTimeStampUS");              // For program developement
  Serial.println(curTimeStampUS);                // For program developement
  periodUS = curTimeStampUS - prevTimeStampUS;   // Tooth period = current time stamp minus the previous one
  Serial.println("periodUS");                    // For program developement
  Serial.println(periodUS);                      // For program developement
  prevTimeStampUS = curTimeStampUS;              // Update the previous time stamp with the current one for next iteration
}// End of triggerInput ISR

// -------------------------------------------------:

//   The setup function will only run once, after each powerup or reset of Arduino. 
void setup()
{ // Start of setup function
   curTimeStampUS = 0;   // Current microsecond time stamp initialized with 0
   prevTimeStampUS = 0;  // Previous microsecond time stamp initialized with 0
   periodUS = 0;         // Period between time stamps initialized with 0
   iteration = 0;        // Iteration counter initialized with 0 
   attachInterrupt (digitalPinToInterrupt (triggerPin), triggerInput, RISING);  //  pulseIn() function is called  when pin 19 goes from Low to High
   Serial.begin(9600);                   // Initialize serial communication at 9600 bits per second(for program developement)
 } // End of setup function  

// - The loop() function contains the main program loop.
void loop()
{ // Start of loop function 
  // No code here yet
} // End of loop function

Here's a portion of the serial monitor print out:
iteration
1
prevTimeStampUS
0
curTimeStampUS
10307556
periodUS
10307556
iteration
2
prevTimeStampUS
10307556
curTimeStampUS
10308112
periodUS
556
iteration
3
prevTimeStampUS
10308112
curTimeStampUS
10452616
periodUS
144504
iteration
4
prevTimeStampUS
10452616
curTimeStampUS
10452940
periodUS
324
iteration
5
prevTimeStampUS
10452940
curTimeStampUS
10452204
periodUS
4294966560
iteration
6
prevTimeStampUS
10452204
curTimeStampUS
10452604
periodUS
400
iteration
7
prevTimeStampUS
10452604
curTimeStampUS
10452892
periodUS
288
iteration
8
prevTimeStampUS
10452892
curTimeStampUS
10452156
periodUS
4294966560
iteration
9
prevTimeStampUS
10452156
curTimeStampUS
10452556
periodUS
400
iteration
10
prevTimeStampUS
10452556
curTimeStampUS
10452860
periodUS
304
iteration
11
prevTimeStampUS
10452860
curTimeStampUS
10452140
periodUS
4294966576
iteration
12
prevTimeStampUS
10452140
curTimeStampUS
10452556
periodUS
416

I have a screen shot of the digital analyzer screen but I don't know how to attach it.

Thanks,
Robert

It is recommended that an interruption routine be as small as possible.

All calculation and printing or display routines must be outside the interrupt routine.

Your interrupt routine is too long and affects new interrupts.

PS:
micros(): this function is the same as millis(), but returns the time in microseconds . However, contrary to millis(), micros() will work at the beginning of an interrupt. But after 1 or 2 milliseconds, the behavior won't be accurate and you may have a permanent drift every time you use micros() afterwards.

PS 2:

Try this code:

// ************************ Program constants **************************:
// - Pin numbers -:
const byte triggerPin = 19;         // Trigger  input on pin 19

// ************************ Global Variables ***************************:
volatile unsigned long curTimeStampUS;   // Current microsecond time stamp
volatile unsigned long prevTimeStampUS;  // Previous microsecond time stamp
volatile unsigned long periodUS;         // Period between time stamps
volatile unsigned long iteration;        // Iteration counter
bool flag = true;
// ************************ Program Functions **************************:

// -------------------------------------------------:
// ISR Function to calculate period between trigger inputs.
void triggerInput()
{ // Start of triggerInput ISR
  // Subtract the current microsecond time stamp from the previous microsecond time stamp to get the microsecond period between trigger inputs
  iteration++;
  flag = true;                                  // Increment iteration (For program developement)
  // Update the previous time stamp with the current one for next iteration
}// End of triggerInput ISR

// -------------------------------------------------:

//   The setup function will only run once, after each powerup or reset of Arduino.
void setup()
{ // Start of setup function
  curTimeStampUS = 0;   // Current microsecond time stamp initialized with 0
  prevTimeStampUS = 0;  // Previous microsecond time stamp initialized with 0
  periodUS = 0;         // Period between time stamps initialized with 0
  iteration = 0;        // Iteration counter initialized with 0
  attachInterrupt (digitalPinToInterrupt (triggerPin), triggerInput, RISING);  //  pulseIn() function is called  when pin 19 goes from Low to High
  Serial.begin(9600);                   // Initialize serial communication at 9600 bits per second(for program developement)
} // End of setup function

// - The loop() function contains the main program loop.
void loop()
{
  if (flag == true) {
    Serial.print("iteration ");                   // For program developement
    Serial.println(iteration);                     // For program developement
    Serial.print("prevTimeStampUS ");             // For program developement
    Serial.println(prevTimeStampUS);               // For program developement
    curTimeStampUS = micros();                     // Get the current microsecond time stamp
    Serial.print("curTimeStampUS ");              // For program developement
    Serial.println(curTimeStampUS);                // For program developement
    periodUS = curTimeStampUS - prevTimeStampUS;   // Tooth period = current time stamp minus the previous one
    Serial.print("periodUS ");                    // For program developement
    Serial.println(periodUS);                      // For program developement
    Serial.println(" ");
    flag = false;
    prevTimeStampUS = curTimeStampUS;
  }
}

All of your serial print data will remain in the print buffer until your interrupt code as completed, only then are interrupts allowed to begin send the data to your PC.

In addition, if you fill the outbound buffer before the end of an interrupt, the whole thing crashes because there's no serial interrupt available to remove characters from the output buffer.
Rule is, never print from within your interrupt, and as others are saying, keep the interrupt code as brief as possible. Do your quick calc in the interrupt, let loop() take care of printing any new value. Use a flag to tell loop() you've updated the output. You'll have to determine if it's even possible for loop() to keep up, printing every new value.

Thanks very much for the suggestions everyone. I tried the suggested revised code but I still have issues.
Here is the serial print display print out. I'm sorry it is so long but it might reveal something:
iteration 0
prevTimeStampUS 0
curTimeStampUS 348
periodUS 348

iteration 3
prevTimeStampUS 348
curTimeStampUS 29636304
periodUS 29635956

iteration 7
prevTimeStampUS 29636304
curTimeStampUS 29763424
periodUS 127120

iteration 9
prevTimeStampUS 29763424
curTimeStampUS 29986264
periodUS 222840

iteration 12
prevTimeStampUS 29986264
curTimeStampUS 30055252
periodUS 68988

iteration 14
prevTimeStampUS 30055252
curTimeStampUS 30134352
periodUS 79100

iteration 19
prevTimeStampUS 30134352
curTimeStampUS 30221712
periodUS 87360

iteration 24
prevTimeStampUS 30221712
curTimeStampUS 30309072
periodUS 87360

iteration 26
prevTimeStampUS 30309072
curTimeStampUS 30396436
periodUS 87364

iteration 31
prevTimeStampUS 30396436
curTimeStampUS 30483792
periodUS 87356

iteration 36
prevTimeStampUS 30483792
curTimeStampUS 30571152
periodUS 87360

iteration 41
prevTimeStampUS 30571152
curTimeStampUS 30658512
periodUS 87360

iteration 49
prevTimeStampUS 30658512
curTimeStampUS 30745872
periodUS 87360

iteration 55
prevTimeStampUS 30745872
curTimeStampUS 30833232
periodUS 87360

iteration 61
prevTimeStampUS 30833232
curTimeStampUS 30920592
periodUS 87360

iteration 65
prevTimeStampUS 30920592
curTimeStampUS 31007952
periodUS 87360

iteration 75
prevTimeStampUS 31007952
curTimeStampUS 31095312
periodUS 87360

iteration 82
prevTimeStampUS 31095312
curTimeStampUS 31182672
periodUS 87360

iteration 90
curTimeStampUS 31270032
periodUS 87360

iteration 97
prevTimeStampUS 31270032
curTimeStampUS 31357392
periodUS 87360

iteration 105
prevTimeStampUS 31357392
curTimeStampUS 31445792
periodUS 88400

iteration 115
prevTimeStampUS 31445792
curTimeStampUS 31534192
periodUS 88400

iteration 121
prevTimeStampUS 31534192
curTimeStampUS 31622592
periodUS 88400

iteration 130
prevTimeStampUS 31622592
curTimeStampUS 31710992
periodUS 88400

iteration 140
prevTimeStampUS 31710992
curTimeStampUS 31799392
periodUS 88400

iteration 150
prevTimeStampUS 31799392
curTimeStampUS 31887792
periodUS 88400

iteration 160
prevTimeStampUS 31887792
curTimeStampUS 31976192
periodUS 88400

iteration 170
prevTimeStampUS 31976192
curTimeStampUS 32064592
periodUS 88400

iteration 178
prevTimeStampUS 32064592
curTimeStampUS 32152992
periodUS 88400

iteration 187
prevTimeStampUS 32152992
curTimeStampUS 32241392
periodUS 88400

iteration 196
prevTimeStampUS 32241392
curTimeStampUS 32329792
periodUS 88400

iteration 208
prevTimeStampUS 32329792
curTimeStampUS 32418192
periodUS 88400

iteration 218
prevTimeStampUS 32418192
curTimeStampUS 32506592
periodUS 88400

iteration 231
prevTimeStampUS 32506592
curTimeStampUS 32594992
periodUS 88400

iteration 242
prevTimeStampUS 32594992
curTimeStampUS 32683392
periodUS 88400

iteration 255
prevTimeStampUS 32683392
curTimeStampUS 32771792
periodUS 88400

iteration 266
prevTimeStampUS 32771792
curTimeStampUS 32860192
periodUS 88400

iteration 281
prevTimeStampUS 32860192
curTimeStampUS 32948592
periodUS 88400

iteration 293
prevTimeStampUS 32948592
curTimeStampUS 33036992
periodUS 88400

I started the trigger wheel from stop and accelerated it for 288 iterations. The logic analyzer capture shows the first period to be 132,900 microseconds. The last one is 14,905 microseconds. The serial print records don't make any sense to me so I must be doing something wrong.

Post the sketch as it is now.

There is code in the core to take care of printing when interrupts are turned off so you don't get stuck forever but it is still a very bad idea to do it.

You can also speed up your serial printing a lot, 9600 baud was the standard in the 1980s....
Make sure to adjust your Serial Monitor baud rate to match.

  //Serial.begin(9600);
  Serial.begin(115200);

You have succeeded in duplicating the long interrupt time by only turning off the Boolean in your loop() AFTER you have done the same serial printing as you previously did in the interrupt code. That gives you the same problem as you had before!

Here is my latest code. I believe it is as was suggested I use.

// ************************ Program constants **************************:
// - Pin numbers -:
const byte triggerPin = 19;         // Trigger  input on pin 19

// ************************ Global Variables ***************************:
volatile unsigned long curTimeStampUS;   // Current microsecond time stamp
volatile unsigned long prevTimeStampUS;  // Previous microsecond time stamp
volatile unsigned long periodUS;         // Period between time stamps
volatile unsigned long iteration;        // Iteration counter
bool flag = true;

// ************************ Program Functions **************************:

// -------------------------------------------------:
// ISR Function to calculate period between trigger inputs.
void triggerInput()
{ // Start of triggerInput ISR
  iteration++;                                   // Increment iteration (For program developement)
  flag = true;                                   // Set the flag true
}// End of triggerInput ISR

// -------------------------------------------------:

//   The setup function will only run once, after each powerup or reset of Arduino. 
void setup()
{ // Start of setup function
   curTimeStampUS = 0;   // Current microsecond time stamp initialized with 0
   prevTimeStampUS = 0;  // Previous microsecond time stamp initialized with 0
   periodUS = 0;         // Period between time stamps initialized with 0
   iteration = 0;        // Iteration counter initialized with 0
   attachInterrupt (digitalPinToInterrupt (triggerPin), triggerInput, RISING);  //  pulseIn() function is called  when pin 19 goes from Low to High
   Serial.begin(115200);                   // Initialize serial communication at 9600 bits per second(for program developement)
 } // End of setup function  

// - The loop() function contains the main program loop.
void loop()
{ // Start of loop function
  if (flag == true) {
    Serial.print("iteration ");                   // For program developement
    Serial.println(iteration);                     // For program developement
    Serial.print("prevTimeStampUS ");             // For program developement
    Serial.println(prevTimeStampUS);               // For program developement
    curTimeStampUS = micros();                     // Get the current microsecond time stamp
    Serial.print("curTimeStampUS ");              // For program developement
    Serial.println(curTimeStampUS);                // For program developement
    periodUS = curTimeStampUS - prevTimeStampUS;   // Tooth period = current time stamp minus the previous one
    Serial.print("periodUS ");                    // For program developement
    Serial.println(periodUS);                      // For program developement
    Serial.println(" ");
    flag = false;
    prevTimeStampUS = curTimeStampUS;
  } 
} // End of loop function 

Here is the the partial serial.print print out:
iteration 0
prevTimeStampUS 0
curTimeStampUS 384
periodUS 384

iteration 6
prevTimeStampUS 384
curTimeStampUS 17055544
periodUS 17055160

iteration 9
prevTimeStampUS 17055544
curTimeStampUS 17105812
periodUS 50268

iteration 10
prevTimeStampUS 17105812
curTimeStampUS 17122512
periodUS 16700

iteration 11
prevTimeStampUS 17122512
curTimeStampUS 17139196
periodUS 16684

iteration 12
prevTimeStampUS 17139196
curTimeStampUS 17155856
periodUS 16660

iteration 13
prevTimeStampUS 17155856
curTimeStampUS 17172544
periodUS 16688

iteration 14
prevTimeStampUS 17172544
curTimeStampUS 17189224
periodUS 16680

iteration 15
prevTimeStampUS 17189224
curTimeStampUS 17205908
periodUS 16684

iteration 20
prevTimeStampUS 17205908
curTimeStampUS 17255108
periodUS 49200

iteration 22
prevTimeStampUS 17255108
curTimeStampUS 17272636
periodUS 17528

iteration 23
prevTimeStampUS 17272636
curTimeStampUS 17289320
periodUS 16684

iteration 24
prevTimeStampUS 17289320
curTimeStampUS 17306012
periodUS 16692

iteration 26
prevTimeStampUS 17306012
curTimeStampUS 17310284
periodUS 4272

iteration 29
prevTimeStampUS 17310284
curTimeStampUS 17442856
periodUS 132572

iteration 30
prevTimeStampUS 17442856
curTimeStampUS 17456120
periodUS 13264

iteration 31
prevTimeStampUS 17456120
curTimeStampUS 17472788
periodUS 16668

iteration 33
prevTimeStampUS 17472788
curTimeStampUS 17488324
periodUS 15536

iteration 36
prevTimeStampUS 17488324
curTimeStampUS 17524516
periodUS 36192

iteration 37
prevTimeStampUS 17524516
curTimeStampUS 17539548
periodUS 15032

iteration 38
prevTimeStampUS 17539548
curTimeStampUS 17556200
periodUS 16652

iteration 40
prevTimeStampUS 17556200
curTimeStampUS 17565912
periodUS 9712

iteration 43
prevTimeStampUS 17565912
curTimeStampUS 17599720
periodUS 33808

iteration 44
prevTimeStampUS 17599720
curTimeStampUS 17606252
periodUS 6532

iteration 45
prevTimeStampUS 17606252
curTimeStampUS 17622924
periodUS 16672

iteration 47
prevTimeStampUS 17622924
curTimeStampUS 17638200
periodUS 15276

iteration 50
prevTimeStampUS 17638200
curTimeStampUS 17669828
periodUS 31628

iteration 51
prevTimeStampUS 17669828
curTimeStampUS 17674096
periodUS 4268

iteration 52
prevTimeStampUS 17674096
curTimeStampUS 17689656
periodUS 15560

iteration 53
prevTimeStampUS 17689656
curTimeStampUS 17705992
periodUS 16336

iteration 56
prevTimeStampUS 17705992
curTimeStampUS 17735624
periodUS 29632

iteration 57
prevTimeStampUS 17735624
curTimeStampUS 17739904
periodUS 4280

iteration 58
prevTimeStampUS 17739904
curTimeStampUS 17756356
periodUS 16452

iteration 60
prevTimeStampUS 17756356
curTimeStampUS 17770024
periodUS 13668

iteration 63
prevTimeStampUS 17770024
curTimeStampUS 17797716
periodUS 27692

iteration 64
prevTimeStampUS 17797716
curTimeStampUS 17806392
periodUS 8676

iteration 65
prevTimeStampUS 17806392
curTimeStampUS 17823072
periodUS 16680

iteration 67
prevTimeStampUS 17823072
curTimeStampUS 17829344
periodUS 6272

iteration 70
prevTimeStampUS 17829344
curTimeStampUS 17855596
periodUS 26252

iteration 72
prevTimeStampUS 17855596
curTimeStampUS 17873136
periodUS 17540

iteration 74
prevTimeStampUS 17873136
curTimeStampUS 17885548
periodUS 12412

iteration 77
prevTimeStampUS 17885548
curTimeStampUS 17910648
periodUS 25100

iteration 78
prevTimeStampUS 17910648
curTimeStampUS 17923160
periodUS 12512

iteration 79
prevTimeStampUS 17923160
curTimeStampUS 17938836
periodUS 15676

iteration 82
prevTimeStampUS 17938836
curTimeStampUS 17962452
periodUS 23616

iteration 83
prevTimeStampUS 17962452
curTimeStampUS 17973212
periodUS 10760

iteration 84
prevTimeStampUS 17973212
curTimeStampUS 17989248
periodUS 16036

iteration 87
prevTimeStampUS 17989248
curTimeStampUS 18011736
periodUS 22488

iteration 88
prevTimeStampUS 18011736
curTimeStampUS 18023228
periodUS 11492

iteration 89
prevTimeStampUS 18023228
curTimeStampUS 18037772
periodUS 14544

iteration 92
prevTimeStampUS 18037772
curTimeStampUS 18059216
periodUS 21444

iteration 93
periodUS 14068

iteration 95
prevTimeStampUS 18073284
curTimeStampUS 18084092
periodUS 10808

iteration 98
prevTimeStampUS 18084092
curTimeStampUS 18104836
periodUS 20744

iteration 99
prevTimeStampUS 18104836
curTimeStampUS 18109108
periodUS 4272

iteration 100
prevTimeStampUS 18109108
curTimeStampUS 18123364
periodUS 14256

iteration 102
prevTimeStampUS 18123364
curTimeStampUS 18129036
periodUS 5672

iteration 105
prevTimeStampUS 18129036
curTimeStampUS 18148884
periodUS 19848

iteration 106
prevTimeStampUS 18148884
curTimeStampUS 18156732
periodUS 7848

iteration 108
prevTimeStampUS 18156732
curTimeStampUS 18172004
periodUS 15272

I just did a short trigger run, about 231 iterations. The logic capture showed the first period as 81,670 microseconds. The shortest period before the trigger wheel coasted down was 11,404 microseconds.
I am using a 36 minus 1 trigger wheel and a hall effect gear tooth sensor. The trigger teeth are 10 degrees of rotation apart except for where the missing tooth is . That period is for 20 degrees of rotation. As the wheel starts to turn I am expecting the period between teeth to steadily decrease as the speed increases. When the missing tooth is reached the period will be about twice as long as the previous period. I'm not seeing that on the print out. The print outs show that the iterations are not all consecutive, and none of the periods really make sense. I don't know what is causing this.

Turn interrupts OFF.
Save iterations to a separate variable.
Move 0 to iterations.
Turn interrupts back on.
Continue code using the new variable.

In Serial Monitor, please turn on the timestamp feature, so we can get a feel for how often you're printing.

OK. I think this is what you want me to try:

// ************************ Program constants **************************:
// - Pin numbers -:
const byte triggerPin = 19;         // Trigger  input on pin 19

// ************************ Global Variables ***************************:
volatile unsigned long curTimeStampUS;   // Current microsecond time stamp
volatile unsigned long prevTimeStampUS;  // Previous microsecond time stamp
volatile unsigned long periodUS;         // Period between time stamps
volatile unsigned long iteration;        // Iteration counter
bool flag = true;
unsigned long iteration2;

// ************************ Program Functions **************************:

// -------------------------------------------------:
// ISR Function to calculate period between trigger inputs.
void triggerInput()
{ // Start of triggerInput ISR
  iteration++;                                   // Increment iteration (For program developement)
  flag = true;                                   // Set the flag true
}// End of triggerInput ISR

// -------------------------------------------------:

//   The setup function will only run once, after each powerup or reset of Arduino. 
void setup()
{ // Start of setup function
   curTimeStampUS = 0;   // Current microsecond time stamp initialized with 0
   prevTimeStampUS = 0;  // Previous microsecond time stamp initialized with 0
   periodUS = 0;         // Period between time stamps initialized with 0
   iteration = 0;        // Iteration counter initialized with 0
   iteration2 = 0;
   attachInterrupt (digitalPinToInterrupt (triggerPin), triggerInput, RISING);  //  pulseIn() function is called  when pin 19 goes from Low to High
   Serial.begin(115200);                   // Initialize serial communication at 9600 bits per second(for program developement)
 } // End of setup function  

// - The loop() function contains the main program loop.
void loop()
{ // Start of loop function
  if (flag == true) {
    cli ();                                           // Interrupts disabled
    iteration2 = iteration;                        // Save iteration as iteration2
    iteration = 0;                                 // Clear iteration
    sei();                                           // Interrupts enabled
    Serial.print("iteration2 ");                   // For program developement
    Serial.println(iteration2);                     // For program developement
    Serial.print("prevTimeStampUS ");             // For program developement
    Serial.println(prevTimeStampUS);               // For program developement
    curTimeStampUS = micros();                     // Get the current microsecond time stamp
    Serial.print("curTimeStampUS ");              // For program developement
    Serial.println(curTimeStampUS);                // For program developement
    periodUS = curTimeStampUS - prevTimeStampUS;   // Tooth period = current time stamp minus the previous one
    Serial.print("periodUS ");                    // For program developement
    Serial.println(periodUS);                      // For program developement
    Serial.println(" ");
    flag = false;
    prevTimeStampUS = curTimeStampUS;
  } 
} // End of loop function 

Here is the partial serial monitor print out:
16:39:07.988 -> iteration2 0
16:39:07.988 -> prevTimeStampUS 0
16:39:07.988 -> curTimeStampUS 392
16:39:07.988 -> periodUS 392
16:39:07.988 ->
16:39:22.853 -> iteration2 2
16:39:22.853 -> prevTimeStampUS 392
16:39:22.853 -> curTimeStampUS 14860152
16:39:22.853 -> periodUS 14859760
16:39:22.853 ->
16:39:22.853 -> iteration2 7
16:39:22.853 -> prevTimeStampUS 14860152
16:39:22.853 -> curTimeStampUS 14878512
16:39:22.853 -> periodUS 18360
16:39:22.922 ->
16:39:22.922 -> iteration2 1
16:39:22.922 -> prevTimeStampUS 14878512
16:39:22.922 -> curTimeStampUS 14895240
16:39:22.922 -> periodUS 16728
16:39:22.922 ->
16:39:22.922 -> iteration2 1
16:39:22.922 -> prevTimeStampUS 14895240
16:39:22.922 -> curTimeStampUS 14911948
16:39:22.929 -> periodUS 16708
16:39:22.929 ->
16:39:22.929 -> iteration2 1
16:39:22.929 -> prevTimeStampUS 14911948
16:39:22.929 -> curTimeStampUS 14945316
16:39:22.956 -> periodUS 33368
16:39:22.956 ->
16:39:22.956 -> iteration2 1
16:39:22.956 -> prevTimeStampUS 14945316
16:39:22.956 -> curTimeStampUS 14961988
16:39:22.956 -> periodUS 16672
16:39:22.956 ->
16:39:23.001 -> iteration2 1
16:39:23.001 -> prevTimeStampUS 14961988
16:39:23.001 -> curTimeStampUS 14995324
16:39:23.001 -> periodUS 33336
16:39:23.001 ->
16:39:23.001 -> iteration2 1
16:39:23.001 -> prevTimeStampUS 14995324
16:39:23.001 -> curTimeStampUS 15012024
16:39:23.001 -> periodUS 16700
16:39:23.001 ->
16:39:23.001 -> iteration2 1
16:39:23.001 -> prevTimeStampUS 15012024
16:39:23.032 -> curTimeStampUS 15028700
16:39:23.032 -> periodUS 16676
16:39:23.032 ->
16:39:23.032 -> iteration2 1
16:39:23.032 -> prevTimeStampUS 15028700
16:39:23.032 -> curTimeStampUS 15045372
16:39:23.032 -> periodUS 16672
16:39:23.032 ->
16:39:23.032 -> iteration2 1
16:39:23.032 -> prevTimeStampUS 15045372
16:39:23.065 -> curTimeStampUS 15062064
16:39:23.065 -> periodUS 16692
16:39:23.065 ->
16:39:23.065 -> iteration2 1
16:39:23.065 -> prevTimeStampUS 15062064
16:39:23.065 -> curTimeStampUS 15078748
16:39:23.065 -> periodUS 16684
16:39:23.065 ->
16:39:23.065 -> iteration2 1
16:39:23.065 -> prevTimeStampUS 15078748
16:39:23.098 -> curTimeStampUS 15095432
16:39:23.098 -> periodUS 16684
16:39:23.098 ->
16:39:23.098 -> iteration2 1
16:39:23.098 -> prevTimeStampUS 15095432
16:39:23.098 -> curTimeStampUS 15112108
16:39:23.098 -> periodUS 16676
16:39:23.098 ->
16:39:23.098 -> iteration2 1
16:39:23.098 -> prevTimeStampUS 15112108
16:39:23.134 -> curTimeStampUS 15128792
16:39:23.134 -> periodUS 16684
16:39:23.134 ->

Does that tell us anything?

As I suspected, you're pumping a lot of serial data. For instance, above, you're pushing 154 characters in the 23.065 interval(36 ms); that's ~5char per ms, which is okay at 115 kbaud, but just. To be sure this isn't affecting your measurement, try doing the following:
change ONLY prevTimeStampUS to pUS, curTimeStampUS to cUS, periodUS to pUS, and iteration2 to i2.
Then rerun your test, to see if you've alleviated serial 'constipation'.
Adding serial output to code is an art; the more you add output for clarity, the more likely you deleteriously affect test conditions. Brevity is necessary.
To be clear, I'm not sure this is going to be fruitful, but it cannot hurt.

16:39:22.929 -> periodUS 16708
16:39:22.929 ->
16:39:22.929 -> iteration2 1
16:39:22.929 -> prevTimeStampUS 14911948
16:39:22.929 -> curTimeStampUS 14945316
16:39:22.956 -> periodUS 33368
16:39:22.956 ->
16:39:22.956 -> iteration2 1
16:39:22.956 -> prevTimeStampUS 14945316
16:39:22.956 -> curTimeStampUS 14961988
16:39:22.956 -> periodUS 16672
16:39:22.956 ->
16:39:23.001 -> iteration2 1

And this clearly shows your 'missing tooth' event.

Thanks for the suggestion, but that didn't help anything either.
It's as if my variables and flags aren't being found by the program. Is there a special way to declare them as globals? I've studied Nick Gammons notes on interrupts and it is my understanding that only variables that are used both within the interrupt and the main program need to be declared as volatile. I know he said not to use serial.prints but I tried it anyway to see what would happen. I'm going to write another small troubleshooting routine without serial.prints and attack it from another angle. Maybe that will flush something out. I should be able have that done tonight or tomorrow and will post it then. Thanks again for the suggestions so far.

OK. I've tried a different approach.

// Program constants:
const byte pinD12 = 12;    // Output on pin D12, PB6, Output Compare 1B
const byte pinD11 = 11;    // Output on pin D11, PB5, Output Compare 1A
const byte pinD7 = 7;      // Output on pin D7, PH4, Output Compare 4B
const byte pinD6 = 6;      // Output on pin D6, PH3, Output Compare 4A
const byte pinD5 = 5;      // Output on pin D5, PE3, Output Compare 3A
const byte pinD19 = 19;    // ISR input on pin D19, INT2 
const byte pinD45 = 45;    // Output on pin D45, PL4
const byte pinD49 = 49;    // Output on pin D49, PL0 (Debug output)

// Program variables:
volatile bool ckpFlag;                       // Flag to tell the main loop that we have just had falling edge on pin 19
volatile unsigned int iteration;
volatile unsigned long curTimeStampUS;       // Current microsecond time stamp
volatile unsigned long prevTimeStampUS;      // Previous microsecond time stamp
volatile unsigned long curToothPeriod;       // Period between time stamps
volatile unsigned long prevToothPeriod;      // Previous period between time stamps
volatile bool periodOKFlag;                  // Flag to indicate that the interrupt period is great enough not to be noise and short enough that 
                                             // calculations that us the period can be doen without overflow 
volatile byte pinD49State;                   // Debug output state

void pinD19Interrupt()
{
//  iteration++;
  ckpFlag = true;
}

void setup()
{
  pinMode(pinD12, OUTPUT);         // Declare  pinD12 an output
  digitalWrite(pinD12, LOW);       // Initialize pinD12 LOW 
  pinMode(pinD11, OUTPUT);         // Declare  pinD11 an output
  digitalWrite(pinD11, LOW);       // Initialize pinD11 LOW
  pinMode(pinD7, OUTPUT);          // Declare  pinD7 an output
  digitalWrite(pinD7, LOW);        // Initialize pinD7 LOW
  pinMode(pinD6, OUTPUT);          // Declare  pinD6 an output
  digitalWrite(pinD6, LOW);        // Initialize pinD6 LOW
  pinMode(pinD5, OUTPUT);          // Declare  pinD5 an output
  digitalWrite(pinD5, LOW);        // Initialize pinD5 LOW
  pinMode(pinD45, OUTPUT);         // Declare  pinD45 an output
  digitalWrite(pinD45, LOW);       // Initialize pinD45 LOW
  pinMode(pinD49, OUTPUT);         // Declare  pinD49 an output
  digitalWrite(pinD49, LOW);       // Initialize pinD49 LOW
  attachInterrupt(digitalPinToInterrupt(pinD19), pinD19Interrupt, FALLING); // Attach pinD19 to pinD19 Interrupt() ISR function, interrupt on falling edge
//  Serial.begin(115200);            // Initialize serial communication at 115200 bits per second(for program developement)
  ckpFlag = false;
//  iteration = 0;
  periodOKFlag = false;
  pinD49State = LOW;       
}

void loop()
{
  if(ckpFlag == true)
  {
//    iteration++;
//    Serial.println(iteration); // (For program developement)
    curTimeStampUS = micros();                         // Get the current microsecond time stamp
    curToothPeriod = curTimeStampUS - prevTimeStampUS; // Tooth period = current time stamp minus the previous one
    prevToothPeriod = curToothPeriod;                  // Save the current tooth period as the previous tooth period
    prevTimeStampUS = curTimeStampUS;                  // Save the current time stamp as the previous time stamp

    if(periodOKFlag == false)
    {
     if((curToothPeriod > 20000) && (curToothPeriod< 40000))
      {
        periodOKFlag = true;
      }
        if(periodOKFlag == true)
        {
//          Serial.println(curToothPeriod); // (For program developement)
         digitalWrite(pinD49, pinD49State);     // Copy pinD49State to pinD49
         pinD49State = !pinD49State;            // Toggle pinD49State
        }
     }
       ckpFlag = false;
  }
}

The ISR now just sets a flag to tell the main loop that an interrupt has occurred. I've eliminated the serial prints for de-bugging and just use output pin states. The program works fine until it sets the periodOKFlag. From then on I don't get any more interrupts. Can anyone see where I've gone wrong?

You never reset the periodOKFlag so your if() statement will never be true which means you will never change pinD49 state again after the first time.

Did I not do it correctly here?

You set periodOKFflag to true but it never gets reset back to false so after the initial period, that code will never execute again, including the code that toggles D49.

Right. At this point the speed of the trigger wheel is increasing and the periods are getting smaller so there is no need to test the period for minimum any more. I will test it again when the revs drop but I haven't included that test here.
What I am trying to do when I set the periodOKFlag to true is to be able to go ahead and do the calculations with the period. I thought I had this covered with:

        if(periodOKFlag == true)
        {
//          Serial.println(curToothPeriod); // (For program developement)
         digitalWrite(pinD49, pinD49State);     // Copy pinD49State to pinD49
         pinD49State = !pinD49State;            // Toggle pinD49State
        }
     }

How would you suggest I do it differently?

I tried something even simpler and I'm still l having problems. With this one the interrupt will only occur once. I must be missing a very basic principle here.

// interruptTest3:

// How it is supposed to work:
// ISR(TIMER2_OVF_vect) generates a 100mS time rate. At each each 100mS time interval pin D45 and pin D49 are toggled. Pin D45 is monitored by a digital 
// signal analyzer. The output pin D49 is wired to the the input pin D19 to provide a signal for the interrupt routine. On each falling edge of pinD49 
// the ISR will echo the state of pinD49State. PinD12 is monitored by the digital signal analyzer.

// How it is working:
// The trace for pinD45 is correct. A square wave ~5 volt signal every 100mS. On reset pinD12 is low and goes high with the first corresponding high to
// low state of pinD45, which was expected. Then it stays high with no more ISRs.
// What have I done wrong here?


// Program constants:
const byte pinD12 = 12;    // Output on pin D12, PB6, Output Compare 1B
const byte pinD19 = 19;    // ISR input on pin D19, INT2 
const byte pinD45 = 45;    // Output on pin D45, PL4
const byte pinD49 = 49;    // Output on pin D49, PL0

// Time rate generator variables:
volatile int count100ms;              // Counter to signal 100mS events (1000 of 100uS interrupts)

// Program developement variables
volatile byte pinD45State;
volatile byte pinD49State;


void pinD19Interrupt()
{
  digitalWrite(pinD12, pinD49State);
}

ISR(TIMER2_OVF_vect)
{
  count100ms++;  // Increment the 100 mS counter
// Loop executed every 100mS (1mS x 100 = 100mS). Anything inside this if statement will run every 100mS.
      if(count100ms == 100) 
      {
        count100ms = 0;                        // Reset the 100mS counter.
        digitalWrite(pinD45, pinD45State);     // Copy pinD45State to pinD45
        pinD45State = !pinD45State;            // Toggle pinD45State
        digitalWrite(pinD49, pinD49State);     // Copy pinD49State to pinD49 // NOTE! Pin D49 is jumpered to pin D19
        pinD49State = !pinD49State;            // Toggle pinD45State


      }
//Reset Timer2 to trigger in another ~100uS 
    TCNT2 = 131;     // Timer/Counter 2: //Preload timer2 with 131 cycles, leaving 125 till overflow. Testing shows this to be very close to a 1mS interrupt. 
    TIFR2 = 0x00;    // Timer/Counter 2 Interrupt Flag Register:  //Timer2 INT Flag Reg: Clear Timer Overflow Flag
}

void setup()
{
  pinMode(pinD12, OUTPUT);         // Declare  pinD12 an output
  digitalWrite(pinD12, LOW);       // Initialize pinD12 LOW 
  pinMode(pinD45, OUTPUT);         // Declare  pinD45 an output
  digitalWrite(pinD45, LOW);       // Initialize pinD45 LOW
  pinMode(pinD49, OUTPUT);         // Declare  pinD49 an output
  digitalWrite(pinD49, LOW);       // Initialize pinD49 LOW
  pinMode(pinD19, INPUT);          // Declare pinD19 an input
  attachInterrupt(digitalPinToInterrupt(pinD19), pinD19Interrupt, FALLING); // Attach pinD19 to pinD19 Interrupt() ISR function, interrupt on falling edge

  count100ms = 0;
  pinD45State = 0;
  pinD49State = 0;

// Set up for Time Rate Generator ISR:
//Configure 8 bit Timer2 to interrupt every 100 microseconds: 
   TCCR2B = 0x00;  // Timer/Counter 2 Control Register B:      //Disable Timer2 while we set it up
   TCNT2  = 131;   // Timer/Counter 2: //Preload timer2 with 131 cycles, leaving 125 till overflow. Testing shows this to be very close to a 1mS interrupt. 
   TIFR2  = 0x00;  // Timer/Counter 2 Interrupt Flag Register: //Timer2 INT Flag Reg: Clear Timer Overflow Flag
   TIMSK2 = 0x01;  // Timer/Counter 2 Interrupt Mask Register: //Timer2 Set Overflow Interrupt enabled.
   TCCR2A = 0x00;  // Timer/Counter 2 Control Register A:      //Timer2 Control Reg A: Wave Gen Mode normal
// Now configure the prescaler to CPU clock divided by 128 = 125Khz 
   TCCR2B = B00000101; // Prescale = 5  (2048uS interrupt) 
}

void loop()
 {
 }