   SUMPreset();
 }
 
-
 inline void waitForTimeout (void)
 {
-  #ifdef TIMING_DISCRETES     
+  #ifdef TIMING_DISCRETES
     digitalWriteFast (TIMING_PIN_0, HIGH);
   #endif
+
+#if Teensy_4_0
+
+  // TODO: this handles rollover but takes extra cpu cycles
+  //  while (ARM_DWT_CYCCNT - previousSampleTime < cpuClockCycles) ; // wait
+  while (ARM_DWT_CYCCNT < cpuClockCycles + previousSampleTime) ; // wait
+
+  previousSampleTime += cpuClockCycles;
+
+#else
 
   // for speed, to reduce jitter
   if (TIMER_FLAG_REGISTER)


      sumpSetup.cpuClockTicks = F_CPU / sumpSetup.clockFrequency;

      break;

    case SUMP_CAPTURE_COUNT:

//   Serial : interface to SUMP user interface
//   Serial1/2/3 : debug info (if turned on)

// define the various types of Teensy's

// Teensy 3.0
