Re: Verilog coding query
Thanks....Now i am able to find the biggest value and its location among 20 values but the problem is i have to find the first location of the maximum value if the maximum value occur more than once..
i have attached the code with this..... can u help me......
module biggg(clock,Enable,reset,corrouti1,corrouti2,corrouti3,corrouti4,corrouti5,corrouti6,corrouti7,
corrouti8,corrouti9,corrouti10,corrouti11,corrouti12,corrouti13,corrouti14,corrouti15,
corrouti16,corrouti17,corrouti18,corrouti19,corrouti20,max_value, max_pos) ;
input clock;
input reset;
input Enable;
input [9:0] corrouti1,corrouti2,corrouti3,corrouti4,corrouti5,corrouti6,corrouti7,
corrouti8,corrouti9,corrouti10,corrouti11,corrouti12,corrouti13,corrouti14,corrouti15
output [9:0] max_value ;
output [4:0] max_pos;
wire [9:0] temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,temp8,temp9,temp10, temp11,
temp12,temp13,temp14,temp15,temp16,temp17,temp18, max_val_temp, n_max_value;
wire [4:0] pos0, pos1, pos2,pos3,pos4,pos5,pos6,pos7,pos8,pos9,pos10,pos11, pos12,pos13,
pos14,pos15,pos16,pos17,pos18, max_pos_temp, n_max_pos;
reg [9:0] max_value;
reg [4:0] max_pos;
//Maximum value
assign temp0 = (corrouti1 > corrouti2) ? corrouti1 : corrouti2;
assign temp1 = (temp0 > corrouti3) ? temp0 : corrouti3;
assign temp2 = (temp1 > corrouti4) ? temp1 : corrouti4;
assign temp3 = (temp2 > corrouti5) ? temp2 : corrouti5;
assign temp4 = (temp3 > corrouti6) ? temp3 : corrouti6;
assign temp5 = (temp4 > corrouti7) ? temp4 : corrouti7;
assign temp6 = (temp5 > corrouti8) ? temp5 : corrouti8;
assign temp7 = (temp6 > corrouti9) ? temp6 : corrouti9;
assign temp8 = (temp7 > corrouti10) ? temp7 : corrouti10;
assign temp9 = (temp8 > corrouti11) ? temp8 : corrouti11;
assign temp10 = (temp9 > corrouti12) ? temp9 : corrouti12;
assign temp11 = (temp10 > corrouti13) ? temp10 : corrouti13;
assign temp12 = (temp11 > corrouti14) ? temp11 : corrouti14;
assign temp13 = (temp12 > corrouti15) ? temp11 : corrouti15;
assign temp14 = (temp13 > corrouti16) ? temp13 : corrouti16;
assign temp15 = (temp14 > corrouti17) ? temp14 : corrouti17;
assign temp16 = (temp15 > corrouti18) ? temp15 : corrouti18;
assign temp17 = (temp16 > corrouti19) ? temp16 : corrouti19;
assign temp18 = (temp17 > corrouti20) ? temp17 : corrouti20;
assign max_val_temp = (temp18 > corrouti20) ? temp18 : corrouti20;
//Maximum position
assign pos0 = (corrouti1 > corrouti2) ? 5'd1 : 5'd2;
assign pos1 = (temp0 > corrouti3) ? pos0 : 5'd3;
assign pos2 = (temp1 > corrouti4) ? pos1 : 5'd4;
assign pos3 = (temp2 > corrouti5) ? pos2 : 5'd5;
assign pos4 = (temp3 > corrouti6) ? pos3 : 5'd6;
assign pos5 = (temp4 > corrouti7) ? pos4 : 5'd7;
assign pos6 = (temp5 > corrouti8) ? pos5 : 5'd8;
assign pos7 = (temp6 > corrouti9) ? pos6 : 5'd9;
assign pos8 = (temp7 > corrouti10) ? pos7 : 5'd10;
assign pos9 = (temp8 > corrouti11) ? pos8 : 5'd11;
assign pos10 = (temp9 > corrouti12) ? pos9 : 5'd12;
assign pos11 = (temp10 > corrouti13) ? pos10 : 5'd13;
assign pos12 = (temp11 > corrouti14) ? pos11 : 5'd14;
assign pos13 = (temp12 > corrouti15) ? pos11 : 5'd15;
assign pos14 = (temp13 > corrouti16) ? pos13 : 5'd16;
assign pos15 = (temp14 > corrouti17) ? pos14 : 5'd17;
assign pos16 = (temp15 > corrouti18) ? pos15 : 5'd18;
assign pos17 = (temp16 > corrouti19) ? pos16 : 5'd19;
assign pos18 = (temp17 > corrouti20) ? pos17 : 5'd20;
assign max_pos_temp = (temp18 > corrouti20) ? pos18 : 5'd20;
//Assign new value when Enable is high, else hold previous value
assign n_max_value = (Enable) ? max_val_temp : max_value;
assign n_max_pos = (Enable) ? max_pos_temp : max_pos;
always@(posedge clock or negedge reset) begin
if(!reset) begin
max_value <= 10'd0;
max_pos <= 5'd0;
end
else begin
max_value <= n_max_value;
max_pos <= n_max_pos;
end
end
endmodule