CPLD数码管的简单问题(verilogHDL)?
时间:10-02
整理:3721RD
点击:
module seg7(
clk,rst_n,
sm_cs_n,sm_db
);
input clk;
input rst_n;
output [1:0] sm_cs_n;
output reg[6:0] sm_db;
reg[24:0] cnt;
always @(posedge clk or negedge rst_n)
if(!rst_n) cnt <= 25'd0;
else cnt <= cnt +1'b1;
reg[3:0] num;
always @(posedge clk or negedge rst_n)
if(!rst_n) num <= 4'd0;
else if(cnt == 25'h0ffffff) num <= num +1;
parameter seg0 = 7'h3f,
seg1 = 7'h06,
seg2 = 7'h5b,
seg3 = 7'h4f,
seg4 = 7'h66,
seg5 = 7'h6d,
seg6 = 7'h7d,
seg7 = 7'h07,
seg8 = 7'h7f,
seg9 = 7'h6f,
sega = 7'h77,
segb = 7'h7c,
segc = 7'h39,
segd = 7'h5e,
sege = 7'h79,
segf = 7'h71;
always @(num)
case(num)
4'h0: sm_db <= seg0;
4'h1: sm_db <= seg1;
4'h2: sm_db <= seg2;
4'h3: sm_db <= seg3;
4'h4: sm_db <= seg4;
4'h5: sm_db <= seg5;
4'h6: sm_db <= seg6;
4'h7: sm_db <= seg7;
4'h8: sm_db <= seg8;
4'h9: sm_db <= seg9;
4'ha: sm_db <= sega;
4'hb: sm_db <= segb;
4'hc: sm_db <= segc;
4'hd: sm_db <= segd;
4'he: sm_db <= sege;
4'hf: sm_db <= segf;
default : ;
endcase
assign sm_cs_n = 2'b00;
endmodule
/***********************
reg[3:0] num;
always @(posedge clk or negedge rst_n)
if(!rst_n) num <= 4'd0;
else if(cnt == 25'h0ffffff) num <= num +1;
************************/
问题:这是两个数码管同时从0--f循环变化。而num是当cnt==25'h0fffff时,加一。说明num只会不断加一,可能加到1,2,3,4,5,,,,15,16,17,18,19,20,,,,那么,数码管只会从0--f,然后就木有变化了。但是,事实上,数码管在从0--f不断的循环变化(这是正确的实验现象),我就是有点不理解而已,求大神告知!
clk,rst_n,
sm_cs_n,sm_db
);
input clk;
input rst_n;
output [1:0] sm_cs_n;
output reg[6:0] sm_db;
reg[24:0] cnt;
always @(posedge clk or negedge rst_n)
if(!rst_n) cnt <= 25'd0;
else cnt <= cnt +1'b1;
reg[3:0] num;
always @(posedge clk or negedge rst_n)
if(!rst_n) num <= 4'd0;
else if(cnt == 25'h0ffffff) num <= num +1;
parameter seg0 = 7'h3f,
seg1 = 7'h06,
seg2 = 7'h5b,
seg3 = 7'h4f,
seg4 = 7'h66,
seg5 = 7'h6d,
seg6 = 7'h7d,
seg7 = 7'h07,
seg8 = 7'h7f,
seg9 = 7'h6f,
sega = 7'h77,
segb = 7'h7c,
segc = 7'h39,
segd = 7'h5e,
sege = 7'h79,
segf = 7'h71;
always @(num)
case(num)
4'h0: sm_db <= seg0;
4'h1: sm_db <= seg1;
4'h2: sm_db <= seg2;
4'h3: sm_db <= seg3;
4'h4: sm_db <= seg4;
4'h5: sm_db <= seg5;
4'h6: sm_db <= seg6;
4'h7: sm_db <= seg7;
4'h8: sm_db <= seg8;
4'h9: sm_db <= seg9;
4'ha: sm_db <= sega;
4'hb: sm_db <= segb;
4'hc: sm_db <= segc;
4'hd: sm_db <= segd;
4'he: sm_db <= sege;
4'hf: sm_db <= segf;
default : ;
endcase
assign sm_cs_n = 2'b00;
endmodule
/***********************
reg[3:0] num;
always @(posedge clk or negedge rst_n)
if(!rst_n) num <= 4'd0;
else if(cnt == 25'h0ffffff) num <= num +1;
************************/
问题:这是两个数码管同时从0--f循环变化。而num是当cnt==25'h0fffff时,加一。说明num只会不断加一,可能加到1,2,3,4,5,,,,15,16,17,18,19,20,,,,那么,数码管只会从0--f,然后就木有变化了。但是,事实上,数码管在从0--f不断的循环变化(这是正确的实验现象),我就是有点不理解而已,求大神告知!
原因在于你的num是4位的寄存器,当计数到f时寄存器溢出,重新从0开始。建议你好好看看verilog语法,防止出现这样的低级错误认识。下载程序之前先仿真,通过仿真波形观察写的时序是否达到要求。祝好~~
你说的在理,4位寄存器溢出
学习中希望能从电子发烧论坛中与大家获得交流
谢谢