// D Flip Flop that works with SpectreRF (has no hidden state) // // Version 1a, 21 March 2007 // // Ken Kundert // // Downloaded from The Designer's Guide Community (www.designers-guide.org) // Post any questions on www.designers-guide.org/Forum. `include "discipline.h" // basic d flip flop module dff (clk, d, q); input clk, d; output q; voltage clk, d, q; parameter real v0=0; parameter real v1=1 from (v0:inf); parameter integer dir=1 from [-1:1] exclude 0; parameter real td=0 from [0:inf); parameter real tt=0 from [0:inf); integer actNow, out; real thresh; analog begin thresh = (v0+v1)/2; actNow = 0; @(initial_step or cross(V(clk) - thresh, dir)) actNow = 1; out = idt(0, V(d) > thresh, actNow); V(q) <+ transition(out ? v1 : v0, td, tt); end endmodule // d flip flop with reset (reset is active high) and parameterizable initial state module dff2 (clk, d, reset, q, qb); input clk, d, reset; output q, qb; voltage clk, d, reset, q, qb; parameter real v0=0; parameter real v1=1 from (v0:inf); parameter integer dir=1 from [-1:1] exclude 0; parameter real td=0 from [0:inf); parameter real tt=0 from [0:inf); parameter integer init_state=0 from [0:1]; integer actNow, out, state; real thresh; analog begin thresh = (v0+v1)/2; actNow = 0; @(cross(V(clk) - thresh, dir) or cross(V(reset) - thresh, +1)) begin actNow = 1; state = (V(d) > thresh) && (V(reset) < thresh); end @(initial_step) begin actNow = 1; state = init_state; end out = idt(0, state, actNow); V(q) <+ transition(out ? v1 : v0, td, tt); V(qb) <+ v0 + v1 - V(q); end endmodule