项目作者: abdallahabusedo

项目描述 :
introduction to Verilog in Integrated Circuit Design And VLSI technology
高级语言: Verilog
项目地址: git://github.com/abdallahabusedo/CMP305-introduction-Verilog.git


CMP305-introduction-Verilog

introduction to Verilog in Integrated Circuit Design And VLSI technology



# THIS IS A NOTES FOR MYSELF TAKEN FROM THIS VIDEO LINK_OF_THE_VIDEO


# Verilog language
  • Standard Hardware description Language (HDL).
  • used to describe a digital system.

Behavior Modeling

  • A Component is described by its I/O response.
  • only the functionality of the circuit no structure.

Structural Modeling

  • A component is described by interconnecting Lower-Level Component/primitives
  • Both Functionality and structure of the circuit

Register Transfer Level (RTL)

  • A type of behavioral modeling for the purpose of synthesis

    Synthesis : Translating HDL to a circuit and then optimizing the represented circuit

Module declaration


1) begins with keyword module
2) provides module name
3) include port list

  1. module multi (
  2. // port_list types
  3. 1- input => input port
  4. 2- output => output port
  5. 3- inout => bidirectional port
  6. );
  7. // port declaration
  8. "<port_type> <port_name>;"
  9. // data type declatation
  10. => Net Data type
  11. -> represents physical interconnect between structures
  12. -- wire
  13. -- tri
  14. -- supply0
  15. supply1
  16. example
  17. wire [7:0] out;
  18. tri enable;
  19. => Variable Data type
  20. -> represent element to store data temporarily
  21. -- reg
  22. -- integer
  23. -- real
  24. -- time
  25. -- realtimer
  26. // instantiation format
  27. <component_name> #<delay> <instance_name> (port_list);
  28. #<delay> -> delay through component
  29. // circuit functionality
  30. // timing specifications
  31. endmodule //multi


# Connecting Module Instantiation Ports

Two Methods to define ports connections

1) By Ordered list

  • port connections defined by the order of the port list in the lower-level module declaration
    1. module half_adder ( co , sum , a , b );
    1. half_adder u1 ( c1 , s1 , a , b );
  • the order dose matter
    co -> c1 | sum -> S1 | a -> a | b -> b
  • Port connections defined by name
  • order does not matter


# Parameters
  • Value assigned to a symbolic name
  • must resolve to a constant at compile time
  • can be overwritten at compile time
  • “localparam” -> same as parameters but cannot be overwritten

ex

  1. parameters size = 8; // can be overwritten
  2. localparam outsize = 16; //can't be overwritten




# Numbers

1) Sized -> 3’b010 = 3bits wide binary number

  1. - 3 indicated the size of number

2) Unsized -> 123 = 32bit decimal number

Base Formats

  • Decimal (d || D ) => 16’d255
  • Hexadecimal (h || H) => 8’h9a
  • Binary (b || B) => b1010
  • Octal (o || O) => o21
  • Signed (s || S) 16’shFA

Negative numbers

  • legal ==> -8’d3
  • illegal ==> 4’d-2 ERROR

Special Number Characters

  • underlined ( _ ) used for readability
    • 32’h21_65_bc_fe
  • X or x unknown value
    • 12’h12x
  • z or Z high impedance value
    • 1’bz

Arithmetic operators

  1. ain =5 ; bin =10 ; cin =2'b01; din =2'b0z
  2. 1) "+" => Add | bin+cin => 11
  3. 2) "-" => Subtract | bin-cin => 9
  4. 3) "*" => Multiply | ain*bin => 50
  5. 4) "/" => Divide | bin/ain => 2
  6. 5) "%" => Modulus | bin%ain => 0
  7. 6) "**"=> Exponent | ain**2 => 25
# Bitwise operators
  1. 1) "~" => | invert each bit
  2. 2) "&" => | And
  3. 3) "|" => | OR
  4. 4) "^" => | XOR
  5. 5) "^~" => | XNOR
# Reduction operators
  1. 1) "&" => | AND
  2. 2) "~&" => | NAND
  3. 3) "|" => | OR
  4. 4) "~|" => | NOR
  5. 5) "^" => | XOR
  6. 6) "~^" or "^~" => | XNOR
# Relational operators
  1. 1) ">" => | Grater than
  2. 2) "<" => | Less than
  3. 3) ">=" => | Greater than or equal
  4. 4) "<=" => | Less than or equal
# Equality operators
  1. 1) "==" => | Equality
  2. 2) "!=" => | inEquality
  3. 3) "===" => | Case Equality
  4. 4) "!==" => | Case inEquality
# Logical operators
  1. 1) "!" => | Not
  2. 2) "&&" => | AND
  3. 3) "||" => | OR
# Shift operators
  1. 1) "<<" => | logical shift left
  2. 2) ">>" => | logical shift right
  3. 3) "<<<" => | Arithmetic shift left
  4. 3) ">>>" => | Arithmetic shift right
# Miscellaneous operators
  1. 1) "?:" => | Conditional test
  2. 2) "{}" => | Concatenate
  3. 3) "{{}}" => | Replicate

# Making Assignments
## 1) Continuous Assignment Statement ``` wire[15:0] adder_out =mult_out + out; ``` equivalent to ``` wire[15:0] adder_out; assign adder_out = mult_out + out; ``` when the RHS changes , expression is evaluated and LHS net is updated immediately. ## 2) Procedural Assignment Blocks * Initial => used to initialized behavioral statements for simulation * start at time 0 * execute only once during simulation then does not execute again * statements inside execute sequentially * Keywords begin and end must be used if block contains more than one statement * Examples * Initialization * Monitoring * any functionality that needs to be turned on just once * Always => used to describe te circuit functionality using behavioral statements * Blocks execute concurrently * start at time 0 * and continuously in a looping fashion * Behavioral statements inside an initial block execute sequentially * Examples * Modeling a digital circuit * any Process or functionality needs to be executed continuously - each one represent a separate process - each consists of behavioral statements Example on Always and initial statements ``` module clk_gen #(parameters period =50) ( output reg clk ); initial clk = 1'b0; always #(period/2)clk =~clk; initial #100 $finish; endmodule ``` ## Two Types of Procedural Assignments 1) Blocking Assignments = - executed in the order they are specified in the seq. way Example a=1 b=2 ``` initial begin a = #5 b ; c = #10 a; end ```
  1. |
  2. | a=b=2 c=a=2
  3. |_____|_____|_____|_____|_
  4. 0 5 10 15 20

2) Nonblocking Assignments <=

  1. - allow scheduling of assignments without blocking execution of the statements that follow in a seq block

Example a=1 b=2

  1. initial
  2. begin
  3. a <= #5 b ;
  4. c <= #10 a;
  5. end
  1. |
  2. | a=b=2 c=a=1
  3. |_____|_____|_____|_____|_
  4. 0 5 10 15 20
  • = for combinatorial logic
  • <= for sequential logic

Tow types of RTL processes

1) Combinatorial Processes

  • sensitive to all inputs used in the Combinatorial logic
  1. always @(a,b,sel)
  2. always @*

2) Clocked Processes

  • sensitive to clock or/and control signals
  1. always @(Posedge clk , negedge clr_n)



# Behavioral Statements

1) if-else

  1. always @* begin
  2. if(s)
  3. q=a;
  4. else if(sb)
  5. q=b;
  6. else
  7. q=c;
  8. end

2) case

  1. always @* begin
  2. case(s)
  3. 2'b00 : q = a;
  4. 2'b01 : q = b;
  5. 2'b10 : q = c;
  6. default : q =d;
  7. endcase
  8. end

3) Loop

  1. - forever loop
  2. ```
  3. initial begin
  4. clk=0
  5. forever #25 clk =~clk;
  6. end
  7. ```
  8. - repeat loopp
  9. ```
  10. if(rotate ==1)
  11. repeat (8) begin
  12. tmp= data[15];
  13. data={data<< 1 ,tmp};
  14. end
  15. ```
  16. - while loop
  17. ```
  18. initial begin
  19. count =0;
  20. while (count < 101) begin
  21. count = count+1;
  22. end
  23. end
  24. ```
  25. - for loop
  26. ```
  27. integer i;
  28. always @(inp, cnt) begin
  29. result[7:4]=0;
  30. result[3:0]=inp;
  31. if(cnt==1) begin
  32. for(i=4; i<= 7 ; i=i+1) begin
  33. result[i]=result[i-4];
  34. end
  35. result[3:0]=0;
  36. end
  37. end
  38. ```



# Function and Tasks

1) Function

  1. - return one value
  2. - produces combinatorial logic
  3. - used in expressions
  4. ```assign mult_out = mult(ina,inb); ```

2) Tasks

  1. - can return multi values
  2. - can be combinatorial or registered
  3. - task are invoked as statement
  4. ```stm_out(nxt,first,sel,filter); ```

there are more some differences between Function and Task
go and watch the video for more info and examples

thanks for reading

you are legend 😎