当前位置:网站首页>【数字IC/FPGA】检测最后一个匹配序列的位置
【数字IC/FPGA】检测最后一个匹配序列的位置
2022-06-27 20:44:00 【FPGA硅农】
题目描述
编写一个模块,输入一个64比特的比特流,识别匹配出101101的最后的位置,并输出位置信息。
代码
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/06/21 10:34:41
// Design Name:
// Module Name: top
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module top(
input logic clk,
input logic rst,
input logic valid,
input logic din,
output logic done,
output logic [5:0] pos
);
//101101
logic [5:0] shift_reg;
logic [5:0] cnt;
//cnt
[email protected](posedge clk,posedge rst)
if(rst)
cnt<=0;
else if(valid)
begin
if(cnt==64-1)
cnt<=0;
else
cnt<=cnt+1;
end
//shift_reg
[email protected](posedge clk,posedge rst)
if(rst)
shift_reg<=0;
else if(valid)
shift_reg<={
shift_reg[4:0],din}; //高位先输入
//pos
[email protected](posedge clk,posedge rst)
if(rst)
begin
pos<=64;
end
else if(shift_reg==6'b101101)
begin
pos<=cnt-6;
end
//done
[email protected](posedge clk,posedge rst)
if(rst)
done<=0;
else
done<=(cnt==64-1&&valid)?1:0;
endmodule
测试平台
module test;
logic clk;
logic rst;
logic valid;
logic din;
logic done;
logic [5:0] cnt;
logic [5:0] pos;
logic [63:0] data;
//
initial
begin
//data={12'b101101101101,52'd0};
data={
20'd0,12'b101101101101,32'd0};
end
//clk
initial
begin
clk=0;
forever
#5 clk=~clk;
end
//rst
initial
begin
rst=1;
#100
rst=0;
end
//valid,din
initial
begin
valid<=0;
cnt<=0;
wait(rst==1'b0);
@(posedge clk);
repeat(64)
begin
valid<=1;
din<=data[63-cnt];
cnt<=cnt+1;
@(posedge clk);
end
valid<=0;
end
top U(.*);
/* input logic clk, input logic rst, input logic valid, input logic din, output logic done, output logic [5:0] pos ); */
endmodule
结果

输入比特流为data={20’d0,12’b101101101101,32’d0},因此,最后匹配的序列的位置应该是20+6=26,符合预期。
边栏推荐
- [electron] basic learning
- Spark BUG實踐(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
- [electron] 基础学习
- 凌云出海记 | 沐融科技&华为云:打造非洲金融SaaS解决方案样板
- Using the cucumber automated test framework
- Arcgis-engine二次开发之空间关系查询与按图形查询
- 通过tidymodels使用XGBOOST
- "Top stream Aidou manufacturing machine" cooperates with four industrial capitals to become LP
- 打造南沙“强芯”,南沙首届IC Nansha大会召开
- [network] common request methods
猜你喜欢

PE buys a underwear company

Kill the general and seize the "pointer" (Part 2)

“顶流爱豆制造机”携手四个产业资本,做LP

What problems should be paid attention to in the serpentine wiring of PCB?

如何设置企业微信群机器人定时发消息?

雪糕还是雪“高”?

"I make the world cooler" 2022 Huaqing vision R & D product launch was a complete success

Death of 5 yuan youkuang in Yuanqi forest

跨系统数据一致性问题解决方案汇总

基于 ESXi 的黑群晖 DSM 7.0.1 安装 VMware Tools
随机推荐
Workflow automation low code is the key
华为伙伴暨开发者大会2022 | 麒麟软件携手华为共建计算产业,共创数智未来
"Top stream Aidou manufacturing machine" cooperates with four industrial capitals to become LP
跟着存档教程动手学RNAseq分析(三):使用DESeq2进行计数标准化
[electron] basic learning
ABAP随笔-关于ECC后台server读取Excel方案的想法
6G显卡显存不足出现CUDA Error:out of memory解决办法
PE买下一家内衣公司
Hiplot 在線繪圖工具的本地運行/開發庫開源
Batch processing - Excel import template 1.1- support multiple sheet pages
Spark bug Practice (including bug: classcastexception; connectexception; noclassdeffounderror; runtimeexceptio, etc.)
Spark BUG實踐(包含的BUG:ClassCastException;ConnectException;NoClassDefFoundError;RuntimeExceptio等。。。。)
游戏手机平台简单介绍
Azure Kinect DK realizes 3D reconstruction (PC non real time version)
【你真的会用ES吗】ES基础介绍(二)
基于 ESXi 的黑群晖 DSM 7.0.1 安装 VMware Tools
移动端避免使用100vh[通俗易懂]
MapReduce初级编程实践
netERR_CONNECTION_REFUSED 解决大全
“顶流爱豆制造机”携手四个产业资本,做LP