⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 posi.v

📁 基于ATEREAL EPM1270T144C5N CPLD 压力传感器数据采集源码 开发软件 Quartus II
💻 V
字号:
module posi(clk,rst,position_rever,qea_now,qea_old,qeb_now,qeb_old,count,db_clr);
input         db_clr;
input         clk,rst;
input         position_rever;
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           mb;
reg           clr;

always @(posedge clk or negedge rst)
begin
tempp={qea_now,qeb_now};
tempt={qea_old,qeb_old};
if(!rst)
begin 
  count<=32'b00000000000000000000000000000000;
  clr<=1'b0;
end
else if(clr!=db_clr)
begin
  count<=32'b00000000000000000000000000000000;
  clr<=db_clr;
end
else if(position_rever==1'b0)
begin
clr<=db_clr;
case(tempp)
    2'b00:begin
          if(tempt==2'b01) 
            count<=count+32'b00000000000000000000000000000001;
          else if(tempt==2'b10)
            count<=count-32'b00000000000000000000000000000001;
          else
            count<=count;
          end
    2'b01:begin
          if(tempt==2'b00)
            count<=count-32'b00000000000000000000000000000001;
          else if(tempt==2'b11)
            count<=count+32'b00000000000000000000000000000001;
          else  
            count<=count;
          end
    2'b10:begin
          if(tempt==2'b11)
            count<=count-32'b00000000000000000000000000000001;
          else if(tempt==2'b00)
            count<=count+32'b00000000000000000000000000000001;
          else 
            count<=count;
          end
    2'b11:begin
          if(tempt==2'b01)
            count<=count-32'b00000000000000000000000000000001;
          else if(tempt==2'b10)
            count<=count+32'b00000000000000000000000000000001;
          else 
            count<=count;
          end
  default:  count<=count;
endcase
end
else 
begin
clr<=db_clr;
case(tempp)
    2'b00:begin
          if(tempt==2'b01) 
            count<=count-32'b00000000000000000000000000000001;
          else if(tempt==2'b10)
            count<=count+32'b00000000000000000000000000000001;
          else
            count<=count;
          end
    2'b01:begin
          if(tempt==2'b00)
            count<=count+32'b00000000000000000000000000000001;
          else if(tempt==2'b11)
            count<=count-32'b00000000000000000000000000000001;
          else  
            count<=count;
          end
    2'b10:begin
          if(tempt==2'b11)
            count<=count+32'b00000000000000000000000000000001;
          else if(tempt==2'b00)
            count<=count-32'b00000000000000000000000000000001;
          else 
            count<=count; 
          end
    2'b11:begin
          if(tempt==2'b01)
            count<=count+32'b00000000000000000000000000000001;
          else if(tempt==2'b10)
            count<=count-32'b00000000000000000000000000000001;
          else 
            count<=count;
          end
  default:  count<=count;
endcase
end
end

endmodule

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -