FPGA移位寄存器实验
实验目的
(1)熟悉Quatus18.1的软件应用
(2)熟悉ip核的调用
(3)学习和熟悉移位寄存器的设计
实验环境
Quartus Prime 18.1标准版
Cyclone IV EP4CE6F17C8
测试工具:Signal Tap、In-Systeam Source and Probes Editor
实验原理:
1)系统原理
移位寄存器需要将寄存器中的各位数据在移位控制信号的作用下,依次向高位或地位进行移位。
2)电路原理图
定义输入信号:din、ds;
定义模式信号:mode;
定义输出信号:dout;
其中调用ip核得到的RTL视图如下:
3)代码实现
模块代码:
module shift_reg(
input rst_n ,
input clk ,
input [3:0] din ,
input [1:0] mode ,
input ds ,
output [3:0] dout
);
reg [3:0] data_r ;
always@(posedge clk or negedge rst_n)
if(!rst_n)
data_r<=0;
else begin
case({mode,ds})
3'b000:data_r <= data_r;//保持
3'b001:data_r <= data_r;//保持
3'b010:data_r <= {1'b0,data_r[3:1]};//右移 移入0
3'b011:data_r <= {1'b1,data_r[3:1]};//右移 移入1
3'b100:data_r <= {data_r[2:0],1'b0};//左移 移入0
3'b101:data_r <= {data_r[2:0],1'b1};//左移 移入1
3'b110:data_r <= din;//并行输入
3'b111:data_r <= din;//并行输入
default:data_r <= data_r;
endcase
end
assign dout = data_r ;
endmodule
顶层文件代码:
module top(
input clk ,
input rst_n ,
output [3:0] dout
);
wire [3:0] din ;
wire [1:0] mode ;
wire ds ;
shift_reg u_shift_reg(
.rst_n(rst_n ),
.clk (clk ),
.din (din ),
.mode (mode ),
.ds (ds ),
.dout (dout )
);
issp u_issp (
.source ({din,mode,ds}), // sources.source
.probe (dout ) // probes.probe
);
endmodule
4)测试结果
打开In-Systeam Source and Probes Editor测试软件。
其中的source[0]对应是输入信号ds;
其中的source[1]对应是模式信号mode[0];
其中的source[2]对应是模式信号mode[1];
其中的source[3]对应是输入信号din[0];
其中的source[4]对应是输入信号din[1];
其中的source[5]对应是输入信号din[2];
其中的source[6]对应是输入信号din[3];
而后,我们将输入信号ds、模式信号mode[0]、模式信号mode[1]、信号按键din[0]都置为1时,输出信号dout也为1h.如下图: