//////////////////////////////////// 
// Instantaneous Frequency Meter ///
// Fuding Ge  fudingge@yahoo.com ///
////////////////////////////////////

// This verilogA model will output the frequency of the input
// based on the instantaneous period of input clock siganl

// You need to change the value of hlfvcc to match the power supply
// of the clock signal. In this version vcc=2.5 and hlfvcc=1.25
// The time of the first transition is unknown, so it is discarded 
// and the frequency always begin at 0 Hz

`include "constants.h"
`include "discipline.h"

nature Frequency
	abstol = 1m;
	access = FF;
	units = "Hz";
	blowup = 1.0e10;
endnature

discipline freq_current
	potential Frequency;
	flow Current;
enddiscipline
   


module Fremeter(vin,fout);

input vin;
output fout;

freq_current fout;
electrical vin;


   real tlatest;
   real tearly;
   real fout_val;
   real hlfvcc;
   integer counter;
   
   analog begin
	
      @ ( initial_step ) begin
        tearly=0;
        tlatest=1.0; 
        hlfvcc=1.25;          //Change your hlfvcc here !
	counter =0;
      end
     

      @ ( cross ((V(vin)-hlfvcc),+1 )) begin
         tlatest = $realtime;
	 fout_val =  1/(tlatest-tearly);
         tearly = tlatest;
	 counter = counter +1;
      end
         if (counter == 1)
         FF(fout) <+ 0.0;
         else
         FF(fout) <+ fout_val;
    end
	
endmodule

















    Source: geocities.com/fudinggepll/model

               ( geocities.com/fudinggepll)