Guest User

Untitled

a guest
Mar 10th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //My regMod:
  2. module regMod(clk, data, out, notOut);
  3.    input clk, data;
  4.    output out, notOut;
  5.    wire outTopAnd, outBottomAnd;
  6.    wire outTopOr, outBottomOr;
  7.    wire notData;
  8.    not(notData, data);
  9.  
  10.    and(outTopAnd, data, clk);
  11.    and(outBottomAnd, notData, clk);
  12.  
  13.    nor(outTopOr, outTopAnd, outBottomOr);
  14.    nor(outBottomOr, outBottomAnd, outTopOr);
  15.    assign notOut = outTopOr;
  16.    assign out = outBottomOr;
  17. endmodule
  18.  
  19. //This module was provided.
  20. module ClockMod(clk);
  21.    output clk;
  22.    reg A;
  23.  
  24.    assign clk = A;
  25.    initial A = 0;
  26.    always begin
  27.       #1 A = 1;
  28.       #1 A = 0;
  29.    end
  30. endmodule
  31.  
  32.  
  33. module CounterMod(clk, rst, q1, q0);
  34.    input clk, rst;
  35.    output q1, q0;//2 bit, 4 possible states.
  36.  
  37.    //Wire and register names
  38.    wire registerOneData, registerTwoData;
  39.    wire notRST, clkWire;
  40.  
  41.    wire notRegisterOneData, notRegisterTwoData;
  42.    wire andOneOut, andTwoOut, andThreeOut, andFourOut;
  43.    wire o1,o2,o3,o4;
  44.    wire orOut1, orOut2;
  45.    reg t1, t0;
  46.  
  47.    //t1 and t0 are the inputs looping back in.
  48.    regMod regOne(clk, t1, registerOneData, notRegisterOneData);//s1
  49.    regMod regTwo(clk, t0, registerTwoData, notRegisterTwoData);//s0
  50.  
  51.    //NOT the rst line
  52.    not(notRST, rst);
  53.  
  54. //Set up AND gate lattice
  55.    and(o1, notRST, notRegisterOneData);
  56.    and(andOneOut, o1, registerTwoData);
  57.  
  58.    and(o2, notRST, registerOneData);
  59.  
  60.    and(andTwoOut, o2, notRegisterTwoData);
  61.    
  62.    and(o3, notRST, notRegisterOneData);
  63.    and(andThreeOut, o3, notRegisterTwoData);
  64.  
  65.    and(o4, notRST, registerOneData);
  66.    and(andFourOut, o4, notRegisterTwoData);
  67.  
  68. //Set up OR gate lattice
  69.    or(orOut1, andOneOut, andTwoOut);
  70.    or(orOut2, andThreeOut, andFourOut);
  71.    assign q1 = orOut1;
  72.    assign q0 = orOut2;  
  73.  
  74. always@(negedge clk) begin
  75.    t1 = q1;
  76.    t0 = q0;
  77.  
  78. end
  79. endmodule
  80.  
  81. module TestMod;
  82.    reg rst;
  83.    initial begin
  84.       rst = 1;
  85.       #1 rst = 0;
  86.    end
  87.    wire tyme, clk, q1, q0;
  88.    
  89.    ClockMod my_clock(clk);
  90.    CounterMod my_counter(clk, rst, q1, q0);
  91.  
  92.    initial begin
  93.       $display("Time  clk  rst   q1    q0");
  94.       $display("-----------------------------------------");
  95.     $monitor("%3d   %b   %b    %b    %b", $time, clk, rst, q1, q0);
  96.    end  
  97.  
  98.    initial #16 $finish;
  99. endmodule
Advertisement
Add Comment
Please, Sign In to add comment