// R2E.vams - basic Verilog-AMS discrete wreal to electrical connection module
// last revised:  08/01/06, jhou
//
// REVISION HISTORY:
// Created:  08/01/06, jhou

`include "disciplines.vams"
`timescale 1ns / 100ps

connectmodule R2E (Din, Aout);
input Din;
wreal Din;         //input wreal
\logic Din;
output Aout;
electrical Aout;   //output electrical

  parameter real vdelta=1.8/64   from (0:inf); // voltage delta
  parameter real tr=10p          from (0:1m);  // risetime
  parameter real tf=tr           from (0:1m);  // falltime
  parameter real tdelay=0        from [0:1m);  // delay time of analog output
  parameter real rout=200        from (0:inf); // output resistance

  real Vstate;     //real register for D wreal to A conversion

  initial Vstate = Din;

  always @(Din) begin
      //filter out digital noise within +/-vdelta
      if (Din-Vstate>=vdelta || Vstate-Din>=vdelta) begin
          Vstate = Din;
      end
  end

  assign Din = Din;

  analog begin
    I(Aout) <+ (V(Aout) - transition(Vstate, 0, tr, tf))/rout;
  end

endmodule

