المسجلات والعدادات
دراسة شاملة للمسجلات، مسجلات الإزاحة، والعدادات التموجية والمتزامنة في التصميم المنطقي الرقمي.
Registers and Counters
Comprehensive study of registers, shift registers, and both ripple and synchronous counters in digital logic design.
أهداف التعلم
- فهم استخدام ووظائف وأنماط تشغيل المسجلات، مسجلات الإزاحة، ومسجلات الإزاحة الشاملة.
- معرفة كيفية إنشاء تأثير النبضة الموجهة (gated clock) بشكل صحيح.
- فهم هيكل ووظيفة دائرة الجامع التسلسلي.
- فهم سلوك العداد التموجي والعداد المتزامن.
- Understand the use, functionality, and modes of operation of registers, shift registers, and universal shift registers.
- Know how to properly create the effect of a gated clock.
- Understand the structure and functionality of a serial adder circuit.
- Understand the behavior of a (a) ripple counter, (b) synchronous counter.
1 المسجلات (Registers)
1 Registers
المسجل هو مجموعة من القلابات (Flip-flops) تتشارك في نبضة ساعة واحدة لتخزين البيانات الثنائية، مثل صندوق أمانات يفتح ويغلق في نفس اللحظة.
A register is a group of flip-flops sharing a common clock to store binary data, like a row of lockers that open and close simultaneously.
المسجل ذو n-بت يتكون من مجموعة من n قلاب (Flip-flop) قادرة على تخزين n بت من المعلومات الثنائية. في أبسط أشكاله، يتكون المسجل من قلابات فقط دون أي بوابات إضافية.
يتم تشغيل جميع القلابات بواسطة مدخل ساعة مشترك (Clock) عند الحافة الموجبة لكل نبضة، مما يؤدي إلى نقل البيانات المتوفرة على المداخل إلى داخل المسجل.
كما يحتوي عادةً على مدخل تصفير (Clear_b) غير متزامن لمسح محتويات المسجل (جعلها أصفاراً) قبل بدء التشغيل.
An n-bit register consists of a group of n flip-flops capable of storing n bits of binary information. In its simplest form, it consists of only flip-flops without any gates.
The common clock input triggers all flip-flops on the positive edge of each pulse, transferring the binary data available at the inputs into the register.
It typically includes an active-low asynchronous reset input (Clear_b) to clear the register to all 0's prior to clocked operation.
لماذا نستخدم إشارة Clear غير متزامنة؟ لأننا نحتاج إلى تهيئة النظام إلى حالة معروفة (أصفار) عند بدء التشغيل دون انتظار نبضة الساعة.
يجب الحفاظ على إشارة التصفير عند المنطق 1 (de-asserted) أثناء التشغيل العادي.
Why use an asynchronous Clear signal? Because we need to initialize the system to a known state (all zeros) upon power-up without waiting for a clock edge.
The reset inputs must be maintained at logic 1 (de-asserted) during normal clocked operation.
ماذا يحدث إذا تغيرت قيم المداخل (I3, I2, I1, I0) في اللحظة التي تلي الحافة الموجبة لنبضة الساعة مباشرة؟ What happens if the input values (I3, I2, I1, I0) change immediately after the positive edge of the clock pulse?
لن تتأثر مخرجات المسجل. المسجل يلتقط البيانات فقط عند الحافة الموجبة للساعة. أي تغييرات بعد الحافة سيتم تجاهلها حتى الحافة الموجبة التالية.
The register outputs will not be affected. The register only captures data exactly at the positive clock edge. Any changes after the edge are ignored until the next positive edge.
2 المسجلات ذات التحميل المتوازي (Registers with Parallel Load)
2 Registers with Parallel Load
بما أن قلابات D لا تملك حالة 'عدم تغيير'، نستخدم بوابات منطقية لإنشاء مسار تغذية راجعة يحافظ على البيانات عندما لا نرغب في تحميل بيانات جديدة.
Since D flip-flops lack a 'no change' state, we use logic gates to create a feedback loop that holds the data when we don't want to load new information.
يحدد مدخل التحميل (Load) الإجراء الذي سيتم اتخاذه مع كل نبضة ساعة.
- عندما يكون Load = 1، يتم نقل البيانات الموجودة على المداخل الخارجية الأربعة إلى المسجل مع الحافة الموجبة التالية للساعة.
- عندما يكون Load = 0، يتم توصيل مخرجات القلابات بمداخلها الخاصة (تغذية راجعة).
هذا الاتصال الراجع ضروري لأن قلاب D لا يحتوي على حالة 'عدم تغيير' (No change). البوابات الإضافية تعمل كمضاعف إرسال (Multiplexer) بقناتين لكل قلاب.
The load input determines the action taken with each clock pulse.
- When load is 1, data at the external inputs are transferred into the register on the next positive clock edge.
- When load is 0, the outputs of the flip-flops are connected to their respective inputs (feedback).
This feedback is necessary because a D flip-flop does not have a 'no change' condition. The additional gates effectively implement a two-channel multiplexer for each flip-flop.
لماذا لا نتحكم في إشارة الساعة (Clock Gating) بدلاً من استخدام التغذية الراجعة؟ التحكم المباشر في إشارة الساعة باستخدام بوابات منطقية قد يؤدي إلى مشاكل في التزامن (Clock Skew) ونبضات وهمية (Glitches).
التصميم المتزامن السليم يفضل إبقاء إشارة الساعة مستمرة واستخدام إشارات التحكم (مثل Load) لتوجيه البيانات عبر مضاعفات الإرسال (MUX).
Why not just gate the clock signal instead of using feedback? Directly gating the clock with logic gates can introduce clock skew and glitches.
Proper synchronous design practices dictate keeping the clock continuous and using control signals (like Load) to route data via multiplexers (MUX).
كيف تعمل البوابات المنطقية (AND و OR) المضافة قبل قلاب D كمضاعف إرسال (MUX)؟ How do the added logic gates (AND and OR) before the D flip-flop act as a multiplexer (MUX)?
بوابة AND الأولى تمرر البيانات الجديدة إذا كان Load=1، وبوابة AND الثانية تمرر البيانات القديمة إذا كان Load=0. بوابة OR تجمع النتيجتين، مما يسمح بمرور مسار واحد فقط بناءً على قيمة Load، وهو بالضبط عمل الـ MUX 2x1.
The first AND gate passes new data if Load=1, and the second AND gate passes old data if Load=0. The OR gate combines them, allowing only one path through based on the Load signal, which is exactly how a 2x1 MUX operates.
3 مسجلات الإزاحة (Shift Registers)
3 Shift Registers
مسجل الإزاحة هو سلسلة من القلابات تنقل البيانات من خلية إلى الخلية المجاورة لها مع كل نبضة ساعة.
A shift register is a chain of flip-flops that moves data from one cell to its neighbor with each clock pulse.
مسجل الإزاحة هو مسجل قادر على إزاحة المعلومات الثنائية المحفوظة في كل خلية إلى الخلية المجاورة لها، في اتجاه محدد. يتكون التكوين المنطقي من سلسلة من القلابات المتتالية (Cascade)، حيث يتم توصيل مخرج قلاب واحد بمدخل القلاب التالي.
تتلقى جميع القلابات نبضات ساعة مشتركة، والتي تنشط إزاحة البيانات من مرحلة إلى أخرى. يحدد 'المدخل التسلسلي' (Serial Input) ما يدخل إلى القلاب في أقصى اليسار، بينما يؤخذ 'المخرج التسلسلي' (Serial Output) من القلاب في أقصى اليمين.
A shift register is capable of shifting the binary information held in each cell to its neighboring cell, in a selected direction. The logical configuration consists of a chain of flip-flops in cascade, with the output of one flip-flop connected to the input of the next.
All flip-flops receive common clock pulses, which activate the shift of data from one stage to the next. The 'serial input' determines what goes into the leftmost flip-flop, while the 'serial output' is taken from the rightmost flip-flop.
في النقل التسلسلي بين مسجلين (A إلى B)، لمنع فقدان البيانات في المسجل المصدر (A)، يتم توصيل المخرج التسلسلي لـ A بمدخله التسلسلي.
هكذا، أثناء إزاحة البيانات إلى B، تدور البيانات داخل A لتعود إلى حالتها الأصلية بعد n من النبضات (حيث n هو حجم المسجل).
In serial transfer between two registers (A to B), to prevent loss of information in the source register (A), its serial output is connected to its serial input.
Thus, while data shifts into B, it circulates within A, restoring A to its original state after n clock pulses (where n is the register size).
| Serial Transfer | Parallel Transfer | |
|---|---|---|
| طريقة النقل Transfer Method | بت واحد في كل مرة One bit at a time | جميع البتات في نفس الوقت All bits simultaneously |
| خطوط الإدخال/الإخراج I/O Lines | خط إدخال تسلسلي واحد وخط إخراج واحد Single serial input and output | خطوط متعددة (n خطوط لـ n بت) Multiple lines (n lines for n bits) |
| السرعة Speed | أبطأ (يتطلب n نبضات) Slower (requires n clock pulses) | أسرع (نبضة ساعة واحدة) Faster (one clock pulse) |
ما هو الفرق الأساسي بين النقل التسلسلي والنقل المتوازي من حيث الوقت والموارد؟ What is the main difference between serial and parallel transfer in terms of time and resources?
النقل المتوازي أسرع (يستغرق نبضة ساعة واحدة) ولكنه يتطلب خطوط توصيل متعددة (مورد أكبر). النقل التسلسلي أبطأ (يستغرق n نبضات لـ n بت) ولكنه يتطلب خط توصيل واحد فقط، مما يوفر المساحة والأسلاك.
Parallel transfer is faster (takes 1 clock pulse) but requires multiple data lines (more resources). Serial transfer is slower (takes n pulses for n bits) but requires only a single data line, saving space and wiring.
4 مسجل الإزاحة الشامل (Universal Shift Register)
4 Universal Shift Register
هو مسجل 'الكل في واحد': يمكنه الإزاحة يميناً، الإزاحة يساراً، التحميل المتوازي، أو الاحتفاظ بالبيانات، ويتم التحكم فيه عبر إشارات اختيار.
It's an 'all-in-one' register: it can shift right, shift left, parallel load, or hold data, controlled by selection signals.
مسجل الإزاحة الشامل يمتلك القدرات التالية:
- تصفير (Clear)،
- إدخال ساعة (Clock)،
- إزاحة لليمين (Shift-right)،
- إزاحة لليسار (Shift-left)،
- تحميل متوازي (Parallel-load)،
- مخرجات متوازية،
- وحالة عدم التغيير (No change).
يتم بناء مسجل 4-بت باستخدام أربعة قلابات D وأربعة مضاعفات إرسال (MUX) بحجم 4x1. يتم التحكم في وضع التشغيل عبر مدخلي اختيار (s1, s0):
- 00 = عدم تغيير (No change)
- 01 = إزاحة لليمين (Shift right)
- 10 = إزاحة لليسار (Shift left)
- 11 = تحميل متوازي (Parallel load).
A universal shift register has the following capabilities:
- Clear,
- Clock,
- Shift-right,
- Shift-left,
- Parallel-load,
- Parallel outputs,
- and a No-change state.
A 4-bit version is constructed using four D flip-flops and four 4x1 multiplexers. The mode of operation is controlled by two selection inputs (s1, s0):
- 00 = No change
- 01 = Shift right
- 10 = Shift left
- 11 = Parallel load.
في وضع الإزاحة لليمين (s1s0=01)، تدخل البيانات من MSB_in وتنتقل نحو LSB.
في وضع الإزاحة لليسار (s1s0=10)، تدخل البيانات من LSB_in وتنتقل نحو MSB.
استخدام MUX 4x1 لكل قلاب يوفر طريقة أنيقة وقابلة للتوسع لتوجيه مسارات البيانات المختلفة دون تعقيد البوابات المنطقية الفردية.
In shift-right mode (s1s0=01), data enters from MSB_in and moves towards the LSB.
In shift-left mode (s1s0=10), data enters from LSB_in and moves towards the MSB.
Using a 4x1 MUX for each flip-flop provides an elegant, scalable way to route the different data paths without complex individual logic gate networks.
إذا أردنا تصميم مسجل إزاحة شامل بـ 8 بت، كم عدد مضاعفات الإرسال (MUX) التي سنحتاجها وما هو حجمها؟ If we want to design an 8-bit universal shift register, how many MUXes would we need and what size?
سنحتاج إلى 8 مضاعفات إرسال (MUX)، واحد لكل قلاب. حجم كل منها سيظل 4x1 لأننا لا نزال نحتاج إلى الاختيار بين 4 عمليات فقط (عدم تغيير، يمين، يسار، متوازي).
We would need 8 MUXes, one for each flip-flop. The size of each MUX would still be 4x1 because we still only need to select between 4 operations (no change, right, left, parallel).
5 العدادات التموجية (Ripple Counters)
5 Ripple Counters
في العداد التموجي، مخرج كل قلاب يعمل كنبضة ساعة للقلاب الذي يليه، مما يخلق تأثير 'الدومينو' أو التموج.
In a ripple counter, the output of one flip-flop acts as the clock for the next, creating a 'domino' or ripple effect.
العداد هو مسجل يمر بتسلسل محدد مسبقاً من الحالات. في العداد التموجي (Ripple Counter)، لا يتم تشغيل القلابات بواسطة نبضة ساعة مشتركة. بدلاً من ذلك، يعمل انتقال مخرج القلاب كمصدر لتشغيل القلابات الأخرى.
يتكون العداد الثنائي التموجي من سلسلة من القلابات المكملة (Complementing flip-flops مثل T أو JK مع J=K=1)، حيث يتصل مخرج كل قلاب بمدخل الساعة (C) للقلاب ذي الرتبة الأعلى التالية.
القلاب الذي يحمل البت الأقل أهمية (LSB) هو الوحيد الذي يتلقى نبضات العد الخارجية.
A counter is a register that goes through a prescribed sequence of states. In a ripple counter, flip-flops are not triggered by a common clock. Instead, a flip-flop output transition serves as a source for triggering other flip-flops.
A binary ripple counter consists of a series connection of complementing flip-flops (like T or JK with J=K=1), with the output of each flip-flop connected to the C (clock) input of the next higher-order flip-flop.
The flip-flop holding the least significant bit (LSB) receives the incoming count pulses.
العداد التموجي التنازلي (Countdown) يعمل بشكل مشابه ولكنه ينقص بمقدار 1. يتم تصميمه عادةً بتوصيل المخرج المكمل (Q') بمدخل الساعة للقلاب التالي.
بالنسبة لعداد BCD التموجي، فإنه يعد من 0 إلى 9 ثم يعود إلى 0. يتطلب هذا بوابات منطقية إضافية لاكتشاف الحالة 1001 (رقم 9) وإجبار العداد على التصفير في النبضة التالية، مما يكسر النمط الثنائي الطبيعي.
A countdown ripple counter decrements by 1. It is typically designed by connecting the complemented output (Q') to the clock input of the next stage.
A BCD ripple counter counts from 0 to 9 and returns to 0. This requires additional logic gates to detect the state 1001 (9) and force the counter to reset on the next pulse, breaking the natural binary sequence.
ما هو العيب الرئيسي للعداد التموجي عند زيادة عدد البتات (n)؟ What is the main disadvantage of a ripple counter as the number of bits (n) increases?
تأخير الانتشار التراكمي (Cumulative Propagation Delay). بما أن كل قلاب ينتظر القلاب السابق ليتغير، فإن الوقت الإجمالي لاستقرار العداد يزداد مع كل بت إضافي، مما يحد من سرعة التشغيل القصوى.
Cumulative propagation delay. Since each flip-flop waits for the previous one to toggle, the total time for the counter to stabilize increases with each added bit, limiting the maximum operating speed.
6 العدادات المتزامنة (Synchronous Counters)
6 Synchronous Counters
في العداد المتزامن، تتلقى جميع القلابات نفس نبضة الساعة في نفس الوقت، مما يجعله أسرع وأكثر استقراراً من العداد التموجي.
In a synchronous counter, all flip-flops receive the same clock pulse simultaneously, making it faster and more stable than a ripple counter.
تختلف العدادات المتزامنة عن العدادات التموجية في أن نبضات الساعة يتم تطبيقها على مداخل (C) لجميع القلابات في وقت واحد.
في العداد الثنائي المتزامن، يتم إكمال (Toggle) القلاب في الموضع الأقل أهمية مع كل نبضة. أما أي قلاب في موضع آخر، فيتم إكماله فقط عندما تكون جميع البتات في المواضع الأقل أهمية تساوي 1.
يتم تحقيق ذلك باستخدام سلسلة من بوابات AND التي تولد المنطق المطلوب لمداخل J و K في كل مرحلة.
Synchronous counters differ from ripple counters in that clock pulses are applied to the C inputs of all flip-flops simultaneously.
In a synchronous binary counter, the flip-flop in the least significant position is complemented with every pulse. A flip-flop in any other position is complemented when all the bits in the lower significant positions are equal to 1.
This is achieved using a chain of AND gates that generates the required logic for the J and K inputs in each stage.
تصميم عداد BCD متزامن يتطلب إجراءات تصميم الدوائر التتابعية (Sequential Circuit Design) لأنه لا يتبع نمطاً ثنائياً منتظماً.
يجب إنشاء جدول حالة (State Table) يوضح الحالة الحالية والحالة التالية، ثم استخدام خرائط كارنوف (K-maps) لاستنتاج معادلات مداخل القلابات (مثل TQ1, TQ2, TQ4, TQ8).
الحالات غير المستخدمة (من 10 إلى 15) تعتبر حالات 'لا يهم' (Don't-care) لتبسيط المعادلات.
Designing a synchronous BCD counter requires formal sequential circuit design procedures because it lacks a regular binary pattern.
A state table must be created showing present and next states, followed by K-maps to derive the flip-flop input equations (e.g., TQ1, TQ2, TQ4, TQ8).
Unused states (10 to 15) are treated as don't-care conditions to simplify the logic.
| Ripple Counter | Synchronous Counter | |
|---|---|---|
| إشارة الساعة (Clock) Clock Signal | مخرج القلاب السابق يشغل القلاب التالي Output of previous FF triggers the next | ساعة مشتركة تشغل جميع القلابات معاً Common clock triggers all FFs simultaneously |
| التعقيد الهيكلي Structural Complexity | بسيط، لا يحتاج بوابات إضافية للعد الثنائي Simple, no extra gates needed for binary count | معقد، يتطلب بوابات AND إضافية للمنطق Complex, requires extra AND gates for logic |
في العداد الثنائي المتزامن ذو 4 بت، متى تتغير قيمة البت الأخير (A3) من 0 إلى 1؟ In a 4-bit synchronous binary counter, when does the last bit (A3) change from 0 to 1?
تتغير قيمة A3 عندما تكون جميع البتات الأقل أهمية (A0, A1, A2) تساوي 1 (أي عند العد 0111 أو 7). في النبضة التالية، ستصبح الحالة 1000 (8).
A3 changes when all lower significant bits (A0, A1, A2) are equal to 1 (i.e., at count 0111 or 7). On the next clock pulse, the state becomes 1000 (8).