Advertisement
Guest User

Bleh

a guest
Mar 3rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module MEDIAN #(parameter SIZE = 8) (input [SIZE - 1:0] DI, input DSI, nRST, CLK, output [SIZE - 1:0] DO, output DSO);
  2.  
  3.     logic BYP, inCalc;
  4.     MED #(.SIZE(SIZE)) med(.DI(DI), .DSI(DSI), .BYP(BYP), .CLK(CLK), .DO(DO));
  5.     enum logic [3:0] { PXL1, PXL2, PXL3, PXL4, PXL5, PXL6, PXL7, PXL8, PXL9, CALC, DONE } state;
  6.  
  7.     always @(negedge nRST) begin
  8.         BYP = 1'b0;
  9.         DSO = 1'b0;
  10.         state = PXL1;
  11.         inCalc = 1'b0;
  12.     end
  13.  
  14.     // Also happens to be synchronous
  15.     always_ff @(posedge inCalc) begin
  16.         for(bit [2:0] step = 0; step < 5; step++) begin
  17.             BYP = 1'b0;
  18.             for(bit [3:0] i = step; i < 8; i++)
  19.                 @(posedge CLK);
  20.             BYP = 1'b1;
  21.             if(step < 4)
  22.                 for(bit [2:0] i = 0; i < step + 1; i++)
  23.                     @(posedge CLK);
  24.         end
  25.         BYP = 1'b0;
  26.         state = DONE;
  27.         inCalc = 1'b0;
  28.     end
  29.  
  30.     // Synchronous state machine
  31.     always @(posedge CLK) begin
  32.         case(state)
  33.         PXL1:
  34.             if(DSI)
  35.             begin
  36.                 DSO = 1'b0;
  37.                 state += 1;
  38.             end
  39.         // All pixels have been sent, calculate the thing now
  40.         CALC:
  41.             inCalc = 1'b1;
  42.         DONE:
  43.         begin
  44.             DSO = 1'b1;
  45.             state = PXL1;
  46.         end
  47.         default:
  48.             state += 1;
  49.             // loop through all the pixel states as the pixels get sent and then reach CALC
  50.         endcase
  51.     end
  52.  
  53. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement