第一步:先用visio将原理图画出来
第二步 利用UE编译器将原理实现
第一个模块,利用计数器实现分频
module freq_ctrl(
input wire sclk,
input wire rst_n,
output reg slow_clk
);
reg [5:0] cnt;
parameter CNT_MAX=25-1;
always@(posedge sclk or negedge rst_n)
if (!rst_n)
cnt<='d0;
else if (cnt>CNT_MAX)
cnt<='d0;
else
cnt<=cnt+1;
always@(posedge sclk or negedge rst_n)
if (!rst_n)
slow_clk<=0;
else if (cnt==CNT_MAX)
slow_clk<=~slow_clk;
else
slow_clk<=slow_clk;
endmodule
第二个模块,编写流水灯模块
module run_led(
input wire slow_clk,
input wire rst_n,
output reg [3:0] led_o
);
always@(posedge slow_clk or negedge rst_n)
if(rst_n==0)
led_o<=4'b0001;
else
led_o<={led_o[2:0],led_o[3]};
endmodule
第三个顶层模块例化
module top_led(
input wire sclk_in,
input wire rst_in,
output wire [3:0] led_out
);
wire temp_clk;
freq_ctrl freq_ctrl_inst(
.sclk (sclk_in),
.rst_n (rst_in),
.slow_clk (temp_clk)
);
run_led run_led_inst(
.slow_clk (temp_clk),
.rst_n (rst_in),
.led_o (led_out)
);
endmodule
第四步,建立ISE文件,对模块进行综合仿真
第五步,建立与modelsim联调仿真
在芯片上点击new source 添加测试文件verilog test fixture自动产生测试文件
第六步,仿真检查无误后,就可以添加引脚绑定。步骤和上诉一样,new source 然后添加Ucf文件即可