2015年12月23日 星期三

2015.12.23 上機考試

今天上機考試 經過一番苦戰 終於過啦~~~~
超開心:>

module top;

wire a, A, b, B, c, C, d, D, F, F1, F2, F3, F4, F5;
system_clock #800 clock1(A);
system_clock #400 clock2(B);
system_clock #200 clock3(C);
system_clock #100 clock4(D);

nand S1(a, A, A);
nand S2(b, B, B);
nand S3(c, C, C);
nand S4(d, D, D);
nand C5(F5, a ,b , C);
nand C1(F2, A ,B , d);
nand C2(F4, a, C, d);
nand C3(F3, A, B, C);
nand C4(F1, A, b, c, D);
nand o1(F, F5, F4, F2, F3, F1);

endmodule

module system_clock(clk);
parameter PERIOD=100;
output clk;
reg clk;

initial clk=0;

always
 begin
#(PERIOD/2) clk=~clk;
 end

always@(posedge clk)
 if($time>1000)$stop;

endmodule


2015年12月2日 星期三

2015.12.2 上課內容

今天有提到上機考試
很傷腦筋阿~
希望可以順利通過
期中還被預警..
我沒翹很多堂課啊@@

2015.11.25 上課內容

今天上課第一題很簡單
第二題想很久還是不知道...

2015年11月18日 星期三

2015.11.18 上課內容 2題

這次上課開始進入不一樣的課程 之前都是多工器的熟悉
之後的課程必須更加動腦才能解題
module test_adder1; reg a,b; reg carry_in ; wire sum; wire carry_out; adder1_behavorial A1(carry_out, sum, a, b, carry_in); initial begin carry_in = 0; a = 0; b = 0; # 100 if ( carry_out != 0 | sum !== 0) $display(" 0+0+0=00 sum is WRONG!"); else $display(" 0+0+0=00 sum is RIGHT!"); carry_in = 0; a = 0; b = 1; # 100 if ( carry_out != 0 | sum !== 1) $display(" 0+0+1=01 sum is WRONG!"); else $display(" 0+0+1=01 sum is RIGHT!"); carry_out = 0; a = 1; b = 0; # 100 if ( carry_out != 0 | sum !== 1) $display(" 0+1+0=01 sum is WRONG!"); else $display(" 0+1+0=01 sum is RIGHT!"); carry_out = 0; a = 1; b = 1; # 100 if ( carry_out != 1 | sum !== 0) $display(" 0+1+1=10 sum is WRONG!"); else $display(" 0+1+1=10 sum is RIGHT!"); carry_out = 1; a = 0; b = 0; # 100 if ( carry_out != 0 | sum !== 1) $display(" 1+0+0=01 sum is WRONG!"); else $display(" 1+0+0=01 sum is RIGHT!"); carry_in = 1; a = 0; b = 1; # 100 if ( carry_in != 1 | sum !== 0) $display(" 1+0+1=10 sum is WRONG!"); else $display(" 1+0+1=10 sum is RIGHT!"); carry_in = 1; a = 1; b = 0; # 100 if ( carry_in != 1 | sum !== 0) $display(" 1+1+0=10 sum is WRONG!"); else $display(" 1+1+0=10 sum is RIGHT!"); carry_out = 1; a = 1; b = 1; # 100 if ( carry_in != 1 | sum !== 1) $display(" 1+1+1=11 sum is WRONG!"); else $display(" 1+1+1=11 sum is RIGHT!"); $finish; end endmodule module adder1_behavorial (carry_out, sum, a, b, carry_in); input a, b, carry_in; output carry_out, sum; assign sum = (~a&b&~carry_in)|(~carry_in&a&~b)|(a&b&carry_in)|(~a&~b&carry_in);
assign carry_out = a&carry_in|a&b|b&carry_in; endmodule



module top; wire A, B, Cin, c1, c2, c3, sum, Cout; system_clock #400 clock1(Cin); system_clock #200 clock2(A); system_clock #100 clock3(B); xor(c1, A, B); and(c2, A, B); xor(sum, c1, Cin); and(c3, c1, Cin); xor(Cout, c3, Cin); endmodule module system_clock(clk); parameter PERIOD=100; output clk; reg clk; initial clk=0; always begin #(PERIOD/2) clk=~clk; end always@(posedge clk) if($time>1000)$stop; endmodule

2015年11月4日 星期三

2015.11.4 上課內容

上兩個禮拜都有事所以沒上到課 所以今天要跟同學學之前上的課程..


/////////////////
//行為模式
/////////////////
module top;
  integer ia,ib,is;
  reg  a,b,s;
  wire out;

  mux_behavioral mux1(out,a,b,s);

  initial
    begin
      for (is=0; is<=1; is = is+1)
        begin
          s = is;
          for (ib=0; ib<=1; ib = ib + 1)
            begin
              b = ib;
              for (ia=0; ia<=1; ia = ia + 1)
               begin
                 a= ia;
                 #1 $display("a=%d b=%d s=%d   out=%d",a,b,s,out);
               end
            end
        end
    end
endmodule

module mux_behavioral(OUT, A, B, SEL);
 output OUT;
 input A,B,SEL;
 wire  A,B,SEL;
 reg    OUT;

  always @(A or B or SEL)
   OUT = (A & SEL)|(B & ~SEL );
endmodule


二位元多工器
module top;
  integer is;
  integer ia[1:0],ib[1:0];
  reg [1:0]a,b;
  reg s;
  wire [1:0]out;

  mux_behavioral mux2(out,a,b,s);

  initial
    begin
      for (is=0; is<=1; is = is + 1)
       begin
        s = is;
         for (ia[0]=0; ia[0]<=1; ia[0] = ia[0]+1)
          begin
           a[0]= ia[0];
            for (ia[1]=0; ia[1]<=1; ia[1] = ia[1]+ 1)
             begin
              a[1] = ia[1];
               for (ib[0]=0; ib[0]<=1; ib[0] = ib[0]+1)
                 begin
                   b[0] = ib[0];
                    for (ib[1]=0; ib[1]<=1; ib[1] = ib[1]+ 1)
                     begin
                      b[1] = ib[1];
                 #1 $display("a[0]=%d a[1]=%d b[0]=%d b[1]=%d s=%d out[0]%d out[1]%d",a[0],a[1],b[0],b[1],s,out[0],out[1]);
                      end
                    end
                  end
              end
         end
    end
endmodule

module mux_behavioral(OUT,A,B,SEL);
 output [1:0]OUT;
 input [1:0] A,B;
 input SEL;

mux1 X1(OUT[0],A[0],B[0],SEL);
mux1 X2(OUT[1],A[1],B[1],SEL);

endmodule

module mux1(OUT, A, B, SEL);
 output OUT;
 input A,B,SEL;

 not n1(NOT_SEL, SEL);
 and a1 (X, A, NOT_SEL);
 and a2 (Y, SEL, B);
 or  o1 (OUT, X, Y);

endmodule

2015年10月14日 星期三

2015.10.14 作業2題 一位元多工器 組合 2位元多工器

今天上課內容較難 在老師提示下還是完成了~~感動XD

一位元多工器


一位元多工器組合成2位元多工器

                                      

2015年10月7日 星期三

2015.10.7 上課作業

今天教得比較複雜,比較需要花時間思考
動動腦筋 最後還是做完了~~