当前位置:网站首页>Digital IC hand tearing code -- voting device
Digital IC hand tearing code -- voting device
2022-07-02 16:48:00 【FPGA silicon agriculture】
subject
Design a voting device , Input as a 5bit Vector , by 1 Agree with , by 0 Express disagreement with , When the number of people who agree is greater than the number of people who do not agree , Voter output is 1, Otherwise 0.
Ideas : One way is in statistical vectors 1 The number of , If greater than or equal to 3, The output 1, Otherwise output 0. Another way is to consider all possible situations , in fact , As long as the value of three bits is 1, Then the voter outputs 1, Therefore, enumeration can be carried out accordingly ( C 5 3 = 10 C_5^3=10 C53=10), Get the final result .
Code
`timescale 1ns / 1ps
//
// Company:
// Engineer:
//
// Create Date: 2022/07/01 15:19:05
// 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 [4:0] vote,
output logic r1,
output logic r2
);
//1
[email protected](posedge clk,posedge rst)
if(rst)
r1<=0;
else
r1<=(vote[0]&vote[1]&vote[2])
|(vote[0]&vote[1]&vote[3])
|(vote[0]&vote[1]&vote[4])
|(vote[0]&vote[2]&vote[3])
|(vote[0]&vote[2]&vote[4])
|(vote[0]&vote[3]&vote[4])
|(vote[1]&vote[2]&vote[3])
|(vote[1]&vote[2]&vote[4])
|(vote[1]&vote[3]&vote[4])
|(vote[2]&vote[3]&vote[4]);
//2
logic s1;
logic c1;
logic s2;
logic c2;
logic [2:0] sum;
assign {
c1,s1}=vote[0]+vote[1]+vote[2];
assign {
c2,s2}=vote[3]+vote[4];
assign sum={
c1,s1}+{
c2,s2};
[email protected](posedge clk,posedge rst)
if(rst)
r2<=0;
else if(sum>=3)
r2<=1;
else
r2<=0;
endmodule
Test platform
module test;
logic clk;
logic rst;
logic [4:0] vote;
logic r1;
logic r2;
logic error;
//clk
initial
begin
clk=0;
forever
#5 clk=~clk;
end
//rst
initial
begin
rst=1;
#100
rst=0;
end
//
[email protected](posedge clk,posedge rst)
if(rst)
vote<=0;
else
vote<=$urandom%32;
//
assign error=(r1!=r2)?1:0;
top U(.*
/* input logic clk, input logic rst, input [4:0] vote, output logic r1, output logic r2 */
);
endmodule
result
summary
about N Input voter (N It's odd ), We can also use a similar method :
1. Find by adder 1 The number of , If sum is greater than (N-1)/2, The output of 1
2. Enumerate this N One input (N+1)/2 Combine ( common C N ( N + 1 ) / 2 C_N^{(N+1)/2} CN(N+1)/2 term ), Then put them together .
边栏推荐
- 自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
- A week of short video platform 30W exposure, small magic push helps physical businesses turn losses into profits
- 电脑管理员权限在哪里可以打开
- ⌈ 2022 ⌋ how to use webp gracefully in projects
- LeetCode 1. Sum of two numbers
- False summer vacation
- LeetCode 6. Z 字形变换 (N字形变换)
- john爆破出現Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
- 有赞和腾讯云、阿里云一同摘得“中国企业云科技服务商50强”[通俗易懂]
- Interview summary of large factories
猜你喜欢
触发器:Mysql实现一张表添加或删除一条数据,另一张表同时添加
历史上的今天:支付宝推出条码支付;分时系统之父诞生;世界上第一支电视广告...
大厂面试总结大全
Résumé de l'entrevue de Dachang Daquan
小鹏P7雨天出事故安全气囊没有弹出 官方回应:撞击力度未达到弹出要求
大廠面試總結大全
[North Asia data recovery] data recovery case of raid crash caused by hard disk disconnection during data synchronization of hot spare disk of RAID5 disk array
Sim2real environment configuration tutorial
DGraph: 大规模动态图数据集
Today in history: Alipay launched barcode payment; The father of time-sharing system was born; The first TV advertisement in the world
随机推荐
外企高管、连续创业者、瑜伽和滑雪高手,持续迭代重构的程序人生
SSM integration exception handler and project exception handling scheme
流批一体在京东的探索与实践
DigiCert SSL证书支持中文域名申请吗?
Aujourd'hui dans l'histoire: Alipay lance le paiement par code à barres; La naissance du père du système de partage du temps; La première publicité télévisée au monde...
HMS core machine learning service helps zaful users to shop conveniently
Global and Chinese markets for airport baggage claim conveyors 2022-2028: technology, participants, trends, market size and share Research Report
渗透工具-内网权限维持-Cobalt strike
PCL least median square method fitting plane
Where can I open computer administrator permissions
头条 | 亚控科技产品入选中纺联《纺织服装行业数字化转型解决方案重点推广名录》
Written by unity Jason
LeetCode 4. 寻找两个正序数组的中位数(hard)
618 deep resumption: Haier Zhijia's winning methodology
Day 18 of leetcode dynamic planning introduction
学生选课系统(山东农业大学课程设计)
云原生的 CICD 框架:Tekton
MySQL min() finds the minimum value under certain conditions, and there are multiple results
自注意力机制和全连接的图卷积网络(GCN)有什么区别联系?
绝对真理和相对真理思考