dipin
Full Member level 4
- Joined
- Jul 16, 2014
- Messages
- 223
- Helped
- 14
- Reputation
- 28
- Reaction score
- 14
- Trophy points
- 18
- Activity points
- 1,731
What is the algorithm that you are using, any link ?
**broken link removed**Hi Dipin. For 2 shifting and 1 subtraction, I don't know why does it take 5 clock cycles. And anyways, u said the xilinx core takes 5, not this..
end else if(count>0) begin
temp_in_data <= temp_in_data << 2;
if(temp_in_data[2*N-1:2*Q]>= temp_sub_result[N-1:0]) begin
temp_in_data [2*N-1:2*Q+2] <= temp_in_data[2*N-1:2*Q] - temp_sub_result[N-1:0];
a_out_data <= a_out_data << 1;
a_out_data[0] <= 1'b1;
count <= count-1;
temp_sub_result[2] <= 1'b1;
temp_sub_result[Q+2:3] <= a_out_data[Q-1:0];
end else begin
a_out_data <= a_out_data << 1;
a_out_data[0] <= 1'b0;
count <= count-1;
temp_sub_result[Q+2:3] <= a_out_data[Q-1:0];
temp_sub_result[2] <= 1'b0;
end
end
end else if(count>0) begin
temp_in_data <= temp_in_data << 2;
temp_in_data_1 <= temp_in_data << 2;
temp_in_data_2 << temp_in_data_1 << 2;
//...etc
temp_in_data [2*N-1:2*Q+2] <= temp_in_data[2*N-1:2*Q] - temp_sub_result[N-1:0];
// instead of this:
temp_sub_result[2] <= 1'b1;
temp_sub_result[Q+2:3] <= a_out_data[Q-1:0];
// you can concatenate the RHS like this:
temp_sub_result[Q+2:2] < {a_out_data[Q-1:0, 1'b1};
No it won't, the design is not pipelined, it's got feedback elements that need to have every iteration completed before they can get the first output. Hence their problem stated in post #3After the 5th clock, you will notice an output every clock.
if i give input in next clock cycle.it will overwrite the operand and results in error
temp_in_data_1 <= temp_in_data << 2;
temp_in_data_2 <= temp_in_data_1 << 2;
temp_in_data_3 <= temp_in_data_2 << 2;
temp_in_data_4 <= temp_in_data_3 << 2;
if(temp_in_data[2*N-1:2*Q]>= temp_sub_result[N-1:0]) begin
temp_in_data_1 [2*N-1:2*Q+2] <= temp_in_data[2*N-1:2*Q] - temp_sub_result[N-1:0] ;
a_out_data_1 <= {a_out_data ,1'b1 };
count <= count-1;
temp_sub_result_1[Q+2:2] <= {a_out_data[Q-1:0], 1'b1};
end else begin
temp_in_data_1 <= temp_in_data << 2;
a_out_data_1 <= {a_out_data ,1'b0 };
count <= count-1;
temp_sub_result_1[Q+2:2] <= {a_out_data[Q-1:0],1'b0};
end
if(temp_in_data_1[2*N-1:2*Q]>= temp_sub_result_1[N-1:0]) begin
temp_in_data_2 [2*N-1:2*Q+2] <= temp_in_data_1[2*N-1:2*Q] - temp_sub_result_1[N-1:0];
a_out_data_2 <= {a_out_data_1 ,1'b1 };
count <= count-1;
temp_sub_result_2[Q+2:2] <= {a_out_data_1[Q-1:0], 1'b1};
end else begin
temp_in_data_2 <= temp_in_data_1 << 2;
a_out_data_2 <= {a_out_data_1 ,1'b0 };
count <= count-1;
temp_sub_result_2[Q+2:2] <= {a_out_data_1[Q-1:0],1'b0};
end
module main(
input en,
input clk
);
localparam N = 32;
reg [N-1:0] input_data = 1927;
reg [N-1:0] _input_data = 0;
reg [N-1:0] rest = 0;
reg [N-1:0] result = 0;
reg [N-1:0] counter = 0;
wire[N-1:0] rest_1;
wire[N-1:0] rest_2;
wire[N-1:0] result_1;
wire[N-1:0] result_2;
assign rest_1 = ({rest,_input_data[N-1:N-2]} - {result,2'b01}),
rest_2 = {rest,_input_data[N-1:N-2],_input_data[N-3:N-4]},
result_1 = {result,1'b1,2'b01},
result_2 = {result,1'b0,2'b01};
always @(posedge clk)
begin
if (en)
begin
_input_data <= input_data;
rest <= 0;
result <= 0;
counter <= 0;
end
else
begin
counter = counter + 1;
_input_data <= _input_data<<4;
if (~rest_1[N-1] && {rest_1,_input_data[N-3:N-4]} >= result_1) // first positive, second positive
begin
rest <= {rest_1,_input_data[N-3:N-4]} - result_1;
result <= {result,1'b1,1'b1};
end
else if (~rest_1[N-1] && {rest_1,_input_data[N-3:N-4]} < result_1) // first positive, second negative
begin
rest <= {rest_1,_input_data[N-3:N-4]};
result <= {result,1'b1,1'b0};
end
else if (rest_1[N-1] && rest_2 >= result_2) // first negative, second positive
begin
rest <= rest_2 - result_2;
result <= {result,1'b0,1'b1};
end
else if (rest_1[N-1] && rest_2 < result_2) // First negative, second negative
begin
rest <= rest_2;
result <= {result,1'b0,1'b0};
end
end
end
endmodule
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?