序列信号发生和检测器设计
实验程序:
//counter.v
module counter(clk,en,rst,m,sel,SG);
[2:0] sel;
input clk,en,rst,m;
output reg[7:0] SG;
output reg
clk0;
reg
reg
[3:0] gw,sw,bw,a;
reg [11:0] mod,q;
reg [7:0] cnt;
always @(posedge clk)//100 分频
begin cnt=cnt+1;
if(cnt==99)
begin clk0=1'b1; cnt=0; end
//clk 数码管扫描频率,clk0 计数频率
else clk0=1'b0;
if(sel<2) sel=sel+1;
else sel=0;//sel 为数码管选择
gw=q[3:0];
sw=q[7:4];
bw=q[11:8];
end
always @(sel)
begin
case(sel)
2: a=gw; //0 数码管为个位
1: a=sw; //1 数码管为十位
0: a=bw; //2 数码管为百位
default: a=0;
endcase
case (a)
0:SG<=8'b00111111; 1:SG<=8'b00000110;
2:SG<=8'b01011011; 3:SG<=8'b01001111;
4:SG<=8'b01100110; 5:SG<=8'b01101101;
6:SG<=8'b01111101; 7:SG<=8'b00000111;
8:SG<=8'b01111111; 9:SG<=8'b01101111; //8 段译码值
default: SG=8'b11111111;
endcase
end
always @(m)
if(m==0) mod=12'b000000100010;
mod=12'b000100000001;
else
//模值 22
//模值 101
always @(posedge clk0,negedge rst)
begin
if(!rst)
q=0;
else if(en)
begin
if(q