 // TICC.ino - master sketch file
 
 // TICC Time interval Counter based on TICC Shield using TDC7200
-// version 0.60 -- 30 July 2016
+// version 0.62 -- 6 August 2016
 
 // Copyright John Ackermann N8UR 2016
 // Portions Copyright George Byrkit K9TRV 2016

  Serial.print(" cal2Result="), Serial.println(cal2Result);
*/
  
  long ringticks;            //  time1Result - time2Result, unitless
  long ringps;               // ps per ring cycle, picosends, result of calibration formula, nominal 55ps 
  long ringtime;             // ringticks * ringperiod, picoseconds
  unsigned long clocktime;   // clock1Result * CLOCK_PERIOD, picoseconds
  unsigned long tof;         // clocktime - ringtime, picoseconds; "time of flight" per datasheet

  // get ringperiod.  Datasheet says: (cal2Result - cal1Result)/(cal2Periods - 1)
  
  // TODO: 
  // 1. refactor so that we get 0.1ps effective ringps precision in the ringtime calculation
  // 2. optimize!!!
  ringps = CLOCK_PERIOD_PS / ((cal2Result - cal1Result)/(CALIBRATION2_PERIODS -1));
  ringticks = time1Result - time2Result;
  ringtime = ringticks * ringps;
  
  clocktime = clock1Result * CLOCK_PERIOD_PS;
  tof = clocktime - ringtime - FUDGE0_PS;  //FUDGE0 compensates for propagation delays
    
  /*  
  Serial.print(" ringps: ");Serial.print(ringps);


/**************************************************************************************/
 
// ISR for timer. 
void coarseTimer() {
  PICcount++;
}
