Verilog HDL specification (1)

This blog post reference: "Large-Scale Logic Design Guide" is very helpful for writing standard code and cultivating a good code style.


wire and register

  • A reg variable can only be assigned in one always statement;

This explanation is very important. If this is not satisfied, maybe there is no problem in the simulation, but it will definitely appear during the synthesis and cannot be synthesized. I have made this mistake many times.

I once wrote a blog that specifically said:There is no problem to perform functional simulation under Modelsim, but a comprehensive error is reported in ISE, how to solve it?

  • The definition of the significant bits of the vector is generally from large to small.

Although the standard does not enforce this, it is more standardized and easier to read.

Expressions

  • Use parentheses to indicate the priority of execution;

This is easier to understand. Although the Verilog HDL language has its own priority, the use of parentheses to indicate priority is clearer and more meaningful to the reader.

For example: if ((a> b) && (c> d)) ......

It is better than the following expression:

if (a> b && c> d), although the two have the same effect.

 

  • Instead of repeating expressions multiple times with a function, a frequently used set of descriptions can be written to a task.

If statement

  • When comparing vectors, the compared vectors must be equal;

When comparing vectors, Verilog will zero-extend vectors with a small number of bits to match their lengths, and its automatic expansion is implicit. It is recommended to use display expansion. This rule also applies to the comparison of vectors and constants.

E.g:

reg [7:0] a;

reg [3:0] b;

...

if( a == {4'b0, b} ) begin

...

end

if( a == 8'b0 ) begin

...

end

 

  • Each if has an else corresponding to it;

When doing hardware design, it is often required to perform an action when the condition is true, and perform another action when the condition is false. Even if the condition is false, it is impossible to occur, there must be an else statement, which can be an empty Statement.

If there is no else statement, the synthesized logic may be different from the logic at the RTL level. (What does this sentence mean? If there is no else statement, the synthesis tool may synthesize something that you do not want to appear, such as synthesizing a latch. You can not use a latch, but it is because there is no else Statement, and the latch is synthesized, which not only affects the overall performance of the circuit, but also causes waste of resources.)

E.g:

always @(Cond)
begin
    if(Cond)
        DataOut <= DataIn; // The else statement is missing
end

The above statement DataOut will be integrated into a latch.

  • Should pay attention to the priority of if ... else if ... else

The above statement has priority, if has the highest priority, else if follows, else last.

  • If the variable is incompletely assigned in an if ... else or case statement, the variable should be given a default value, namely:
V1 = 2'b00; //default
V2 = 2'b00;
v3 = 2'b00;

if(a == b) begin
    V1 = 2'b01;
    V2 = 2'b10; //V3 is not assigned

end

else if(a == c) begin
    V2 = 2'b10;
    V3 = 2'b11; //V1 is not assigned
end

else ;

The above meaning is that if the variable is not all assigned in the statement, then the variable should be given a default value at the beginning, otherwise its value is unpredictable.

case statement

  • The case is usually integrated into a first-level multiplexer (the right part of the figure), and if ... else ... is integrated into multiple multiplexers with priority coding in series, as shown in the left part of the figure. The case statement is usually faster than the if statement, and the structure of the priority encoder is only used when the signal arrives in sequence. Conditional assignment statements can also be synthesized into multiplexers, and case statement simulation is faster than conditional assignment statements.

 

  • All cases should have a default, allowing empty statements, namely:

case

...

default: ;

endcase

 


This blog post is here for the time being. Of course, there are still many places to pay attention to, and we will continue to update it in the future. The update includes modifications and additions to this blog, which are explained based on actual inspections.

For example: I haven't said much about the following sentence because I don't know it yet. In the past circuit design, functions and tasks were rarely used, so you have to learn and then practice.

Instead of repeating expressions multiple times with a function, a frequently used set of descriptions can be written to a task.

[Verilog HDL] A brief introduction to functions and tasks

Intelligent Recommendation

Verilog HDL

content 1. 1.1. Verilog HDL 1.2. Verilog HDL 2. 2.1. 2.1.1. 2.1.2. assign always initial 2.2. 1. (Hardware Description Language, HDL) , , (Electrionic Design Automation, EDA) , , 。 , (Application Spec...

Verilog HDL FPGA from entry to abandonment (1)

This is an introductory article. The author has also been confused and very confused about how hardware programming is, but the effort is not disappointing. I hope my article will be recognized by rea...

Introduction to Verilog HDL and basic syntax (1)

FPGA learning Phase 1: Introduction to Verilog HDL and basic syntax (1) FPGA hardware development route learning plan: Since I want to learn the related content of FPGA and lay some foundation for dig...

Verilog HDL simple design example (1)

Verilog HDL simple design example (1) statement 8-bit adder with carry end Use level-sensitive always block to design instruction decoding circuit Use task and always blocks to design the combinatoria...

[Verilog HDL] 4 Select 1 Data Selector

Source code Signal connection diagram...

More Recommendation

Verilog HDL learning notes (1) - Chapter 3

First, the lexical agreement 1.Verilog is the case in case, to distinguish, where the keywords should be lowercase 2. Blank characters and spaces (/ b) and tabs (/ T) consist of, in addition to blanks...

"Design and Verification: Verilog HDL" reading notes (1)

Introduction to HDL design method Verilog is essentially a design method Verilog first impression Verilog design verification process glance Verilog is essentially a design method In the past people w...

3. 1【Verilog HDL】After learning about Verilog programming language

Recommended study books: "Verilog HDL Digital Design and Comprehensive" (Second Edition) "Verilog HDL Programming Art" Currently, we will learn based on these two books and wildfir...

How to understand FPGA and Verilog HDL in a common way? - Quick Start Verilog HDL and FPGA Series 1

How to understand FPGA and Verilog HDL in a common way? - Quick Start Verilog HDL and FPGA Series 1 1. From novice to expert There are five stages in any field, from novice to expert: the exploration ...

[Verilog HDL Learning Path] Chapter 1 Verilog HDL Digital Design Overview

1 Verilog HDL Digital Design Overview 1.1 Several important concepts EDA(Electronic Design Automation) Electronic technology automation EDA tools Similar to IDE (Integrated Development Environment) in...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top