各位
FPGA的高手们,小弟再做一个FPGA二分频信号时,有一个很困惑的问题,一直搞不明白,具体要求如下硬件连接,编程要求
图中电源电压VCC=3.3V,R1 = 1×(1±10%)KΩ,R2 = 1×(1±10%)KΩ,C1 = 30×(1±10%)pF。输入信号F0 = 1MHz,F1 = F0/2,F2 = F1/2,F3 = F2/2,F4 = F3/2,F5 = F4/2,F6 = F5/2,F7 = F6/2,F8 = F7/2,F9 = F8/2,F10 = F9/2,F11 = F10/2,F12 = F11/2,F13 = F12/2,F14 = F13/2,F15 = F14/2,F16 = F15/2, F17 = F16/2,FC0 = 500KHZ,CLK0输入时钟为50MHZ。
现在 我的代码如下:
module VDEE5M40(
sys_clk,
sys_rst,
div_clk,
cs,
led
);
input sys_clk;
input sys_rst;
output cs;
output [16:0] div_clk; //地址信号
output [2:0] led;
reg clk_2mhz;
reg [16:0] clk_2mhz_count;
reg [2:0] led;
reg [16:0] s_div_clk; //二分频寄存器
reg [31:0] count;
reg [31:0] count2; //绯荤粺鏃堕挓璁℃暟
reg [31:0] count3; //500khz璁℃暟
//reg address;
reg cs;
reg sys_clk500;
assign div_clk = s_div_clk ;
/*ini
tial
begin
clk_2mhz_count <=1'b0;
clk_2mhz <=1'b0;
led <=3'hf8;
cs <=1'b0;
count <=32'h0000;
count2 <=32'h0000;
count3 <=19'h0000;
end*/
always @(posedge sys_clk or negedge sys_rst)begin //1MHZ
if(!sys_rst)begin
clk_2mhz <= 1'b0;
clk_2mhz_count <= 17'd0;
end
else begin
if(clk_2mhz_count == 17'd24)begin
clk_2mhz <= 1'b1;
clk_2mhz_count <= 17'd0;
end
else begin
clk_2mhz <= 1'b0;
clk_2mhz_count <= clk_2mhz_count + 17'd1;
end
end
end
always @(posedge sys_clk or negedge sys_rst ) begin //系统时钟检测 LED[2]
if(!sys_rst)begin
count2 <= 32'h0000_0000;
end
else begin
if(count2 ==32'd20000_000)begin
led[2]<= ~led[2];
count2 <= 32'h0000_0000;
end
else begin
count2 <= count2+1'b1;
end
end
end
always @(negedge sys_clk or negedge sys_rst ) begin //500KhZ给予cs端口信号,LED【1】检测
if(!sys_rst) begin
sys_clk500 <=0;
count3 <=32'h0000_0000;
end
else begin
if(count3==100)
begin
sys_clk500 <= ~sys_clk500;
led [1] <= ~led [1];
count3 <=32'h0000_0000;
end
else
count3 <=count3+1'b1;
end
end
always @(posedge sys_clk500 or negedge sys_rst ) begin //cs片选控制端口LED[0],检测片选信号
if(!sys_rst) begin
cs <=1'b1;
count <=32'h0000_0000;
end
else begin
if(count <=32'd50000) begin
if(count% 2 ==1'b1)begin
cs <=~cs;
led [0] <= ~led [0];
end
else begin
cs <=1'b1;
end
count <=count +1'b1; end
else begin
count <=32'h0000_0000;
//led [0] <= ~led [0];
end
end
end
always @(posedge clk_2mhz or negedge sys_rst)begin //1MHZ频率信号
if(!sys_rst)begin
s_div_clk[0] <= 1'b0;
end
else begin
s_div_clk[0] <= ~s_div_clk[0];
end
end
always @(posedge s_div_clk[0] or negedge sys_rst)begin //500khz棰戠巼
if(!sys_rst)begin
s_div_clk[1] <= 1'b0;
end
else begin
s_div_clk[1] <= ~s_div_clk[1];
end
end
always @(posedge s_div_clk[1] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[2] <= 1'b0;
end
else begin
s_div_clk[2] <= ~s_div_clk[2];
end
end
always @(posedge s_div_clk[2] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[3] <= 1'b0;
end
else begin
s_div_clk[3] <= ~s_div_clk[3];
end
end
always @(posedge s_div_clk[3] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[4] <= 1'b0;
end
else begin
s_div_clk[4] <= ~s_div_clk[4];
end
end
always @(posedge s_div_clk[4] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[5] <= 1'b0;
end
else begin
s_div_clk[5] <= ~s_div_clk[5];
end
end
always @(posedge s_div_clk[5] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[6] <= 1'b0;
end
else begin
s_div_clk[6] <= ~s_div_clk[6];
end
end
always @(posedge s_div_clk[6] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[7] <= 1'b0;
end
else begin
s_div_clk[7] <= ~s_div_clk[7];
end
end
always @(posedge s_div_clk[7] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[8] <= 1'b0;
end
else begin
s_div_clk[8] <= ~s_div_clk[8];
end
end
always @(posedge s_div_clk[8] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[9] <= 1'b0;
end
else begin
s_div_clk[9] <= ~s_div_clk[9];
end
end
always @(posedge s_div_clk[9] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[10] <= 1'b0;
end
else begin
s_div_clk[10] <= ~s_div_clk[10];
end
end
always @(posedge s_div_clk[10] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[11] <= 1'b0;
end
else begin
s_div_clk[11] <= ~s_div_clk[11];
end
end
always @(posedge s_div_clk[11] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[12] <= 1'b0;
end
else begin
s_div_clk[12] <= ~s_div_clk[12];
end
end
always @(posedge s_div_clk[12] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[13] <= 1'b0;
end
else begin
s_div_clk[13] <= ~s_div_clk[13];
end
end
always @(posedge s_div_clk[13] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[14] <= 1'b0;
end
else begin
s_div_clk[14] <= ~s_div_clk[14];
end
end
always @(posedge s_div_clk[14] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[15] <= 1'b0;
end
else begin
s_div_clk[15] <= ~s_div_clk[15];
end
end
always @(posedge s_div_clk[15] or negedge sys_rst)begin
if(!sys_rst)begin
s_div_clk[16] <= 1'b0;
end
else begin
s_div_clk[16] <= ~s_div_clk[16];
end
end
endmodule
但我
仿真图下面情况,
1.但我的仿真图里面的div_clk 信号没有出来,我在程序中用s_div_clk寄存器,存储地址线上的不同频率,让后把这个寄存器的值,赋值给输出端口div_clk,但仿真中div_clk信号没有出来,理论上div_clk上输出的就是整个二分频信号,现在我的地址线上都没有信号,有点搞不通。
2。还有lways @(posedge sys_clk or negedge sys_rst ) begin //50mhz晶振,LED2检测
if(!sys_rst)begin
count2 <= 32'h0000_0000;
end
else begin
if(count2 ==32'd20000_000)begin
led[2]<= ~led[2];
count2 <= 32'h0000_0000;
end
这个语句内,我加入复位信号后,LED2出现常亮,不闪烁。去除复位信号后,LED2 闪烁,不知道什么情况。
这个小程序,希望会FPGA的大神,能够指点一下,再次感激了,小弟不很会FPGA,在自学中有些语法规则不是很懂,希望大神能看看我的程序,谢谢
-
-
VDEE5M40_CPLD_v3.rar
下载积分: 积分 -1 分
557 KB, 下载次数: 2, 下载积分: 积分 -1 分
分频出来产生的这个data:s_div_clk直接作为时钟去作驱动,始终是不稳定,建议不要这样做,如果确实要的话,最好加个buf。至于led,没有仔细去看。
一周热门 更多>