[source lang="verilog"]module process (clk,rst,ad,out);input clk,rst;input [15:0] ad;output [15:0] out; reg [15:0] memory_3,memory_2,memory_1;reg clock,clkout;reg [12:0] ii,jj,kk;reg [15:0] adc_rms ;wire remainder;wire [15:0] RMS_adc_sqr;wire [15:0] ad,data;reg [2:0] stat;reg [13:0] count;reg [31:0] rms_adc_s2,rms_adc_s;reg [15:0] RMS_adc;reg wren;reg [7:0] address; parameter idle =3'b001, start=3'b010, ram =3'b011, fsh =3'b100, work =3'b101; always@(negedge rst or posedge clk)begin if(!rst) begin count<=0; clkout<=0; end else if(count<=4999) begin count<=count+1; clkout<=0; end else if (count>4999 &&count<9999) begin count<=count+1; clkout<=1; end else begin count<=0; clkout<=1; endend always @(negedge rst or posedge clkout)begin if(!rst) begin memory_1<=0; memory_2<=0; memory_3<=0; stat<=idle; ii<=1; kk<=0; jj<=0; end else begin memory_3<=memory_2; memory_2<=memory_1; memory_1<=ad; case(stat) idle: if(memory_2>memory_1 && memory_2>memory_3) begin address=0; wren=1; ram2(clk,wren,address,memory_1,adc_rms); stat<=start; ii<=1; kk<=0; end else stat<=idle; start: if(ii<256) begin address=ii; wren=1; ram2(clk,wren,address,ad,adc_rms); adc_rms[ii]<=ad; if(memory_2>memory_1 &&memory_2>memory_3&&ii>4) begin jj<=ii-1; ii<=256; stat<=start; end else begin ii<=ii+1; stat<=start; end end else stat<=ram; ram: if(ii>=256) begin address=0; wren=0; rms_adc_s=ram2(clk,wren,address,ad,adc_rms); rms_adc_s2<=rms_adc_s2*rms_adc_s2; stat<=work; end elsestat<=idle; work: if(kk<=jj) begin address=jj; wren=0; rms_adc_s=ram2(clk,wren,address,ad,adc_rms) ; rms_adc_s2<=rms_adc_s2+(rms_adc_s*rms_adc_s); stat<=work; kk<=kk+1; end else stat<=fsh; fsh: if(kk>=jj) begin RMS_adc<=rms_adc_s2/(jj+1); stat<=idle; ii<=1; kk<=0; jj<=0; rms_adc_s2<=0; end defaultstat<=idle; endcase end end assign out = RMS_adc; task ram2;input clk,wren,address,data;output adc_rms;beginram ram1( .address (address), .q (adc_rms), .clock (clk), .wren (wren), .data (data) );endendtaskendmodule[/source]ram 是我调用的一个IP RAM-1PORT,因为不能在case里面调用,就把他放在了task 中,然后再task里面调用他,不知道这样写可以不,本人初学,谢谢各位了
一周热门 更多>