Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2014
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module D_FF(q, d, clk, reset);
  2.     output q;
  3.     input d, clk, reset;
  4.     reg q;
  5.     always @(posedge reset or negedge clk)
  6.         if(reset) q <= 1'b0;
  7.         else q <= d;
  8. endmodule
  9.  
  10. module JK_FF(q, j, k, clk, reset); //requires D_FF
  11.     output q;
  12.     input j, k, clk, reset;
  13.     wire qn, kn, jqn, knq, d;
  14.    
  15.     not notq(qn, q);   
  16.     not notk(kn, k);
  17.    
  18.     and andjqn(jqn, j, qn);
  19.     and andknq(knq, kn, q);
  20.    
  21.     or ord(d, jqn, knq);
  22.    
  23.     D_FF dff(q, d, clk, reset);
  24. endmodule
  25.  
  26. module T_FF(q, t, clk, reset); //requires T_FF
  27.     output q;
  28.     input t, clk, reset;
  29.    
  30.     JK_FF jkff(q, t, t, clk, reset);
  31. endmodule
  32.  
  33. module counter(q, x, clk, reset);
  34.     output[2:0] q;
  35.     input x;
  36.     input clk, reset;
  37.    
  38.     wire q0n, q1n, xn;
  39.     not not0(q0n, q[0]);
  40.     not not1(q1n, q[1]);
  41.     not notx(xn, x);
  42.    
  43.     wire t1, t2;
  44.    
  45.     wire t21, t22;
  46.    
  47.     xor xort1(t1, x, q[0]);
  48.    
  49.     and andt21(t21, xn, q[1], q[0]);
  50.     and andt22(t22, x, q0n, q1n);
  51.     or ort2(t2, t21, t22);
  52.    
  53.     T_FF tff0(q[0], 1'b1, clk, reset);
  54.     T_FF tff1(q[1], t1, clk, reset);
  55.     T_FF tff2(q[2], t2, clk, reset);
  56. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement