module: time_to_digital_period_avg
parameters: int avg_length
inputs: double in_rising, double in_falling, double clk
outputs: double out
classes: List avg_list(), Filter avg("1","1"), EdgeDetect clkedge()
static_variables:
init:
int i;
double val;

if (avg_length < 1)
  {
   printf("error in 'time_to_digital_period_avg':\n");
   printf("  parameter 'avg_length' must be > 0\n");
   printf("  in this case, avg_length = %d\n",avg_length);
   exit(1);
  }
val = 1/((double) avg_length);

// create an FIR filter of length avg_length
for (i = 0; i < avg_length; i++)
   avg_list.inp(val);
avg.set(avg_list,"1");
avg.reset(1.0);
out = 1.0;

code:
double diff;

if (clkedge.inp(clk))
  {
  diff = in_rising - in_falling;
  if (diff < 0.0)
     diff = -diff;  
  avg.inp(diff);
  out=2.0*avg.out;
  }

