Advertisement
Guest User

Untitled

a guest
Dec 31st, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. `timescale 1ns/100ps
  2.  
  3. `define CYCLE 10   /*you can modify this value*/
  4. `define LATENCY 1
  5.  
  6. `define tb1
  7. `define PICIN "C:/Users/feather/Desktop/hand/ate/tb1.map"
  8. `define BINOUT "C:/Users/feather/Desktop/hand/ate/tb1.bin"
  9. `define THRESHOLDOUT "C:/Users/feather/Desktop/hand/ate/tb1.threshold"
  10. `define BLOCKS 24
  11.  
  12.  
  13. `define SDFFILE "ate.sdf"
  14.  
  15.  
  16. module testfixture();
  17.  
  18. reg clk, reset;
  19. reg [7:0] pix_data;
  20. wire bin;
  21. wire [7:0] threshold;
  22.    
  23.  
  24. reg [7:0] picin [0:1535];
  25. reg [63:0] binout [0:23];
  26. reg [7:0] thresholdout [0:23];
  27.  
  28.  
  29. reg [7:0] expect_threshold;
  30. reg expect_bin;
  31. real cycle = `CYCLE;
  32. real helfCYCLE;
  33. initial  helfCYCLE = cycle/2;    
  34. integer inputblock,outputblock;
  35. integer inputpixel,outputpixel;
  36. integer startcompare;
  37. integer i;
  38. integer stcycle;
  39. integer goterror;
  40. reg [63:0] block_bin;
  41.      
  42. ate  ate(.clk(clk), .reset(reset), .pix_data(pix_data), .bin(bin), .threshold(threshold));
  43.            
  44.  
  45. initial
  46. begin
  47.     `ifdef FSDB
  48.         $fsdbDumpfile("ate.fsdb");
  49.         $fsdbDumpvars;
  50.     `endif
  51.     /*
  52.     $dumpvars;
  53.     $dumpfile("ate.vcd");
  54.     */
  55.  
  56.     `ifdef SDF
  57.         $sdf_annotate(`SDFFILE,ate);
  58.     `endif
  59.  
  60.     $readmemh (`PICIN,picin);
  61.     $readmemb (`BINOUT,binout);
  62.     $readmemh (`THRESHOLDOUT,thresholdout);
  63.    
  64. end
  65.  
  66. always #helfCYCLE clk = ~clk;
  67.  
  68. initial
  69. begin
  70. clk = 1'b1;
  71. reset = 1'b0;
  72. #helfCYCLE reset = 1'b1;
  73. $write("\nblock              bin output");
  74. #`CYCLE     reset =1'b0;
  75.  
  76. end
  77.  
  78. always @(posedge clk)
  79. begin
  80.  
  81. // //  $fsdbDumpMem(ate.block_tmp, 0, 64);
  82. //        $fsdbDumpMem(binout,0,24);
  83.  
  84.     if(reset) begin
  85.         inputblock=0;
  86.         inputpixel=-1;
  87.         goterror=0;
  88.         startcompare=0;
  89.     end
  90.     #helfCYCLE
  91.     inputpixel=inputpixel+1;
  92.     if(startcompare==1) outputpixel=outputpixel+1;
  93.     if(inputpixel==64) begin
  94.         inputblock=inputblock+1;
  95.         inputpixel=0;
  96.     end
  97.     i=inputblock*64+inputpixel;
  98.     pix_data=picin[i];
  99.  
  100.     if(outputpixel==64) begin
  101.         outputblock=outputblock+1;
  102.         outputpixel=0;
  103.         $write("\n%4d  ",outputblock);
  104.     end
  105.  
  106.     stcycle=64+`LATENCY;
  107.     if((inputblock*64+inputpixel) == stcycle) begin
  108.         startcompare=1;
  109.         outputblock=0;
  110.         outputpixel=0;
  111.         $write("\n%4d  ",outputblock);
  112.     end
  113.  
  114.     /*compare*/
  115.     if((startcompare==1) && (outputblock < `BLOCKS)) begin
  116.         block_bin = binout[outputblock];
  117.         expect_bin = block_bin[63-outputpixel];
  118.         expect_threshold = thresholdout[outputblock];
  119.         $write("%d",bin);
  120.         if(threshold !== expect_threshold) begin
  121.             $write("\nthreshold error found at block%4d, pixel%4d : expect %h, got %h",outputblock,outputpixel,expect_threshold,threshold);
  122.                 goterror=1;
  123.  
  124.         end
  125.         if(bin !==expect_bin) begin
  126.             $write("\nbin error found at block %2d , pixel %2d : expect bin: %h, got bin: %h",outputblock, outputpixel,expect_bin,bin);
  127.             goterror=1;
  128.         end
  129.         if(goterror==1) begin
  130.             $write ("\n\n");
  131.             #20
  132.             $finish;
  133.         end
  134.        
  135.     end
  136.  
  137.     if(outputblock== `BLOCKS) begin
  138.         $display("");
  139.         $display("");
  140.         $display("                           ,-.__.-,                           ");
  141.         $display("                          (``-''-//).___..--'''`-._           ");
  142.         $display("                           `6_ 6  )   `-.  (     ).`-.__.`)   ");
  143.         $display("                           (_Y_.)'  ._   )  `._ `. ``-..-'    ");
  144.         $display("                         _..`--'_..-_/  /--'_.' ,'            ");
  145.         $display("                        (il),-''  (li),'  ((!.-'              ");
  146.         $display("  Congratulations !");
  147.         $display("  Simulation Complete!!");
  148.         $display("");
  149.         $finish;
  150.     end
  151. end
  152.  
  153.  
  154. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement