FGPA異步信號問題

FPGA在處理異步信號時,儘可能打1~2拍寄存器,不然在線調試會發現各類奇怪問題。異步


下面是verilog代碼
spa

在線調試發現,計數器在跳變調試

緣由是cmd_start由ARM輸出,與FPGA時鐘異步,須要打1~2拍寄存器code

reg [5:0] cmdcnt;
reg fl_cmd_start;
reg cmd_start_0,cmd_start_1;
//-----------------------cmd_start濾波------------------//(ARM輸出持續580ns的脈衝)
//cmd_start爲異步信號,這裏打兩拍寄存器(ARM與FPGA時鐘異步)
always @(posedge clk_50m) begin
        cmd_start_0 <= cmd_start;
        cmd_start_1 <= cmd_start_0;
end

always@(posedge clk_50m or negedge rst_n)
begin
    if(!rst_n) begin
        cmdcnt <= 6'd0;
        fl_cmd_start <= 0;
    end else begin
        if(cmd_start_1) begin
            if(cmdcnt==6'd24) fl_cmd_start <= 1'b1;
            cmdcnt <= cmdcnt + 1'b1;
        end else begin
            cmdcnt <= 6'd0;
            fl_cmd_start <= 0;
        end
    end
end

這樣修改後不會出現計數異常跳變blog

相關文章
相關標籤/搜索