当前位置:网站首页>[digital ic/fpga] detect the position of the last matching sequence
[digital ic/fpga] detect the position of the last matching sequence
2022-06-27 23:52:00 【FPGA silicon agriculture】
Title Description
Write a module , Enter a 64 Bit stream of bits , Identify and match out 101101 The last position of , And output position information .
Code
`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}; // High order input first
//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
Test platform
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
result

Input bitstream is data={20’d0,12’b101101101101,32’d0}, therefore , The position of the last matching sequence should be 20+6=26, In line with expectations .
边栏推荐
- Webserver flow chart -- understand the calling relationship between webserver modules
- VirtualBox extended dynamic disk size pit
- Storage structure of graph
- Zero foundation self-study SQL course | complete collection of date functions in SQL
- Stream + Nacos
- 搭建开源美观的数据库监控系统-Lepus
- 往前一步是优秀,退后一步是懵懂
- [tinyriscv verilator] branch transplanted to Da Vinci development board of punctual atom
- Technical implementation process of easycvr platform routing log function [code attached]
- golang使用mongo-driver操作——查(基础)
猜你喜欢

Zero foundation self-study SQL course | case function

c语言字符指针、字符串初始化问题

Detect objects and transfer images through mqtt

2022年PMP项目管理考试敏捷知识点(3)

C# Winform 读取Resources图片

Zero foundation self-study SQL course | complete collection of date functions in SQL

How to quote Chinese documents when writing a foreign language?

Practice torch FX: pytorch based model optimization quantization artifact

小芯片chiplet技术杂谈

How vivado adds timing constraints
随机推荐
Systematic learning + active exploration is the most comfortable way to get started!
【PCL自学:Segmentation3】基于PCL的点云分割:区域增长分割
c语言字符指针、字符串初始化问题
Introduction to quantitative trading
【剑指Offer】47. 礼物的最大价值
apipost脚本使用讲解一~全局变量
刚开始看英文文献,想问一下各位,最初应该怎么看进去?
撰写外文时怎样引用中文文献?
Download versions such as typora 1.2.5
【AI应用】NVIDIA GeForce RTX 3060的详情参数
How to solve the problem that the browser developed with CeF3 does not support flash
[AI application] detailed parameters of NVIDIA Tesla v100s-pcie-32gb
webService
fiddler 监听不到接口怎么办
如何找到外文文献对应的中文文献?
virtualbox扩展动态磁盘大小的坑
【剑指Offer】48. 最长不含重复字符的子字符串
[PCL self study: segmentation4] point cloud segmentation based on Min cut
Zero foundation self-study SQL course | if function
Golang uses Mongo driver operation - query (Advanced)