|

楼主 |
发表于 2011-3-12 16:40:08
|
显示全部楼层
继续等高手的建议!可能是自己哪地方疏忽了,贴出程序来请过路高手帮忙看下,程序很短。
module genwave(
input clk,
input rst,
input [22:0]freq,//固定的分频值
output [5:0] sinwave
);
reg rom_read;
reg [5:0]cnt,cnt1;
always@(posedge clk)begin//计数器
if(rst)
rom_read<=0;
else
if(cnt1==freq-1)//
rom_read<=1;
else
rom_read<=0;
end
always@(posedge clk)begin //对系统时钟分频产生读ROM时钟
if(rst)
cnt1<=0;
else if(cnt1==freq-1)//
cnt1<=0;
else
cnt1<=cnt1+1;
end
always@(posedge rom_read)begin//每读一次ROM就计数一次,ROM中共50个数据,只需50个时钟就可以读完一次,以计数器的值作为ROM的地址
if(rst)begin
cnt<=0;
end
else
if(cnt==49)
cnt<=0;
else
cnt<=cnt+6'd1;
end
core sine(
.clka(rom_read),
.addra(cnt),
.douta(sinwave)
);
endmodule |
|