modu5.v
来自「基于ATEREAL EPM1270T144C5N CPLD 压力传感器数据采集源」· Verilog 代码 · 共 67 行
V
67 行
module modu5(clk,rst,qea_now,qea_old,qeb_now,qeb_old,count,db_clr);
input db_clr;
input clk,rst;
input qea_now,qeb_now;
input qea_old,qeb_old;
output[31:0] count;
reg[31:0] count;
reg[1:0] tempp;
reg[1:0] tempt;
reg clr;
always @(posedge clk or negedge rst)
begin
tempp={qea_now,qeb_now};
tempt={qea_old,qeb_old};
if(!rst)
begin
count<=32'h00000000;
clr<=1'b0;
end
else if(clr!=db_clr)
begin
count<=32'h00000000;
clr<=db_clr;
end
else
begin
clr<=db_clr;
case(tempp)
2'b00:begin
if(tempt==2'b01)
count<=count+32'h00000001;
else if(tempt==2'b10)
count<=count-32'h00000001;
else
count<=count;
end
2'b01:begin
if(tempt==2'b00)
count<=count-32'h00000001;
else if(tempt==2'b11)
count<=count+32'h00000001;
else
count<=count;
end
2'b10:begin
if(tempt==2'b11)
count<=count-32'h00000001;
else if(tempt==2'b00)
count<=count+32'h00000001;
else
count<=count;
end
2'b11:begin
if(tempt==2'b01)
count<=count-32'h00000001;
else if(tempt==2'b10)
count<=count+32'h00000001;
else
count<=count;
end
default:count<=count;
endcase
end
end
endmodule
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?