Computer Architecture
& Verilog HDL
তোমার পুরো lecture টা এখানে — diagram, code, বাংলা explanation, আর exam practice সব একসাথে। Lecture দেখতে দেখতে এটা খোলা রাখো।
Lecture 1 (logic gates, transistor context) recommended.
Why do we need HDL? কেন HDL দরকার?
Before learning Verilog, we need to understand the PROBLEM it solves. Your lecture starts here.
আগের দিনে engineers দুইভাবে circuit design করত। তোমার lecture এর slide 2 এ এই দুইটার কথা আছে:
🔌 Gate Level Design (LogiSim)
প্রতিটা AND, OR, NOT gate হাতে আঁকতে হতো। ছোট circuit এর জন্য ঠিকই আছে — কিন্তু বড় circuit এ হাজার হাজার gate!
একটা calculator বানাতে হলে হাজারো gate। হাতে আঁকলে কত সময় লাগবে? ভুল হলে খুঁজে বের করা আরো কঠিন।
📐 Schematic Design (PSpice)
Computer software দিয়ে circuit আঁকা হতো। কিছুটা ভালো — কিন্তু তবুও একটা একটা করে component বসাতে হয়। Complex design এ scale করে না।
40 million transistor এর chip কি এভাবে আঁকা সম্ভব? একদমই না।
From Lecture 1 you know Moore's Law and transistor counts. তোমার lecture এ দুইটা processor compare করা হয়েছে। এটা দেখো — এটাই বোঝায় কেন HDL এত জরুরি:
Intel 4004 Processor (1971)
2,300 transistor এখনো হাতে design করা possible ছিল — কিন্তু অনেক কষ্টের।
Intel P4 Processor (2000)
40 million transistor! হাতে আঁকা কল্পনাতেও সম্ভব না।
মাত্র ৩০ বছরে transistor সংখ্যা ২,৩০০ থেকে ৪ কোটিতে চলে গেছে। এই জটিলতা সামলানোর জন্যই HDL এসেছে। Verilog দিয়ে তুমি code লিখবে, আর computer সেটাকে hardware circuit এ convert করবে — ঠিক যেমন C++ code কে computer executable এ convert করে!
System Design Pyramid
Hardware design হয় বিভিন্ন level এ। Pyramid দিয়ে সেই levels বোঝানো হয়।
⬆ More Abstract | More Physical ⬇
Physical chip এর actual material। Transistor বানানোর raw layer। তুমি এটা নিয়ে কাজ করবে না।
Transistor গুলো কীভাবে connect → বিদ্যুৎ প্রবাহ। Resistor, Capacitor ইত্যাদি।
AND, OR, NOT — Logic gates। এই level এ Verilog এর gate-level modeling কাজ করে।
Flip-flops, Registers — Data store করতে পারে। Verilog এর behavioral modeling এখানে।
Multiple components মিলে একটা chip (যেমন CPU)।
পুরো computer system — CPU, RAM, I/O সব মিলিয়ে।
Verilog দিয়ে তুমি যেকোনো level এ design করতে পারো। Lecture এর pyramid এ দেখো — Structure side এ Verilog আছে, মানে Verilog দিয়ে gate থেকে শুরু করে পুরো system পর্যন্ত describe করা যায়। তোমার course এ মূলত Gate এবং Register level নিয়ে কাজ করবে।
Gate Level
AND, OR, NOT gate এর instance create করো। Pyramid এর GATE level।
Dataflow (assign)
Boolean equations দিয়ে। তোমার lecture এর main focus। সবচেয়ে বেশি ব্যবহার হয়।
Behavioral (always)
if/else, case দিয়ে behavior describe করো। REGISTER level এবং উপরে।
Two HDL Languages: Verilog vs VHDL
তোমার lecture এ দুইটা HDL compare করা হয়েছে। আমরা Verilog শিখছি।
| Feature | ⚡ Verilog | 🏛️ VHDL |
|---|---|---|
| Full Name | Verilog HDL | VHSIC Hardware Description Language |
| Syntax feels like | C / C++ — তোমার জানা! | Ada / Pascal — কঠিন |
| Ease of learning | ✅ সহজ | ❌ কঠিন |
| Popular where | North America, Asia (তোমার region!) | Europe (academia তে বেশি) |
| Lower-level design | ✅ খুব ভালো (lecture অনুযায়ী) | তুলনামূলক দুর্বল |
| Simulation speed | ✅ দ্রুত | ধীর |
| Industry use | ✅ ASIC design এ dominant | Academic এবং European industry |
| তোমার course | ✅ এটা শিখবে | ❌ এই course এ না |
- Verilog এর syntax C এর মতো — তুমি C++ জানো, তাই তোমার জন্য অনেক সহজ হবে
- Lecture এ বলা হয়েছে Verilog "results in fast simulations, relatively simple, easy in first contacts" — মানে শিখতে সহজ
- VHDL "also difficult, complex character" — আমাদের দরকার নেই এখন
- Verilog North America এবং Asia তে most popular — তোমার job market এর জন্যও কাজে লাগবে
Verilog Basics — বেসিক স্ট্রাকচার
Before diving into code, let's understand the basic structure and building blocks of Verilog.
Verilog হল একটি Hardware Description Language (HDL) যা digital circuits describe করতে ব্যবহৃত হয়। এটি C programming এর মতো দেখতে, কিন্তু এটি hardware তৈরি করে, software নয়।
📝 Verilog Features
- Case-sensitive:
wire≠Wire - Semicolon-terminated: প্রতিটা statement
;দিয়ে শেষ - Module-based: সব কিছু modules এ লেখা হয়
- Comments:
// single lineবা/* multi line */
⚠️ Key Differences from C/C++
- সব কিছু parallel execute হয় (sequential নয়)
- Hardware তৈরি হয়, program run করে না
wireএবংreg— special data types- Time এবং delays important (
#10= 10 time units)
প্রতিটা Verilog program এর তিনটা main parts:
module শুরু করো, তারপর input/output declare করো, ভেতরে logic লেখো, শেষে endmodule দিয়ে বন্ধ করো। এত সহজ!
Keywords & Notation — শব্দ আর সংখ্যা
এই words গুলো Verilog এর জন্য reserved — তুমি variable name হিসেবে ব্যবহার করতে পারবে না।
Module & Structure
module
endmodule
input
output
inout
wire
reg
Behavioral
always
initial
begin
end
if
else
case
endcase
Data & Logic
assign
parameter
integer
real
time
Control
for
while
posedge
negedge
or
and
not
এই keywords lowercase এ লেখতে হয়। Module বা MODULE লিখলে error হবে। সবসময় module লেখো।
Verilog এ different number systems ব্যবহার করা যায়:
| Format | Syntax | Example | বাংলা |
|---|---|---|---|
| Binary | 'b |
4'b1010 |
4-bit binary: 1010 |
| Hexadecimal | 'h |
8'hAF |
8-bit hex: 10101111 |
| Decimal | 'd or none |
8'd15 or 15 |
8-bit decimal: 15 |
| Octal | 'o |
6'o77 |
6-bit octal: 111111 |
তুমি যদি 8'hA5 লেখো, এর মানে 8-bit hexadecimal number A5 = binary 10100101। Size (8) + Format ('h) + Value (A5)।
Verilog এ variable/signal names লেখার নিয়ম:
✅ Valid Identifiers
wire data_bus;wire clk_50MHz;reg counter_8bit;wire _reset_n;(underscore শুরুতে OK)
❌ Invalid Identifiers
wire 8bit;(number দিয়ে শুরু নয়)wire data-bus;(hyphen allowed নয়)wire module;(keyword ব্যবহার নয়)wire clk#;(special characters নয়)
Meaningful names ব্যবহার করো: clk (clock), rst (reset), data_in (input data)। Single letters (a, b) avoid করো except loops এ।
Code বোঝার জন্য comments খুব গুরুত্বপূর্ণ:
Data Types — wire আর reg
Verilog এর দুটো main data types: wire এবং reg। এই difference টা না বুঝলে কিছুই বুঝবে না!
🔌 wire
Physical wire মতো — সরাসরি connect
- Continuous assignment (
assign) - Combinational logic এর জন্য
- Value সবসময় update হয়
- Input কে wire declare করো
AND gate: output সরাসরি inputs এর উপর depend করে — wire ব্যবহার করো।
💾 reg
Storage element — value store করে
- Procedural assignment (
alwaysblock) - Sequential logic এর জন্য
- Value hold করতে পারে
alwaysblock এ reg ব্যবহার করো
Flip-flop: output previous state + clock এর উপর depend করে — reg ব্যবহার করো।
⚠️ Common Confusion
reg মানে এই নয় যে এটা সবসময় physical register! এটা শুধু বলে যে value always block এ assign হবে। Hardware synthesis করার সময় compiler decide করে এটা wire হবে না register হবে।
wire সবসময় assign দিয়ে value পায়। always block এ wire assign করতে পারবে না।
reg সবসময় always বা initial block এ assign হয়। assign দিয়ে reg এ value দিতে পারবে না।
কখন wire আর কখন reg ব্যবহার করবে?
| Situation | Use | বাংলা |
|---|---|---|
| Module input/output (most cases) | wire |
Input/output সাধারণত wire |
Continuous assignment (assign) |
wire |
Combinational logic |
Inside always block |
reg |
Sequential logic |
| Storage (flip-flop, counter, FSM) | reg |
Value store করতে হবে |
Operators — সব অপারেটর
Verilog এ অনেক ধরনের operators আছে। C/C++ এর মতো, কিন্তু কিছু unique ones also।
প্রতিটা bit এর উপর operation করে:
| Operator | Name | Example | Result | বাংলা |
|---|---|---|---|---|
~ |
NOT | ~4'b1010 |
4'b0101 |
প্রতিটা bit উল্টা |
& |
AND | 4'b1010 & 4'b1100 |
4'b1000 |
Bit-by-bit AND |
| |
OR | 4'b1010 | 4'b1100 |
4'b1110 |
Bit-by-bit OR |
^ |
XOR | 4'b1010 ^ 4'b1100 |
4'b0110 |
Bit-by-bit XOR |
~^ or ^~ |
XNOR | 4'b1010 ~^ 4'b1100 |
4'b1001 |
XOR এর opposite |
পুরো expression true/false check করে (C/C++ এর মতো):
| Operator | Name | Example | Result | বাংলা |
|---|---|---|---|---|
! |
Logical NOT | !5 |
0 |
Not zero → 0 |
&& |
Logical AND | (A > 0) && (B < 10) |
1 or 0 |
দুটোই true |
|| |
Logical OR | (A == 0) || (B == 0) |
1 or 0 |
যেকোনো একটা true |
⚠️ Bitwise vs Logical — পার্থক্য
A & B(bitwise) — প্রতিটা bit আলাদাভাবে ANDA && B(logical) — পুরো A এবং B দুটোই non-zero? → 1, else 0
Example: 4'b0001 && 4'b0010 → 1 (both non-zero)
But: 4'b0001 & 4'b0010 → 4'b0000 (bitwise result)
| Operator | Name | Example | বাংলা |
|---|---|---|---|
+ |
Addition | A + B |
যোগ |
- |
Subtraction | A - B |
বিয়োগ |
* |
Multiplication | A * B |
গুণ |
/ |
Division | A / B |
ভাগ |
% |
Modulus | A % B |
ভাগশেষ |
| Operator | Name | Example | Result |
|---|---|---|---|
== |
Equal | A == B |
1 if equal, else 0 |
!= |
Not Equal | A != B |
1 if not equal |
< |
Less Than | A < B |
1 if A less than B |
> |
Greater Than | A > B |
1 if A greater than B |
<= |
Less or Equal | A <= B |
1 if A ≤ B |
>= |
Greater or Equal | A >= B |
1 if A ≥ B |
Concatenation {}
Multiple signals একসাথে join করো:
Replication {n{...}}
Same pattern repeat করো:
Replication sign extension এর জন্য useful: {8{sign_bit}, data} — sign bit 8 বার repeat করে data এর আগে বসায়।
The Module Interface: Port List & Port Declaration
এটা Verilog এর সবচেয়ে গুরুত্বপূর্ণ concept। প্রতিটা hardware component কে "module" হিসেবে লেখা হয়।
C++ (তুমি জানো):
Verilog (শিখছো):
-
class=module— একটা component কে define করে -
C++ এর parameter = Verilog এর
input/outputports -
C++ এর
return= Verilog এরoutputwire
তোমার lecture এ ALU (Arithmetic Logic Unit) এর module interface দেখানো হয়েছে। এটাই lecture এর exact code:
Port List (প্রথম line এ): module এর নাম এবং সব
ports এর নাম একসাথে লেখা →
module ALU (Result, Equal, Cout, In1, In2, ...)
Port Declaration (ভেতরে): প্রতিটা port কি
input নাকি output, আর কত bit সেটা
declare করো → output [3:0] Result;
মনে রাখো: Port list এ নাম, declaration এ type। দুইটাই লাগবে, একটা বাদ দিলে error।
wire — Physical তার
Hardware এর actual wire এর মতো। কোনো value নিজে store করে না —
শুধু signal বহন করে। assign statement এর সাথে
ব্যবহার হয়।
তার = wire। তার কারেন্ট store করে না, বহন করে। input/output by default wire type।
reg — Register (Store করে)
Value store করে রাখতে পারে। always block এর ভেতরে
যে signals assign হয় তারা reg type হতে হবে।
reg = register = ছোট memory। Clock এর সাথে update হয়। Sequential circuit এ দরকার।
Logic Gates — Hardware এর LEGO Blocks
From Lecture 1 you know AND, OR, NOT, NAND, NOR. Here we describe them in Verilog.
Lecture এর full adder বোঝার আগে এই ৫টা gate ভালো করে বুঝতে হবে। প্রতিটা দেখো, truth table মুখস্থ করো।
কী করে?
দুইটা input নেয়। Output 1 হয় শুধুমাত্র যখন দুইটাই 1। একটাও 0 হলে output 0।
AND = "এবং" — "A এবং B দুটোই সত্য হলে Y সত্য।" যেমন: বৃষ্টি আসে এবং ছাতা নেই → ভিজবো।
Truth Table
| A | B | Y = A & B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 ← only here! |
কী করে?
Output 1 হয় যখন যেকোনো একটা বা উভয় input 1 হয়। শুধু দুইটাই 0 হলে output 0।
OR = "অথবা" — "A অথবা B যেকোনো একটা সত্য হলেই Y সত্য।"
Truth Table
| A | B | Y = A | B |
|---|---|---|
| 0 | 0 | 0 ← only here 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
একটাই input। Output সবসময় উল্টো।
NOT = "না" — A সত্য হলে Y মিথ্যা। A মিথ্যা হলে Y সত্য।
| A | Y = ~A |
|---|---|
| 0 | 1 |
| 1 | 0 |
Output 1 যখন inputs আলাদা। দুটো same হলে 0।
XOR = "ভিন্নতা detector" — inputs আলাদা → 1, একই → 0।
Full Adder এ XOR দিয়ে Sum বানানো হয়!
| A | B | Y = A ^ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 ← different |
| 1 | 0 | 1 ← different |
| 1 | 1 | 0 |
& = AND | | = OR
| ~ = NOT | ^ =
XOR | ~^ বা ^~ = XNOR
One-bit Full Adder — তোমার Lecture এর Main Example
এটা তোমার lecture এর সবচেয়ে important circuit। ভালো করে বোঝো — 4-bit adder বানাতে এটাই 4 বার ব্যবহার হবে।
Problem: দুইটা single-bit binary number যোগ করতে হবে, সাথে আগের ঘর থেকে আসা carry।
মনে করো তুমি হাতে 1 + 1 যোগ করছো binary তে:
A = 1
+ B = 1
─────────
Sum = 0 (কারণ 1+1=10 binary তে, unit digit = 0)
Cout = 1 (carry = 1, পরের ঘরে যাবে)
Cin হলো আগের ঘর থেকে আসা carry। Full Adder তিনটা জিনিস যোগ করে: A + B + Cin।
Ports বুঝি:
| A | B | Cin | Sum | Cout | Decimal: A+B+Cin |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0+0+0 = 0 |
| 0 | 0 | 1 | 1 | 0 | 0+0+1 = 1 |
| 0 | 1 | 0 | 1 | 0 | 0+1+0 = 1 |
| 0 | 1 | 1 | 0 | 1 | 0+1+1 = 2 = 10₂ |
| 1 | 0 | 0 | 1 | 0 | 1+0+0 = 1 |
| 1 | 0 | 1 | 0 | 1 | 1+0+1 = 2 = 10₂ |
| 1 | 1 | 0 | 0 | 1 | 1+1+0 = 2 = 10₂ |
| 1 | 1 | 1 | 1 | 1 | 1+1+1 = 3 = 11₂ |
Highlighted rows গুলো দেখো — Sum=1 কারণ result এর unit digit 1। যখন যোগফল ≥ 2 (binary 10), তখন Sum=0 এবং Cout=1 (carry হয়)।
এই exact code তোমার lecture এ আছে। প্রতিটা line বোঝো:
Sum equation দেখতে জটিল — কিন্তু logic সহজ। Truth table থেকে Sum=1 হওয়ার সব row গুলো OR করা হয়েছে:
-
(A & B & Cin)→ row: A=1, B=1, Cin=1 → Sum=1 ✓ -
(~A & ~B & Cin)→ row: A=0, B=0, Cin=1 → Sum=1 ✓ -
(~A & B & ~Cin)→ row: A=0, B=1, Cin=0 → Sum=1 ✓ -
(A & ~B & ~Cin)→ row: A=1, B=0, Cin=0 → Sum=1 ✓
এই pattern কে Sum of Products (SOP) বলে — "যে যে conditions এ output 1, সেগুলো AND করো, তারপর সব OR করো।"
A, B, Cin এর value দাও, দেখো Sum আর Cout কী হয়:
Four-bit Adder — Module Reuse & Structural Modeling
এখানে একটা নতুন concept — আগে বানানো module কে বারবার ব্যবহার করা। ঠিক C++ এ class instance তৈরির মতো।
কল্পনা করো একটা কারখানায় ৪টা worker আছে। প্রথম worker কাজ করে, তার output দ্বিতীয়কে দেয়, দ্বিতীয় তৃতীয়কে, এভাবে চলে। চার-bit adder এ carry ঠিক এভাবে FA1 থেকে FA2, FA2 থেকে FA3, FA3 থেকে FA4 তে যায়।
-
input [3:0] A— 4-bit input। A[3] হলো MSB (বাম দিক), A[0] হলো LSB (ডান দিক) -
wire C0, C1, C2— FA গুলোর মধ্যে carry বহন করার জন্য internal wires। এগুলো বাইরে থেকে দেখা যায় না। -
full_adder FA1(...)— এটা C++ এFullAdder fa1 = new FullAdder()এর মতো! Module এর একটা instance তৈরি করছি। -
Port connection order:
full_adder(A, B, Cin, Sum, Cout)এই order অনুযায়ী values দিতে হয় - FA1 এর Cout (C0) যায় FA2 এর Cin হিসেবে — এটাই "carry ripple"
full_adder FA1(A[0], B[0], Cin, Sum[0], C0) — এখানে
পঞ্চম argument C0 হলো Cout, Cin না। Module definition এর order
মিলিয়ে দেখো।
- N-bit bus =
[N-1 : 0] - 4-bit =
[3:0]→ A[3], A[2], A[1], A[0] -
8-bit =
[7:0]→ 256 possible values (0 to 255) - 16-bit =
[15:0]→ 65536 possible values
Dataflow Modeling — assign দিয়ে logic
Dataflow modeling হল সবচেয়ে সহজ way combinational logic describe করার। assign statement ব্যবহার করে continuous assignment করা হয়।
Dataflow modeling-এ আমরা describe করি data কীভাবে flow করে inputs থেকে outputs এ। Structural modeling এর চেয়ে higher-level।
Structural (আগে শিখেছো)
Gate-by-gate বলে দাও:
Dataflow (এখন শিখছো)
Expression লেখো সরাসরি:
Dataflow = "কী করতে হবে" বলো (what), Structural = "কীভাবে করতে হবে" বলো (how)। Dataflow সহজ এবং পড়তে সুবিধা।
assign মানে "continuously assign" — input change হলে output automatically update হয়। এটা একটা real wire connection মতো।
তুমি আগে structural modeling এ full adder দেখেছো (5টা gate instantiate করে)। Dataflow এ সেই একই logic মাত্র ২ লাইনে:
Dataflow অনেক cleaner! Boolean expression সরাসরি লেখো, intermediate wires declare করতে হয় না। Combinational logic এর জন্য dataflow preferred।
তুমি একই module এ একাধিক assign statements লিখতে পারো:
Behavioral Modeling — always ব্লক
Behavioral modeling সবচেয়ে powerful! এখানে আমরা কী হবে (behavior) describe করি, hardware details নয়। always এবং initial blocks ব্যবহার করে।
always block একটি procedural block যা simulation/synthesis এর সময় সবসময় active থাকে। Sensitivity list দেখে কখন execute হবে।
@(*)— সব inputs (combinational logic এর জন্য)@(posedge clk)— Clock এর rising edge (0→1)@(negedge clk)— Clock এর falling edge (1→0)@(A or B or C)— A, B, অথবা C change হলে
initial block simulation start এ শুধু একবার execute হয়। Hardware synthesis হয় না — শুধু simulation/testing এর জন্য।
initial শুধু testbenches এ — signals initialize করতে, test values set করতে। Real hardware এ initial synthesize হয় না।
| Aspect | Dataflow | Behavioral |
|---|---|---|
| Statement | assign |
always |
| Data Type | wire |
reg |
| Best For | Combinational logic | Sequential & complex logic |
| Abstraction | Medium level | High level (like C code) |
| বাংলা | সহজ combinational logic | Complex behavior, state machines |
Blocking vs Non-blocking — সবচেয়ে গুরুত্বপূর্ণ!
এটা Verilog এর সবচেয়ে confusing এবং important topic! = (blocking) এবং <= (non-blocking) এর difference না বুঝলে sequential logic এ ভুল হবে।
⚠️ THIS IS CRITICAL — Must Understand!
Blocking (=) আর non-blocking (<=) assignments এর মধ্যে পার্থক্য hardware behavior পুরোপুরি change করে দেয়। Wrong assignment ব্যবহার করলে circuit ভুল হবে!
=)"এক্ষুণি করো, পরের line-এ যাওয়ার আগে" — Sequential execution (C code এর মতো)
Blocking = step-by-step execution। প্রথম line execute হওয়ার পরে পরের line। a = b হওয়ার পরে c = a — তাই c নতুন a পায় (যা b)।
<=)"একসাথে করো, parallel এ" — Concurrent execution (real hardware এর মতো)
Non-blocking = parallel execution। সব statements একসাথে schedule হয়, তারপর clock edge এ একসাথে update হয়। c <= a তে a-র পুরনো value যায় (নতুন নয়)।
Blocking =
Result: a = 1, b = 1 (sequential)
Non-blocking <=
Result: a = 1, b = (old value of a)
🎯 Golden Rules — মুখস্থ করো!
Rule 1: Combinational Logic
always @(*) → Use = (blocking)
Combinational logic এ blocking assignment ব্যবহার করো। সব operations sequential order এ হবে।
Rule 2: Sequential Logic (Registers/Flip-flops)
always @(posedge clk) → Use <= (non-blocking)
Sequential logic এ non-blocking assignment ব্যবহার করো। সব registers একসাথে parallel এ update হবে (real hardware এর মতো)।
Shift register এ blocking vs non-blocking এর impact দেখো:
❌ WRONG (Blocking)
✅ CORRECT (Non-blocking)
Blocking (=) এ প্রতিটা assignment immediately হয়। তাই q1 = d হওয়ার পরে q2 = q1 নতুন q1 পায়।
Non-blocking (<=) এ সব assignments একসাথে schedule হয়, তারপর clock edge এ একসাথে update হয়। তাই q2 <= q1 তে q1-এর পুরনো value যায়। Real hardware এভাবেই কাজ করে!
Conditional Constructs — শর্ত যুক্ত logic
Hardware-এও condition check করতে হয় (C/C++ এর মতো)। Verilog এ if-else এবং case statements আছে।
Condition true হলে একটা block execute হয়, else আরেকটা:
if সবসময় always block এর ভেতরে। Module body-তে directly if লেখতে পারবে না।
case cleaner যখন অনেক গুলো conditions check করতে হয়:
case— যখন একটা variable-এর multiple fixed values check করবে (ALU opcodes, state machines)if-else— যখন complex conditions (A > B && C == 0) check করবে
Sequential Logic — ফ্লিপ-ফ্লপ আর রেজিস্টার
Sequential logic-এ memory/state থাকে — output শুধু current input নয়, previous state-এরও উপর depend করে। Clock signal এর সাথে synchronize হয়।
D flip-flop সবচেয়ে basic storage element — clock এর rising edge এ input (D) কে output (Q) তে copy করে এবং hold করে রাখে।
- Clock এর rising edge (0 → 1 transition) detect করো
- সেই moment এ D এর value Q তে copy করো
- Next rising edge পর্যন্ত Q এর value hold করো
Real circuits এ reset signal থাকে — chip power on হওয়ার সময় known state এ আসার জন্য:
একাধিক flip-flops একসাথে = register:
এই register load signal high থাকলে data_in store করে। load low থাকলে আগের value hold করে (else condition নেই মানে previous value রাখো)।
প্রতিটা clock rising edge এ (যদি enable = 1): count নিজের value নিয়ে 1 যোগ করে এবং নতুন value store করে। এভাবে 0 → 1 → 2 → ... → 15 → 0 (wrap around) চলতে থাকে।
State Machines — FSM ডিজাইন
Finite State Machine (FSM) হল sequential circuit যেখানে discrete states আছে। State transitions clock এবং inputs এর উপর নির্ভর করে। খুব powerful concept!
FSM একটি abstract model যা behavior describe করে states এবং transitions দিয়ে:
- States: Discrete conditions (e.g., IDLE, RUNNING, DONE)
- Transitions: State changes based on inputs/events
- Outputs: Depend on current state (and/or inputs)
Traffic Light: States = {RED, YELLOW, GREEN}। Timer শেষ হলে state change (RED → GREEN → YELLOW → RED)। প্রতিটা state এ different output (lights)।
Moore Machine
Output শুধু current state এর উপর depend করে
✅ Outputs stable (glitch-free)
❌ May need more states
Mealy Machine
Output state + inputs দুটোর উপর depend করে
✅ Fewer states needed
❌ Outputs may glitch
সব FSM-এ তিনটা always blocks:
- State Register:
@(posedge clk)— non-blocking (<=) - Next State Logic:
@(*)— blocking (=) - Output Logic:
@(*)— blocking (=)
এই FSM sequence 1011 detect করে (serial input থেকে):
S0 = শুরু, S1 = "1" পেয়েছি, S2 = "10" পেয়েছি, S3 = "101" পেয়েছি। যদি S3 তে থাকা অবস্থায় X=1 আসে, তাহলে পুরো sequence "1011" complete — Z = 1 output!
Hierarchical Design — মডিউল দিয়ে মডিউল
বড় circuits ছোট modules দিয়ে তৈরি করতে হয়। একটা module আরেকটা module instantiate করতে পারে — এটাই hierarchical design।
✅ Benefits
- Reusability: একবার লিখে বারবার ব্যবহার
- Maintainability: ছোট modules সহজে fix করা যায়
- Readability: Code organized এবং clean
- Testing: প্রতিটা module আলাদাভাবে test করো
📊 Example Hierarchy
Processor (top)
├── ALU
│ ├── Adder
│ └── Comparator
├── Register File
└── Control Unit
├── Decoder
└── FSM
তুমি আগে full adder এবং 4-bit adder এ module instantiation দেখেছো। আরো examples:
mux2 একবার লিখে mux4 তে ৩ বার ব্যবহার করেছি। mux4 আরো বড় design এ ব্যবহার করেছি। এভাবে reusability আর clarity দুটোই পাও!
Testbenches — মডিউল টেস্ট করো
একটা module লেখার পরে এটা test করতে হয় — input values দিয়ে output check করতে হয়। এই test code-কে বলে testbench।
Testbench একটি special Verilog module যা:
- Design-under-test (DUT) module instantiate করে
- Test inputs generate করে
- Outputs monitor করে
- Expected values এর সাথে compare করে
- Results display করে
Testbench hardware synthesize হয় না — এটা শুধু simulation এর জন্য। তাই initial blocks, $display, delays ইত্যাদি freely ব্যবহার করতে পারো।
Verilog এ testing এর জন্য special system tasks আছে ($ দিয়ে শুরু):
| Task | Purpose | Example |
|---|---|---|
$display |
Print to console | $display("Sum = %d", sum); |
$monitor |
Auto-print on change | $monitor("Q = %b", Q); |
$finish |
End simulation | $finish; |
$time |
Current simulation time | $display("Time = %t", $time); |
এই testbench clock generate করে (forever #5 clk = ~clk), reset/enable signals control করে, এবং counter output monitor করে। প্রতিটা clock cycle এ count value print হয়।
Verilog simulator (Icarus Verilog, ModelSim, ইত্যাদি) ব্যবহার করে:
Advanced Verilog — Parameters, Generate, Tasks
এই concepts industry-grade design এর জন্য essential। Code reusability এবং scalability dramatically increase করে।
Real-World Verilog — Industry Best Practices
Professional Verilog design এর জন্য memory modeling, common design patterns, এবং synthesis best practices শিখো।
Exam Practice — Code পড়া ও লেখা
তোমার instructor দুই ধরনের question করতে পারেন। দুইটাই practice করো।
❓ এই code টা কী করছে? Truth table বানাও।
"Design a 2-to-1 Multiplexer with inputs A, B (data) and Sel (select). When Sel=0 output Y=A, when Sel=1 output Y=B."
❓ If A=4'b0011 (3) and B=4'b0101 (5), Cin=0, what are Sum and Cout?
Quiz — নিজেকে Test করো
Lecture শেষ হলে এই quiz দাও। সব ঠিক হলে তুমি ready!
Comprehensive Quizzes — সব Topics Test
70+ questions covering ALL topics from basics to advanced। প্রতিটা quiz 10 questions। সব quizzes complete করলে তুমি Verilog expert!
📊 Quiz Structure
- Quiz 1: Verilog Basics & Keywords (10 questions)
- Quiz 2: Data Types — wire vs reg (10 questions)
- Quiz 3: All Operators (10 questions)
- Quiz 4: Modeling Styles (10 questions)
- Quiz 5: Blocking vs Non-blocking — CRITICAL! (10 questions)
- Quiz 6: Advanced Topics (10 questions)
- Quiz 7: FSM & Sequential Logic (10 questions)
Total: 70 Questions covering ENTIRE Verilog curriculum!
Quiz 1: Verilog Basics & Keywords
Quiz 2: Data Types — wire vs reg
Quiz 3: All Operators
Quiz 4: Modeling Styles
Quiz 5: Blocking vs Non-blocking — CRITICAL!
Quiz 6: Advanced Topics
Quiz 7: FSM & Sequential Logic
🎉 Congratulations!
তুমি যদি সব quizzes complete করো এবং 80%+ score পাও, তুমি Verilog HDL expert! এখন তুমি industry-grade digital designs করতে পারবে।
- ✅ Combinational এবং Sequential logic design
- ✅ FSM implementation
- ✅ Parameterized, reusable modules
- ✅ Professional coding standards
- ✅ Testbench development