晚上写了一个简易的信号发生器的程序,上机验证成功,通过了 Signal Tap II验证。
Mif 文件的数据是通过 mif_maker2010 这个软件生成的,它的使用教程通过这个链接可以找到:https://www.cnblogs.com/qidaiymm/p/6007704.html
硬件环境为:DE1-SOC
软件环境为:Quartus II_15.0
可以通过四个拨码开关来进行波形及频率的切换,那个ROM-1 PORT的使用我就不介绍了
实现的效果为:
代码如下:
模块1:
module control_freq(
clk,
rst_n,
key_in,
fout
);
clk,
rst_n,
key_in,
fout
);
input clk;
input rst_n;
input[1:0] key_in;
output fout;
input rst_n;
input[1:0] key_in;
output fout;
reg[3:0] cnt;
reg clk_2,clk_4;
reg fout;
reg clk_2,clk_4;
reg fout;
always@(posedge clk or negedge rst_n)
if(!rst_n)
begin
cnt<=4'd0;
clk_2<=0;
end
else if(cnt==4'd1)
begin
cnt<=4'd0;
clk_2<=~clk_2;
end
else
cnt<=cnt+1'b1;
always@(posedge clk_2 or negedge rst_n)
if(!rst_n)
clk_4<=0;
else
clk_4<=~clk_4;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fout<=0;
else
begin
case(key_in)
0:fout<=clk_2;
1:fout<=clk_4;
default:;
endcase
end
end
endmodule
if(!rst_n)
begin
cnt<=4'd0;
clk_2<=0;
end
else if(cnt==4'd1)
begin
cnt<=4'd0;
clk_2<=~clk_2;
end
else
cnt<=cnt+1'b1;
always@(posedge clk_2 or negedge rst_n)
if(!rst_n)
clk_4<=0;
else
clk_4<=~clk_4;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fout<=0;
else
begin
case(key_in)
0:fout<=clk_2;
1:fout<=clk_4;
default:;
endcase
end
end
endmodule
模块2:
module sw_control(
clk,
rst_n,
data_out,
sw
);
input clk;
input rst_n;
input[1:0] sw;
output[7:0] data_out; //数据输出
clk,
rst_n,
data_out,
sw
);
input clk;
input rst_n;
input[1:0] sw;
output[7:0] data_out; //数据输出
reg[7:0] address;
wire[7:0] q1,q2,q3; //地址寄存器
reg[7:0] data_out;
wire[7:0] q1,q2,q3; //地址寄存器
reg[7:0] data_out;
always@(posedge clk or negedge rst_n)
if(!rst_n)
address <= 8'd0;
else if(address==255)
address <=8'd0;
else
address <= address +1'b1;
san_jiao_xing san_jiao_xing(
.address(address),
.clock(clk),
.q(q1)
);
if(!rst_n)
address <= 8'd0;
else if(address==255)
address <=8'd0;
else
address <= address +1'b1;
san_jiao_xing san_jiao_xing(
.address(address),
.clock(clk),
.q(q1)
);
sin sin(
.address(address),
.clock(clk),
.q(q2)
);
.address(address),
.clock(clk),
.q(q2)
);
fang_bo fang_bo(
.address(address),
.clock(clk),
.q(q3)
);
.address(address),
.clock(clk),
.q(q3)
);
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
data_out<=8'd0;
else
begin
case(sw)
0:data_out<=q1;
1:data_out<=q2;
2:data_out<=q3;
default:data_out<=8'd0;
endcase
end
end
endmodule
begin
if(!rst_n)
data_out<=8'd0;
else
begin
case(sw)
0:data_out<=q1;
1:data_out<=q2;
2:data_out<=q3;
default:data_out<=8'd0;
endcase
end
end
endmodule
//顶层模块
module AD_pulse_signal_generator(
clk,
rst_n,
key_in,
sw,
data_out
);
module AD_pulse_signal_generator(
clk,
rst_n,
key_in,
sw,
data_out
);
input clk;
input rst_n;
input[1:0] key_in;
input[1:0] sw;
output[7:0] data_out;
input rst_n;
input[1:0] key_in;
input[1:0] sw;
output[7:0] data_out;
control_freq u1(
.clk(clk),
.rst_n(rst_n),
.key_in(key_in),
.fout(fout)
);
.clk(clk),
.rst_n(rst_n),
.key_in(key_in),
.fout(fout)
);
sw_control u2(
.clk(fout),
.rst_n(rst_n),
.data_out(data_out),
.sw(sw)
);
.clk(fout),
.rst_n(rst_n),
.data_out(data_out),
.sw(sw)
);
endmodule
欢迎各位朋友批评指正~