module: comparator_basic
description: 
parameters:  double voffset
inputs:  double in_pos, double in_neg
             double_interp clk
outputs:  double_interp out
classes:  EdgeDetect clk_edge()
static_variables:  int state, double prev_in_val, double out_prev
init:  
out = -1.0;
out_prev = -1.0;
state = 0;
prev_in_val = 0.0;
end:  
code:
double in_val, in_val_interp;
  
out = out_prev;

if (state == 0)
    out_prev = -1.0;
else if (state == 1)
    out_prev = 1.0;

in_val = in_pos - in_neg - voffset;

if (clk_edge.inp(clk))
  {
   in_val_interp = prev_in_val*(1.0 + clk)/2.0 + in_val*(1.0-clk)/2.0;
   if (in_val_interp > 0.0)
      {
       if (state == 0)
         {
          state = 1;
          out_prev = clk;
         }
      }
   else
      {   
       if (state == 1)
         {
          state = 0;
          out_prev = -clk;
         }      
      }
  }

prev_in_val = in_val;
