Embedded MidKit

CSE 421 · Embedded Systems · Dr. Ahmed Osman MahmoudEmbedded MidKit

🏠 الرئيسية · Hub
الميدترم: أول 5 محاضرات (لحد آخر التايمرز) + شيت 1 و 2. مقالي كله ومن غير داتاشيت. الشرح بالعربي، والجمل اللي تتحفظ بالإنجليزي زي ما هتكتبها في الامتحان. علامة EXAM = جه في امتحان قبل كده.

MIND MAPLectures 1–5 at a glance

الخريطة الكاملة للي داخل في الميد. كل عنوان أزرق بيوديك لشرحه. ذاكر بيها عشان تعرف إنت فين وكل حاجة تابعة لإيه.

    • 1.1 Embedded systems الأساسيات
      • Embedded systemhardware and softwarespecific functionlarger systemmobile phone
      • CPUMemoryRAM, ROM, FlashPeripheralsBus systemssystem bus
      • lower clock speedsintegrated memoryhigher environmental specs
      • Microcontrolleron a single chipone task onlyburned into ROMany number of applications
    • 1.2 MCU selection اختيار الكنترولر
      • CostEnvironmentPeripheral supportScalability
      • Available powerWeighted power≤ available powerPerformancebelow the required frequencyMemory
    • 1.3 ATmega32 المعمارية
      • 8-bit AVRinstructions and dataat the same timeRISC1–2 clock cycles32 general-purpose registers
    • 2.1 Power management الباور
      • IdleADC Noise Reductionprecise analog measurementPower-downmonths/years on a coin cellPower-save
      • P = I × VWorst casemaximumbest caseminimumtypical
    • 2.2 Firmware & Embedded C الفيرموير والـ C
      • Firmwarenon-volatile memoryDriver layerHALMiddlewareApplication
      • GCC
      • what kind of valuehow much memoryPerformance & memoryPortabilityType safetyReadability & maintenance
    • 2.3 GPIO الـ pins
      • A, B, C, DDDRx1 = output, 0 = inputPORTxPINxread-only
      • active-lowPA3
    • 3.1 Coding styles & PWM الكود والـ PWM
      • Flattenhighest speedlow maintainabilityMacro-basedinlineFunction-based
      • PWMDuty cycleSoftware PWMaccuracy issueshigh CPU usageHardware PWM
    • 3.2 Timers & prescaler التايمرز
      • hardware timerwithout busy-waitingprecise timingperiodic tasksPWM generationinput capture
      • Prescalerlonger intervals1, 8, 64, 256, 1024f_timer = F_CPU / NT_tick = N / F_CPU256 µs
    • 3.3 Timer0 Timer0
      • TCNT0write a start valueOCR0TCNT0 == OCR0OC0 (PB3)TCCR0
      • Counter unitcountdirectionclearclkT0TOP
    • 4.1 Normal mode & interrupts العادي والمقاطعة
      • 0x00 (BOTTOM) → 0xFF (TOP)overflows back to 0TOVnTIMERn_OVF_vectN_MAX × 2ⁿ / F_CPUWGM01 = 0, WGM00 = 0
      • ISRinstead of pollingI-bit (bit 7) = 0peripheral enableand global enableinfrequent
    • 4.2 CTC & Fast PWM المقارنة والـ PWM
      • TCNTn == OCRntimer resets to 0OCFn is setTIMERn_COMP_vectTOVn is NOT settoggle / set / clear
      • 0 → TOPinstantly resets to 0saw-tooth255TCNTn == OCRnduty set by OCRn
    • 4.3 Event counter عدّ الأحداث
      • external eventsT0 = PB0T1 = PB1125 nsEdge detectorone count per edge
    • 5.1 Timer1 Timer1
      • 255 (2⁸−1)65,535 (2¹⁶−1)Best practicesave power
      • T1 = PB1OC1A = PD5OC1B = PD4ICP1 = PD6TOSC1/TOSC2 = PC6/PC7TCCR1A, TCCR1B
      • TCNT1HTCNT1L0xFFFF → 0x0000TOV1
      • TCCR1AFOC1A/Bnon-PWM modes onlyWGM11:10TCCR1BICNC1
    • 5.2 Input capture الالتقاط
      • ICP1 pin (PD6)ICES1 in TCCR1B1 = rising, 0 = fallingTCNT1 is copied into ICR1ICF1 in TIFRTICIE1 in TIMSK = 1
    • 5.3 Interrupt registers TIMSK و TIFR
      • TIMSKenableTIFRflagsclear by writing 1
    • 5.4 Examples الأمثلة
      • TCCR1A = 0reloads TCNT1
      • 10 rising-edge pulses on PB0PORTCTimer010th pulse overflowsTCNT0 = 256 − 10 = 246Timer1
    • TCCR0TCCR2TCCR1A/BTIMSKTIFR

Exam format & what the doctor said

  • 25 marks, all essay — no MCQ this year.كله مقالي؛ السنة اللي فاتت كانت 10 MCQ + 6 + 9 كود.
  • Scope: Lectures 1–5 (up to the end of Timers), Sheet 1, Sheet 2.INT0 و USART و ADC Vref برّه.
  • No datasheet: prescaler / mode values are given, but you must know the registers and their bits.الجداول بتتدّى، أسماء الريجسترز والبتات لأ — شوف Registers.
  • Every code answer starts with #define F_CPU + the #include lines (they carry marks), then the SET / CLEAR / TOGGLE / GET macros.الـ includes عليها درجة؛ والماكروز دي طريقة المعيدة. شوف Sheet 2 Ex 0.
  • Last midterm: power 4 · power mode 2 · timer code 9 · theory 10.الكود والحسابات أكتر من نص الدرجة.

Study plan

#LectureSlidesTopicThen solve
1L1S8–S36ES, processors, MCU selectionSheet 1 Q1–Q2 · Final 2026 Q1
2L1S37–S62ATmega32 architecture numbersFlashcards L1
3L2S2–S37Power modes + power calculationSheet 1 Q3–Q6 · Mid 2026 Q2
4L2S38–S73Firmware, data types, GPIOMid 2026 Q1 (3)–(4)
5L3S2–S39Coding styles, software PWMExpected Q: theory set
6L3S40–S69Timers, prescaler, Timer0 registersRegisters: TCCR0 drill · Mid 2026 Q1 (5)–(6)
7L4S2–S25Normal mode + ISRSheet 2 Ex 1a, 1b · Mid 2026 Q3
8L4S26–S65CTC + Fast PWMSheet 2 Ex 2, 3 · Expected Q4
9L4S66–S84Event counterSheet 2 Ex 4 · Expected Q2
10L5S1–S41Timer1, input capture, TIMSK/TIFRRegisters drill (all) · Sheet 2 Ex 5, 6 · Final 2026 Q5
11ALL—Past exams on a timer, newest firstMid 2026 (1 hour) → Final 2026 midterm parts
12ALL—ReviewFlashcards (all) + Solvers presets

Differences from the slides / model answer

  • Preload: slides & model answer use 255 − ticks; mathematically it is 256 − ticks (Sheet 2 code uses 256).فرق tick واحد؛ اكتب القانون اللي بتستخدمه صريح.
  • Timer1 2 s: slide writes 49910; correct 65536 − 15625 = 49911.فرق tick واحد.
  • Vibration example: TCNT1 * (1024/4000) is integer division = 0 in C.غلطة برمجية في السلايد؛ اضرب الأول.
  • Mid 2026 Q3 model code stops Timer0 in the ISR and never restarts it.الحل المصحح في Mid 2026 Question 3.
  • Heartbeat count0() repeats CS00; correct is CS02 + CS01 + CS00.تكرار غلط في السلايد.