module period_measure(in); input in; voltage in; parameter real vth=0; integer crossings; real latest,previous; analog begin @(initial_step) begin crossings=0;previous=0;latest=0; end @(cross(V(in)-vth,+1)) begin crossings=crossings+1; previous=latest; latest=$realtime; end @(final_step) begin if (crossings < 2) $strobe("Could not measure period.\n"); else $strobe("period = %g, crossings = %d\n", latest-previous,crossings); end end endmodule