Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module SET ( clk , rst, en, central, radius, mode, busy, valid, candidate );
- input clk, rst;
- input en;
- input [23:0] central; // [23:20] Xa [19:16] Ya ; [15:12] Xb [11:8] Yb ;
- // remain the rest of it
- input [11:0] radius; // [11:8] ra ; [7:4] rb ; remain the rest of it
- input [1:0] mode;
- output reg busy; //high > busy
- output reg valid; //high > output
- output [7:0] candidate;
- reg [7:0] candidate_tmp,candidate_tmp1,candidate_tmp2;
- reg [3:0]cnt_x,cnt_y;
- reg [7:0]X_ptr,Y_ptr;
- reg [9:0]r;
- assign candidate[7:0] = candidate_tmp[7:0];
- /* To run all the points */
- always@(posedge clk or posedge rst)
- begin
- if(rst)
- begin
- cnt_x <= 4'h1;
- cnt_y <= 4'h1;
- busy <= 1'b0;
- valid <= 1'b0;
- end
- else if(en)
- begin
- busy <= 1'b1;
- valid <= 1'b0;
- cnt_x <= 4'h1;
- cnt_y <= 4'h1;
- end
- else
- begin
- if(cnt_x == 4'h8 && cnt_y == 4'h8)
- begin
- busy <= 1'b0;
- valid <= 1'b1;
- cnt_x <= 4'h1;
- cnt_y <= 4'h1;
- end
- else if(cnt_x == 4'h8)
- begin
- cnt_x <= 4'h1;
- cnt_y <= cnt_y + 1;
- end
- else if(cnt_y == 4'h8)
- begin
- cnt_x <= cnt_x + 1;
- end
- else
- cnt_x <= cnt_x + 1;
- end
- end
- /* Modes */
- always@(posedge clk or posedge rst)
- begin
- if(rst)
- begin
- candidate_tmp <= 8'b0;
- end
- else if(en)
- begin
- candidate_tmp <= 8'b0;
- candidate_tmp1 <= 8'b0;
- candidate_tmp2 <= 8'b0;
- //A
- X_ptr[7:4] <= central[23:20];
- Y_ptr[7:4] <= central[19:16];
- r[9:5] <= radius[11:8];
- //B
- X_ptr[3:0] <= central[15:12];
- Y_ptr[3:0] <= central[11:8];
- r[4:0] <= radius[7:4];
- end
- else
- begin
- case(mode)
- 2'b00:begin //set A and set B
- if( ((X_ptr[7:4]*X_ptr[7:4]-2*X_ptr[7:4]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])
- + (Y_ptr[7:4]*Y_ptr[7:4]+cnt_y[3:0]*cnt_y[3:0]-2*cnt_y[3:0]*Y_ptr[7:4])) <= (r[9:5]*r[9:5]) )
- candidate_tmp <= candidate_tmp+1;
- end
- // Use a2-2ab+b2 to replace (a-b)2 to avoid negative situation
- 2'b01:begin //set A & B
- if( (((
- (X_ptr[7:4]*X_ptr[7:4]-2*X_ptr[7:4]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])
- +(Y_ptr[7:4]*Y_ptr[7:4]+cnt_y[3:0]*cnt_y[3:0]-2*cnt_y[3:0]*Y_ptr[7:4]))) <= (r[9:5]*r[9:5]))
- && ((((X_ptr[3:0]*X_ptr[3:0]-2*X_ptr[3:0]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])+(Y_ptr[3:0]*Y_ptr[3:0]-2*Y_ptr[3:0]*cnt_y[3:0]+cnt_y[3:0]*cnt_y[3:0]))) <= (r[4:0]*r[4:0])))
- candidate_tmp <= candidate_tmp+1;
- end
- 2'b10:begin //set (A | B) - (A & B)
- if(
- (((((X_ptr[7:4]*X_ptr[7:4]-2*X_ptr[7:4]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])+(Y_ptr[7:4]*Y_ptr[7:4]+cnt_y[3:0]*cnt_y[3:0]-2*cnt_y[3:0]*Y_ptr[7:4]))) <= (r[9:5]*r[9:5]))
- || ((((X_ptr[3:0]*X_ptr[3:0]-2*X_ptr[3:0]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])+(Y_ptr[3:0]*Y_ptr[3:0]-2*Y_ptr[3:0]*cnt_y[3:0]+cnt_y[3:0]*cnt_y[3:0]))) <= (r[4:0]*r[4:0])))
- &&
- !(((((X_ptr[7:4]*X_ptr[7:4]-2*X_ptr[7:4]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])+(Y_ptr[7:4]*Y_ptr[7:4]+cnt_y[3:0]*cnt_y[3:0]-2*cnt_y[3:0]*Y_ptr[7:4]))) <= (r[9:5]*r[9:5]))
- && ((((X_ptr[3:0]*X_ptr[3:0]-2*X_ptr[3:0]*cnt_x[3:0]+cnt_x[3:0]*cnt_x[3:0])+(Y_ptr[3:0]*Y_ptr[3:0]-2*Y_ptr[3:0]*cnt_y[3:0]+cnt_y[3:0]*cnt_y[3:0]))) <= (r[4:0]*r[4:0])))
- )
- //candidate_tmp1 <= candidate_tmp1 +1;
- //candidate_tmp2 <= candidate_tmp2+1;
- candidate_tmp <= candidate_tmp+1;
- end
- //default:mode <= 2'b00;
- endcase
- end
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment