Professional Documents
Culture Documents
Verilog HDL
Page 1
Page 2
Lm c Khi
Page 3
Page 4
Page 5
Page 6
Page 7
Lm c Khi
Page 8
Page 9
Lm c Khi
Page 10
Lm c Khi
Page 11
1.1.4.3 Ti u logic
Lm c Khi
Page 12
Lm c Khi
Page 13
Page 14
Quan st trn hnh 1.1, bc phn tch thi gian l mt phn trong
qu trnh bin dch, hoc trong mt s cng c th bc phn tch thi gian
ny c thc hin sau qu trnh bin dch. Bc ny s to ra kh nng
xu nht v tr hon , tc xung clock, tr hon t cng ny n
cng khc, cng nh thi gian cho vic thit lp v gi tn hiu. Kt qu
ca bc phn tch thi gian c th hin di dng bng hoc biu .
Ngi thit k s dng nhng thng tin ny xc nh tc xung clock,
hay ni cch khc l xc nh tc hot ng ca mch thit k.
1.1.7 To linh kin phn cng
Lm c Khi
Page 15
Page 16
Lm c Khi
Page 17
Lm c Khi
Page 18
Lm c Khi
Page 19
Page 20
Lm c Khi
Page 21
Lm c Khi
Page 22
unsigned_number[.unsigned_number]
exp
[sign]
unsigned_number
Exp = e | E
Sign = + | Size = non_zero_unsigned_number
Lm c Khi
Page 23
non_zero_decimal_digit
_|
decimal_digit}
Non_zero_decimal_digit = 1|2|3|4|5|6|7|8|9
Unsigned_number = decimal_degit{_| decimal_digit}
Decimal_digit = 0|1|2|3|4|5|6|7|8|9
Binary_value = binary_digit {_| binary_digit }
Binary_digit = x|X|z|Z|0|1
Octal_value = octal_digit {_| octal_digit }
Octal_digit = x|X|z|Z|0|1|2|3|4|5|6|7
Hex_value = hex_digit {_|hex_digit }
Hex_digit = x|X|z|Z|0|1|2|3|4|5|6|7|8|9|a|A|b|B|c|C|d|D|e|E|f|F
Lm c Khi
Page 24
Page 25
Page 26
Lm c Khi
Page 27
// s thp phn
h 837FF
// s thp lc phn
o7460
// s bt phn
4af
h)
V d 2: Hng s c rng bit
4b1011
// s nh phn 4 bit
5 D 3
3b01x
nht c gi tr khng xc nh
12hx
16hz
xc nh
cao.
V d 3: S dng du vi hng s
Lm c Khi
Page 28
// c php khng ng
-8 d 6
// s b 2 ca 6, tng ng vi (8d 6)
4 shf
tng ng vi 4h1
-4 sd15
16sd?
//tng ng 16sbz
= 0001
V d 4 T ng thm vo bn tri
reg [11:0] a, b, c, d;
initial begin
a = h x;
// to ra xxx
b= h 3x;
// to ra 03x
c = h z3;
// to ra zz3
d = h 0z3;
// to ra 0z3
end
reg [84:0]
Lm c Khi
e, f, g;
e = h5;
// to ra {82{1b0}, 3b101}
f = hx
// to ra {85{1hx}}
Page 29
// to ra {85{1hz}}
Lm c Khi
Page 30
Page 31
Lm c Khi
Page 32
Page 33
K t to bi chui escape
\n
K t xung dng
\t
K t tab
\\
K t \
K t
\ddd
Lm c Khi
Page 34
Page 35
2.7.2 T kha
Lm c Khi
Page 36
dollar
($)
trong
system_function_identifier
hay
Lm c Khi
Page 37
Lm c Khi
Page 38
Nhng loi d liu khc nhau trong Verilog c khai bo bng pht
biu khai bo d liu. Nhng pht biu ny xut hin trong nhng nh
ngha module trc khi s dng v mt s trong chng c th c khai
Lm c Khi
Page 39
phn tch sau qu trnh bin dch v cho php modules c gn tham s.
input , output, inout
Lm c Khi
Page 40
Time
Real
Event
bt tch cc.
Nhng loi d liu ny tt c c th c khai bo mc module.
Nhng m t khc trong Verilog vi nhng kh nng to lp mc ch bao
gm nhng tc v, nhng hm v nhng khi begin-end c t tn. Nets
c iu khin khng theo hnh vi (non-behaviorally) nn do n khng
th c khai bo cho nhng mc ch khc. Tt c nhng loi d liu
khc c th c th hin trong nhng tc v v trong nhng khi beginend.
3.3.2 V d
Page 41
Lm c Khi
Page 42
Wor
Tri
Tri0
Tri1
tri/wire
triand/wand 0
Lm c Khi
Page 43
trior/wor
tri1
tri0
trireg
Lm c Khi
Page 44
Lm c Khi
Page 45
Assign out = b;
Assign out = c;
Endmodule
Module abc (a, b, c, select)
Output a, b, c;
Input [1:0] select;
Always @(select) begin
A = 1bz;
// thit lp tt c cc bin c gi tr Z
B = 1bz;
C = 1bz;
Case (select)
2b00: a = 1b1;
Lm c Khi
Page 46
Wired nets bao gm nhng loi d liu wor, wand, trior v triand.
Chng c dng m hnh gi tr logic ca net. Nhng wired net trn c
Lm c Khi
Page 47
Lm c Khi
Page 48
Lm c Khi
Page 49
Page 50
Simulation result:
Lm c Khi
time = 0
time = 1
Page 51
Lm c Khi
Page 52
Lm c Khi
Page 53
::=
#delay_value
#(
delay_value
[,delay_value
[,delay_value]])
delay2 ::= #delay_value | #( delay_value [,delay_value])
delay_value
::= unsigned_number
| parameter_identifier
|
(mintypmax_expression
[,mintypmax_expression]
[,mintypmax_expression])
3.4.10 C php khai bo net
Page 54
Lm c Khi
Page 55
V d 2.2:
reg r1, r2;
reg [63:0] data_a, data_b, data_c;
Lm c Khi
Page 56
reg_declaration
::= reg [range] list_of_register_ identifiers;
list_of_ register_ identifiers ::= register _ identifier , { register _
identifier }
3.6 Khai bo port
3.6.1 Gii thiu
Page 57
V d 2.11:
module fulladder(cOut, sum, aIn, bIn, cIn);
input aIn, bIn, cIn;
output cOut, sum;
Lm c Khi
Page 58
Endmodule
3.6.3 C php
list_of_ports
::= ( port {,port })
port
::= [port_expression]
| . port_identifier ( [port_expression] )
port_expression
::= port_reference
| { port_reference ,port_reference }
port_reference
::= port_identifier
| port_identifier[ constant_expression ]
| port_identifier [ msb_constant_expression :lsb_constant_expression
]
Lm c Khi
Page 59
V d 2.12:
wire [63:0] system_bus
v d 2.12 m t vic khai bo mt wire c rng 64 bits.
V d 2.13:
wire vectored [31:0] bus1;
wire scalared [31:0] bus2;
Lm c Khi
Page 60
Lm c Khi
Page 61
Lm c Khi
Page 62
Lm c Khi
Page 63
3.7.5 C php
3.7.5.1 Khai bo Vectored Net v Reg
memory_variable
::= memory_identifier [ constant_expression : constant_expression ]
3.7.5.3 Nhng trng hp c bit ca Vectored Net
expandrange
::= range
| scalared range
| vectored range
Lm c Khi
Page 64
Integer_declaration
::= integer list_of_register_identifiers;
Lm c Khi
Page 65
time_declaration
::= time list_of_register_identifiers;
3.8.4 S thc (real) v thi gian thc (realtime)
3.8.4.1 Gii thiu
Lm c Khi
Page 66
nhng s thc.
Bin d liu c gi tr mc nh l 0.
real_declaration
Lm c Khi
Page 67
Page 68
parameter_declaration ::=
parameter [ signed ] [ range ] list_of_param_assignments
| parameter parameter_type list_of_param_assignments
parameter_type ::=
integer | real | realtime | time
list_of_param_assignments ::=
param_assignment { , param_assignment }
param_assignment ::=
parameter_identifier = constant_mintypmax_expression
range ::=
[ msb_constant_expression : lsb_constant_expression ]
3.9.2.1.3 V d
Lm c Khi
Page 69
Lm c Khi
Page 70
Page 71
Page 72
Lm c Khi
Page 73
Page 74
Page 75
Page 76
Lm c Khi
Page 77
Page 78
Page 79
Page 80
Page 81
local_parameter_declaration ::=
localparam [ signed ] [ range ] list_of_param_assignments
| localparam parameter_type list_of_param_assignments
parameter_type ::=
integer | real | realtime | time
list_of_param_assignments ::=
param_assignment { , param_assignment }
param_assignment ::=
parameter_identifier = constant_mintypmax_expression
range ::=
[ msb_constant_expression : lsb_constant_expression ]
3.9.4 c t tham s (specify parameter)
3.9.4.1 Gii thiu
Page 82
Lm c Khi
Page 83
th
gn
bi
Page 84
END
Lm c Khi
Page 85
Lm c Khi
Page 86