当前位置:网站首页>Verilog grammar basics HDL bits training 04
Verilog grammar basics HDL bits training 04
2022-07-23 09:39:00 【Nanyou school slag】
List of articles
- One 、Procedures:Always blocks
- Two 、Procedures:Always blocks(clocked)
- 3、 ... and 、Procedures:If statement
- Four 、Procedures:If statement latches
- 5、 ... and 、Procedures:Case statement
- 6、 ... and 、Procedures:Priority encoder
- 7、 ... and 、Procedures:Priority encoder with casez
- 8、 ... and 、Procedures:Avoiding latches
One 、Procedures:Always blocks

Use continuous assignment statements and always Block to implement and gate
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module(
input a,
input b,
output wire out_assign,
output reg out_alwaysblock
);
assign out_assign = a & b;
always @(*)
out_alwaysblock = a&b;
endmodule
- Simulation oscillogram

Two 、Procedures:Always blocks(clocked)

Clock controlled always block
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module(
input clk,
input a,
input b,
output wire out_assign,
output reg out_always_comb,
output reg out_always_ff );
assign out_assign = a ^ b;
always @(*)
out_always_comb = a ^ b;
always @(posedge clk)
out_always_ff <= a ^ b;
endmodule
- Simulation oscillogram

3、 ... and 、Procedures:If statement

Build a two-way multiplexer
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module(
input a,
input b,
input sel_b1,
input sel_b2,
output wire out_assign,
output reg out_always );
assign out_assign = ({
sel_b1,sel_b2} == 2'b11)? b : a;
always @(*)
if({
sel_b1,sel_b2} == 2'b11)
out_always = b;
else
out_always = a;
endmodule
- Simulation oscillogram

Four 、Procedures:If statement latches

This is an example of a latch error , In general , Latches make us unwanted , So I'm writing if When the sentence is , To add else Statement guarantees that the output will not be latched
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module (
input cpu_overheated,
output reg shut_off_computer,
input arrived,
input gas_tank_empty,
output reg keep_driving ); //
always @(*) begin
if (cpu_overheated)
shut_off_computer = 1;
else
shut_off_computer = 0;
end
always @(*) begin
if (~arrived)
keep_driving = ~gas_tank_empty;
else if(arrived)
keep_driving = 0;
else
keep_driving = gas_tank_empty;
end
endmodule
- Simulation oscillogram

5、 ... and 、Procedures:Case statement

case Select statement
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module (
input [2:0] sel,
input [3:0] data0,
input [3:0] data1,
input [3:0] data2,
input [3:0] data3,
input [3:0] data4,
input [3:0] data5,
output reg [3:0] out );//
[email protected](*) begin // This is a combinational circuit
case(sel)
3'b000 : out = data0;
3'b001 : out = data1;
3'b010 : out = data2;
3'b011 : out = data3;
3'b100 : out = data4;
3'b101 : out = data5;
default : out = 0;
endcase
end
endmodule
- Simulation oscillogram

6、 ... and 、Procedures:Priority encoder
Build a priority encoder
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module (
input [3:0] in,
output reg [1:0] pos );
always @(*)begin
case(in)
in[0] : pos = 2'b0;
in[1] : pos = 2'b1;
in[2] : pos = 2'b2;
in[3] : pos = 2'b3;
default : pos = 2'b0;
endcase
end
endmodule
- Simulation oscillogram

7、 ... and 、Procedures:Priority encoder with casez
Use casez sentence
- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module (
input [7:0] in,
output reg [2:0] pos );
always @(*)begin
casez(in[7:0])
8'bzzzz_zzz1 : pos = 3'b000;
8'bzzzz_zz1z : pos = 3'b001;
8'bzzzz_z1zz : pos = 3'b010;
8'bzzzz_1zzz : pos = 3'b011;
8'bzzz1_zzzz : pos = 3'b100;
8'bzz1z_zzzz : pos = 3'b101;
8'bz1zz_zzzz : pos = 3'b110;
8'b1zzz_zzzz : pos = 3'b111;
default : pos = 3'b000;
endcase
end
endmodule
- Simulation oscillogram

8、 ... and 、Procedures:Avoiding latches

- RTL Code
// synthesis verilog_input_version verilog_2001
module top_module (
input [15:0] scancode,
output reg left,
output reg down,
output reg right,
output reg up );
always @(*)begin
up = 1'b0; down = 1'b0; left = 1'b0; right = 1'b0;
case(scancode)
16'he06b : left = 1;
16'he072 : down = 1;
16'he074 : right = 1;
16'he075 : up = 1;
endcase
end
endmodule
- Simulation oscillogram

边栏推荐
- IBM:到2030年实现容错量子优势
- Installation, configuration and use of sentry
- 判断两个类型是否相同
- PNA肽核酸修饰多肽Z-Gly-Pro-pNA|D-Phe-Pip-Arg-pNA|Tos-Gly-Pro-Arg-pNA
- FPGA出错的积累
- 【洛谷】P1972 HH的项链
- QML (17) -- read and write txt files
- PNA modified polypeptide BZ Val Gly Arg PNA | BOC Val Leu Gly Arg PNA
- Linear feedback shift register (lsfr)
- virtualbox NAT网络模式配置
猜你喜欢

Developers must see | devweekly issue 1: what is time complexity?

服务器内存性能调优

使用HiFlow场景连接器查看每天处于地区的疫情

MATLAB之优劣解距离法Topsis模型

新规出|一建证书公路与水利专业含金量上升

PNA modified polypeptide suc ala Pro ala PNA | suc ala Glu Pro Phe PNA

肽核酸PNA-多肽suc-Ala-Ala-Pro-Aaa-pNa|Suc-Ala3-pNA|Pyr-Phe-Leu-pNA

【C语言】预处理详解

程序环境和预处理

PNA modified polypeptide BZ Val Gly Arg PNA | BOC Val Leu Gly Arg PNA
随机推荐
力扣(LeetCode)203. 移除链表元素(2022.07.22)
【C语言】预处理详解
每周推荐短视频:为什么会写这样一本书?
我想在挖财学习理财开户安全吗?
MongoDB的CRUD操作(2)
Peptide nucleic acid coupled polypeptide ile Glu Gly Arg PNA (s-2222) | BOC Leu Gly Arg PNA
复盘:什么是B+树?你知道B+树怎么构建有序表的吗?B+树有什么特点
向后量子密码学迁移!美国NIST公布12家合作伙伴
污水处理厂设备巡检的解决方案
判断两个类型是否相同
结合实战,浅析GB/T 28181(二)——设备目录同步
MATLAB之优劣解距离法Topsis模型
Canal 03 (8 chapters in total)
一文带你了解如何用SQL处理周报数据
第三方依赖库 AG Grid调研分析
LEADTOOLS 20-22 Crack-DotNetCore!!!
【HLS】流水线仿真之排队函数的调用
canal 02
肽核酸(PNA)偶联穿膜肽(CCPs)(KFF)3K形成CCPs-PNA|肽核酸的使用方法
Teach you how to set up Alibaba cloud DDNS in Qunhui