当前位置:网站首页>【数字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,符合预期。
边栏推荐
- Spark bug practice (including bug:classcastexception; connectexception; NoClassDefFoundError; runtimeException, etc.)
- 新加坡国立大学|采用无模型强化学习方法评估能源效益数据中心的节能情况
- MySQL十八:写语句的执行过程
- Workflow automation low code is the key
- OData - API using SAP API hub in SAP S4 op
- 【你真的会用ES吗】ES基础介绍(二)
- Mysql database experiment report (I)
- Teach you how to print your own log -- how to customize log4j2 components
- 华为伙伴暨开发者大会2022 | 麒麟软件携手华为共建计算产业,共创数智未来
- Passerelle de service pour les microservices
猜你喜欢

EasyCVR平台路由日志功能的技术实现过程【附代码】

MySQL数据库 实验报告(一)

SQL Server 2016详细安装教程(附注册码和资源)

打造南沙“强芯”,南沙首届IC Nansha大会召开

因美纳陷数据泄露“丑闻”:我国基因数据安全能交给美企吗?

Mysql database experiment report (I)

How to use RPA to achieve automatic customer acquisition?

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

Character interception triplets of data warehouse: substrb, substr, substring

第一性原理(最优解理论)
随机推荐
Ice cream or snow "high"?
[electron] 基础学习
跟着存档教程动手学RNAseq分析(一)
Hiplot 在线绘图工具的本地运行/开发库开源
Livox Lidar+海康Camera 基于loam的实时三维重建生成RGB彩色点云
Learn rnaseq analysis by following the archiving tutorial (I)
[electron] basic learning
STM32与RC522简单公交卡系统的设计
Avoid using 100vh[easy to understand] at mobile terminal
[js]var, let,const 的区别
Spatial relation query and graph based query in secondary development of ArcGIS Engine
用pytorch进行CIFAR-10数据集分类
Liuleifeng, a "good man in Guangzhou" in the first quarter of 2022, has a strong sense of integrity and food safety
Death of 5 yuan youkuang in Yuanqi forest
Livox lidar+ Hikvision camera real-time 3D reconstruction based on loam to generate RGB color point cloud
mongodb基础操作之聚合操作、索引优化
各种loam总结(激光slam)
pytorch实现kaggle猫狗识别
2022年第一季度“广州好人”刘磊峰:具有强烈的诚信意识和食品安全意识
Brief introduction to game phone platform