     
             SpeedCyclometer_revPs = 1000.0 / WheelRev_ms;
             SpeedCyclometer_mmPs  = 
-            data->oldSpeed_mmPs = Circum_mm * SpeedCyclometer_revPs;
+          data->oldSpeed_mmPs = Circum_mm * SpeedCyclometer_revPs;
             data->oldTime_ms = data->TickTime_ms;  // time stamp for oldSpeed_mmPs
             data->oldClickNumber = data->nowClickNumber;
         }
     }
+    if(data->nowTime_ms - data->TickTime_ms > WheelRev_ms)
+    {  // at this speed, should have already gotten a tick?; If so, we are slowing.
+        float SpeedSlowing_revPs = 1000.0 / (data->nowTime_ms - data->TickTime_ms);
+        long SpeedSlowing_mmPs  = Circum_mm * SpeedCyclometer_revPs;                 
+        SpeedCyclometer_revPs = min(SpeedCyclometer_revPs, SpeedSlowing_revPs);
+        SpeedCyclometer_mmPs  = min(SpeedCyclometer_mmPs, SpeedSlowing_mmPs);
+   }
     return;
 }
 /*---------------------------------------------------------------------------------------*/ 
-
+void PrintSpeed( struct hist *data)
+{
+      Serial.print(SpeedCyclometer_mmPs); Serial.print("\t");
+      Serial.print(data->InterruptState); Serial.print("\t");
+      Serial.print(data->oldSpeed_mmPs); Serial.print("\t");
+      Serial.print(data->olderSpeed_mmPs); Serial.print("\t");
+      Serial.print(data->oldClickNumber); Serial.print("\t");
+      Serial.print(data->nowClickNumber); Serial.print("\t");
+      Serial.print(data->olderTime_ms); Serial.print("\t");
+      Serial.print(data->oldTime_ms); Serial.print("\t");      
+      Serial.print(data->nowTime_ms); Serial.print("\t");
+      Serial.print(data->TickTime_ms); Serial.print("\t");
+      Serial.println(data->OldTick_ms);
+}
+/*---------------------------------------------------------------------------------------*/ 
 void show_speed(SerialData *Results)
 {
    history.nowTime_ms = millis();       

            }
            else
            {  // accelerating; should get new data soon
                if(data->nowTime_ms - data->oldTime_ms > MaxTickTime_ms)
                {  // too long without getting a tick
                    SpeedCyclometer_mmPs = 0;
                    SpeedCyclometer_revPs = 0;
                }
            }
        }


#include <SPI.h>
#include <Elcano_Serial.h>
#define LOOP_TIME_MS 400
#define ERROR_HISTORY 20

// Orange Trike
