www.pudn.com > shiboqi.rar > fuzhi.txt, change:2013-03-16,size:839b


module fuzhi 
( 
	clk, 
	rst, 
	ad_in, 
	fuzhi 
); 
input clk,rst; 
input[9:0] ad_in; 
 
output[9:0]fuzhi; 
wire[9:0] fuzhi; 
 
//计数 
parameter  t1s=32'd49_999_999;  
reg	[31:0] cnt; 
wire	t; 
always @(posedge clk or negedge rst) 
begin 
	if (!rst)cnt <= 1'b0; 
	else if(cnt ==t1s)cnt <= 1'b0; 
	else cnt <= cnt + 1'b1; 
end 
	 
assign t=(cnt==t1s) ? 1'b1 : 1'b0;//			 
 
 
//计算ad幅值 
reg	[9:0]ad_max,ad_min,fuzhi_r; 
reg	[9:0]ad_m; 
always @(posedge clk or negedge rst) 
begin 
	if (!rst) ad_m<= 10'd0; 
	else if (t) 
		begin 
			fuzhi_r<= ad_max-ad_min; 
		ad_max	<= 10'd0; 
		ad_min 	<= 10'd1023; 
		end 
	else 
		begin 
			ad_m<=ad_in; 
			if(ad_m>ad_max)ad_max<=ad_m;//只要大于最大值,就将其值赋给最大值 
			if(ad_m<ad_min)ad_min<=ad_m;//只要小于最小值,就将其值赋给最小值 
		end		 
end 
	 
assign   fuzhi=fuzhi_r; 
endmodule