<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ` `UART是常用模塊,無論是調試還是用于使用過程中的數據傳輸,都很重要。該模塊使用FPGA實現時候,一般接收數據比較容易實現,但是發送數據容易出錯,原因在于時鐘不精確,導致數據接收錯誤。 ` `對于50MHz時鐘的晶振,一般使用9600的波特率,因為我們需要得到9600*16Hz的時鐘,使用PLL可以得到精確的這個值。 ## UART接收模塊 ``` `timescale 1ns/1ns module uart_rd ( input i_rst_n, input i_clk, output [7 : 0] o_rx_data, //UART數據接收接收到的數據 output o_uart_rx_busy, //UART數據接收模塊接收數據忙 output o_uart_rx_error, //UART數據接收幀出錯 input i_uart_rx //UART串行數據輸入 ); reg r_uart_rx_buf; reg r_uart_rx_falling; reg [3 : 0] r_sample_cnt; //采樣計數器 reg [1 : 0] cstate, nstate; parameter [1 : 0] idle = 2'b00; parameter [1 : 0] receive_data = 2'b01; parameter [1 : 0] receive_done = 2'b10; reg [3 : 0] r_shift_cnt; reg [9 : 0] r_shift; reg [7 : 0] r_rx_data; reg r_uart_rx_error; assign o_rx_data = r_rx_data; assign o_uart_rx_busy = (cstate == idle)? 1'b0 : 1'b1; assign o_uart_rx_error = r_uart_rx_error; //*********************************PROCESS************************************** // FUNCTION :捕獲UART數據的下降沿 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) begin r_uart_rx_buf <= 1'b0; r_uart_rx_falling <= 1'b0; end else begin r_uart_rx_buf <= i_uart_rx; r_uart_rx_falling <= ~i_uart_rx & (r_uart_rx_buf); end end //*********************************PROCESS************************************** // FUNCTION :UART下個狀態到現狀態的轉化 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) cstate <= idle; else cstate <= nstate; end //*********************************PROCESS************************************** // FUNCTION :UART下個狀態的轉化 //****************************************************************************** always @(*) begin case(cstate) idle : if(1'b1 == r_uart_rx_falling) nstate = receive_data; else nstate = idle; receive_data : if(4'd10 == r_shift_cnt) nstate = receive_done; else nstate = receive_data; receive_done : nstate = idle; default : nstate = idle; endcase end //*********************************PROCESS************************************** // FUNCTION :UART在現狀態的操作 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) begin r_shift <= 10'b1111111111; r_shift_cnt <= 4'd0; r_sample_cnt <= 4'd0; r_rx_data <= 8'd0; r_uart_rx_error <= 1'b0; end else begin if(receive_data == cstate) if(4'd5 == r_sample_cnt) begin r_shift_cnt <= r_shift_cnt + 4'd1; r_shift <= {i_uart_rx, r_shift[9 : 1]}; r_sample_cnt <= r_sample_cnt + 4'd1; end else r_sample_cnt <= r_sample_cnt + 4'd1; else if(receive_done == cstate) begin r_shift_cnt <= 4'd0; r_shift <= 10'b1111111111; r_rx_data <= r_shift[8 : 1]; if(1'b0 == r_shift[9]) r_uart_rx_error <= 1'b1; else r_uart_rx_error <= 1'b0; r_shift_cnt <= 4'd0; r_sample_cnt <= 4'd0; end else begin r_shift <= 10'b1111111111; r_shift_cnt <= 4'd0; r_sample_cnt <= 4'd0; end end end endmodule ``` ## UART發送模塊 ``` `timescale 1ns/1ns module uart_tx ( input i_rst_n, input i_clk, input i_tx_order, //UART數據發送指令 input [7 : 0] i_tx_data, //UART發送的數據 output o_uart_tx_busy, //UART發送模塊忙 output o_uart_tx //UART數據輸出 ); reg r_tx_order_buf; reg r_tx_order_rising; // reg [4 : 0] r_div_cnt; //時鐘分頻計數器 // reg r_div_clk; //分頻時鐘信號 reg [1 : 0] cstate, nstate; parameter [1 : 0] idle = 2'b00; parameter [1 : 0] load_data = 2'b01; parameter [1 : 0] shift_data = 2'b10; reg [3 : 0] r_shift_cnt; reg [9 : 0] r_shift; reg [3 : 0] r_hold_cnt; assign o_uart_tx = r_shift[0]; assign o_uart_tx_busy = (cstate == idle)? 1'b0 : 1'b1; ////*********************************PROCESS************************************** //// FUNCTION :產生分頻時鐘 ////****************************************************************************** // // always @(posedge i_clk, negedge i_rst_n) // begin // if(1'b0 == i_rst_n) // begin // r_div_cnt <= 4'd0; // r_div_clk <= 1'b0; // end // else // begin // r_div_cnt <= r_div_cnt + 4'd1; // r_div_clk <= r_div_cnt[3]; // end // end //*********************************PROCESS************************************** // FUNCTION :捕獲UART發送指令的上升沿 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) begin r_tx_order_buf <= 1'b0; r_tx_order_rising <= 1'b0; end else begin r_tx_order_buf <= i_tx_order; r_tx_order_rising <= i_tx_order & (~r_tx_order_buf); end end //*********************************PROCESS************************************** // FUNCTION :UART下個狀態轉化到現狀態 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) cstate <= idle; else cstate <= nstate; end //*********************************PROCESS************************************** // FUNCTION :UART下個狀態轉化進程 //****************************************************************************** always @(*) begin case(cstate) idle : if(1'b1 == r_tx_order_rising) nstate = shift_data; else nstate = idle; shift_data : if(4'd9 == r_shift_cnt) nstate = idle; else nstate = shift_data; default : nstate = idle; endcase end //*********************************PROCESS************************************** // FUNCTION :UART在各個現狀態下的操作 //****************************************************************************** always @(posedge i_clk, negedge i_rst_n) begin if(1'b0 == i_rst_n) begin r_shift <= 10'b1111111111; r_shift_cnt <= 4'd0; r_hold_cnt <= 4'd0; end else begin if(idle == cstate && 1'b1 == r_tx_order_rising) begin r_shift_cnt <= 4'd0; r_shift <= {1'b1, i_tx_data, 1'b0}; r_hold_cnt <= r_hold_cnt + 4'd1; end else if(shift_data == cstate) begin r_hold_cnt <= r_hold_cnt + 4'd1; if(4'd15 == r_hold_cnt) begin r_shift_cnt <= r_shift_cnt + 4'd1; r_shift <= {1'b1, r_shift[9 : 1]}; end end else begin r_shift <= 10'b1111111111; r_shift_cnt <= 4'd0; end end end endmodule ``` ## 時鐘 ` `時鐘使用IP核實現。 ## 測試模塊 ``` module top( input wire clk50, //rst,// output reg led, //用于指示 input wire rxd, output wire txd ); wire rx_busy;//16倍波特率 //reset //*********************************PROCESS************************************** // 復位模塊 //****************************************************************************** reg rst_n ; reg [9:0]delay_cnt; always@(posedge clk50) begin if(delay_cnt>=10'd1000)begin delay_cnt <= delay_cnt; rst_n <= 1'b1; end else begin rst_n <= 1'b0; delay_cnt <= delay_cnt + 1'b1; end end /********************************************************** //串口接口 **********************************************************/ wire [7:0]data_temp; //wire rx_busy; uart_interface uart_inst_int ( .clk50 (clk50) , .rst_n (rst_n) , .rxd (rxd) , .txd (txd) , .tx_data(data_temp) , .rx_data(data_temp) , .rx_busy(rx_busy) , .tx_start(!rx_busy), .tx_busy() ); //指示燈 //assign txd = led; reg [31:0]cnt; //always@(posedge clk50) //begin // if(cnt >= 32'd25000000 - 1) // begin // cnt <= 0; // led <=~led; // end // else begin // cnt <= cnt + 1'b1 ; // end //end always@(posedge rx_busy) led<=~led; endmodule ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看