原创 Xilinx FPGA学习笔记(2)——串并转换移位模块设计

2017-10-22 20:10 4969 9 9 分类: FPGA/CPLD


8bit 串进并出,并进串出

1、源代码

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2017/10/22 18:09:21
// Design Name:
// Module Name: shift
// Project Name:
// Target Devices:
// Tool Versions:
// Description:  8bit并进,1bit串出;1bit串进,8bit并出

// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////


module shift(
input clk,  
input sft_clk,  //移位时钟
input rst,
input is_load,  //加载数据信号
input [7:0] data_in,  //输入8bit并行数据
input sft_in,  //1bit 串行输入
input sft_en,  // 移位使能
output sft_out,   // 1bit 串行输出
output [7:0] data_out  // 8bit 并行输出
);

reg [7:0] data_temp;  

assign data_out = data_temp;
assign sft_out = data_temp[7];  

/*
数据从MSB开始移出,到串行输出;
在使能后,每个移位时钟上升沿,串行输入,不断从LSB往MSB

*/
always @(posedge clk)begin
if(!rst)
data_temp <= 0;

else if(is_load)
data_temp <= data_in; //加载数据

else if(sft_clk)begin   //移位时钟上升沿移位
if(sft_en)
data_temp <= {data_temp[6:0],sft_in};

end

end

endmodule


RTL 视图


仿真代码

`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 2017/10/22 19:01:06
// Design Name:
// Module Name: simu
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////


module simu(

);

reg clk;
reg sft_clk;
reg rst;
reg is_load;
reg [7:0] data_in;
reg sft_in;
reg sft_en;

wire sft_out;
wire [7:0] data_out;

shift inst(
.clk(clk),
.sft_clk(sft_clk),
.rst(rst),
.is_load(is_load),
.data_in(data_in),
.sft_in(sft_in),
.sft_en(sft_en),

.sft_out(sft_out),
.data_out(data_out)
);  

initial begin
clk = 0;
sft_clk = 0;
rst = 0;
is_load = 0;
data_in = 0;
sft_in = 0;
sft_en = 0;

#10 clk = ~clk;
#10 clk = ~clk;
#10 clk = ~clk;

rst = 1; //复位完成

forever #10 clk = ~clk;
end  

reg [3:0]  C1;

always @(posedge clk)begin
sft_clk = ~sft_clk;
end

always @(posedge clk)begin
if(!rst)begin
is_load <= 1'b1;
data_in <= 8'haa;
sft_in <= 1'b0;
C1 <= 4'd0;    
end

else if(sft_clk)begin // 当 C1<8 的时候,使能移位时钟
if( C1 < 4'd8)begin
is_load <= 1'b0;
sft_en <= 1'b1;
sft_in <= !sft_in;
C1 <= C1 + 1'b1;
end
else begin //当 C1>8的时候,加载数据0
sft_en <= 1'b0;
C1 <= 4'd0;
data_in <= 8'h00;
is_load <= 1'b1;
end

end

end

initial begin
$monitor($time,,,"sft_out=%b  data_out=%b ",sft_out,data_out);

end

endmodule

仿真波形


打印输出




文章评论0条评论)

登录后参与讨论
相关推荐阅读
LoneSurvivor 2018-02-25 08:26
C++输入/输出流(2)
1. get()函数#include<iostream>using namespace std;int main(){    char s1[80], s2[...
LoneSurvivor 2018-02-23 12:19
C++输入/输出流(1)
1. 输入/输出流类层次 C++的输入/输出流类库是用派生方法建立起的,它有2个平行的基类,streambuf和ios。其他的流类都是从这两个基类直接或间接派生的。1.1   s...
LoneSurvivor 2018-02-19 11:36
C++多态(4)——特殊运算符重载和类类型转换
1.“++”和“--”的重载     运算符“++”和“--”的重载要区分前置和后置两种形式。如果不区分前置和后置,则使用operator++()或operator—()即可,否...
LoneSurvivor 2018-02-12 11:15
C++多态(3)——运算符重载
1.     运算符重载的定义     运算符重载也是实现多态的一个重要手段。运算符重载实现的是编译时的多态,即静态多态性。C++预定义的...
LoneSurvivor 2018-02-12 10:31
C++多态(2)——纯虚函数与抽象类
   抽象类是一种特殊的类,它提供了统一的操作界面。建立抽象类是为了多态地使用抽象类的成员函数。抽象类是包含纯虚函数的类。 1.     ...
LoneSurvivor 2018-02-11 16:24
C++多态(1)
1.     多态      多态是人类思维方式的一种直接模拟,多态性是指不同对象接收到相同的消息时,根据对象类的不同而产生不同...
我要评论
0
9
1
2
3
4
5
6
7
8
9
0
关闭 站长推荐上一条 /3 下一条