2021年6月25日 星期五

HDLBits 3-bit LFSR (DE2-115)

 HDLBits 3-bit LFSR

Taken from 2015 midterm question 5. See also the first part of this question: mt2015_muxdff

Mt2015 muxdff.png

Write the Verilog code for this sequential circuit (Submodules are ok, but the top-level must be named top_module). Assume that you are going to implement the circuit on the DE1-SoC board. Connect the R inputs to the SW switches, connect Clock to KEY[0], and L to KEY[1]. Connect the Q outputs to the red lights LEDR.

希望我們結合實際的板子(DE1-SoC)和其外部接口(KEY&LED),實現一個線性移位寄存器電路。

使用 Verilog 實現上圖中的時序電路,(可以使用子模塊進行構建,但頂層要命名為 top_module)。假設你要在 DE1-SoC 教學板上實現這個電路,將輸入端口 r 連接到板子上的撥動開關,clock 端口接到按鍵 KEY[0],端口 L 接到按鍵 KEY[1]。輸出端口 Q 連接到板子上的紅色 LED。

module top_module (
input [2:0] SW,      // R
input [1:0] KEY,     // L and clk
output [2:0] LEDR);  // Q
    
    wire clk = KEY[0];
    wire load = KEY[1];
reg [2:0] LEDR_next;
    
    always@(*)begin
    if(load)begin
        LEDR_next = SW;
        end
        else begin
        LEDR_next[0] = LEDR[2];
    LEDR_next[1] = LEDR[0];
    LEDR_next[2] = LEDR[2] ^ LEDR[1];
        end
    end
    
    always@(posedge clk)begin
        LEDR <= LEDR_next;
    end
 endmodule

沒有留言:

張貼留言

WOKWI ESP32 LED Control , Node-Red MQTT SQLITE  

WOKWI ESP32 LED Control ,  Node-Red  MQTT SQLITE   const char broker[] = "test.mosquitto.org" ; //const char broker[] = "br...