当前位置:网站首页>[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 .
边栏推荐
- 系统学习+主动探索,是最舒适的入门学习方式!
- virtualbox扩展动态磁盘大小的坑
- Applet referer
- Swing UI container (I)
- C language - date formatting [easy to understand]
- 【数字IC/FPGA】检测最后一个匹配序列的位置
- The latest cloud development wechat balance charger special effect applet source code
- c语言之字符串数组
- Small chip chiplet Technology
- 【AI应用】NVIDIA Tesla V100-PCIE-32GB的详情参数
猜你喜欢

Small chip chiplet Technology

C# Winform 读取Resources图片
![[PCL self study: pclplotter] pclplotter draws data analysis chart](/img/ca/db68d5fae392c7976bfc93d2107509.png)
[PCL self study: pclplotter] pclplotter draws data analysis chart

Swing UI container (I)

小芯片chiplet技术杂谈

What if Fiddler fails to listen to the interface

Discuz taobaoke website template / Dean taobaoke shopping style commercial version template

An analysis of C language functions

ClickOnce error deploying ClickOnce application - the reference in the manifest does not match the identity of the downloaded assembly

Online JSON to plaintext tool
随机推荐
Zero foundation self-study SQL course | complete collection of SQL basic functions
小芯片chiplet技术杂谈
golang - new和make的区别
[PCL self study: pclplotter] pclplotter draws data analysis chart
fiddler 监听不到接口怎么办
C# Winform 读取Resources图片
VirtualBox extended dynamic disk size pit
十大券商注册账户安全吗,会有风险吗?
企业架构师面试的100个问题
EXCEL 打印设置公共表头
超纲练习题不超纲
Cornernet由浅入深理解
[learn FPGA programming from scratch -48]: Vision - development and application of intelligent sensors
手把手教你移植 tinyriscv 到FPGA上
思源笔记订阅停止直接删云端数据嘛?
Is not null and in SQL= Difference between null
Zero foundation self-study SQL course | complete collection of date functions in SQL
seata
seata
使用cef3开发的浏览器不支持flash问题的解决