5.5.3 · D3 · HinglishEmbedded Systems & Real-Time Software

Worked examplesTimers — PWM generation, input capture, output compare

2,622 words12 min read↑ Read in English

5.5.3 · D3 · Coding › Embedded Systems & Real-Time Software › Timers — PWM generation, input capture, output compare


Scenario matrix

Har timer problem in cells mein se ek (ya inka blend) hoti hai. Neeche har worked example tagged hai un cell(s) ke saath jo wo cover karta hai.

# Cell (case class) Kya tricky hai Example
A Forward design, PWM % — target frequency + duty ke liye PSC/ARR/CCR choose karo PSC choose karna taaki ticks tidy rahein Ex 1
B Forward design, pulse-width (servo/ESC) — CCR ko µs mein set karo, % mein nahi duty irrelevant hai; width matter karta hai Ex 2
C Degenerate duty — 0%, 100%, aur top par off-by-one vs Ex 3
D Toggle mode — square wave, divide-by-2 subtlety do toggles = ek period Ex 4
E Input capture, no wrap — frequency measure karo plain subtraction Ex 5
F Input capture, WITH wrap — negative-difference trap modulo arithmetic Ex 6
G Limiting / resolution — 16-bit timer ki smallest & largest frequency ARR range limits Ex 7
H Real-world word problem — LED ko perceived brightness par dim karo physical want ko registers se map karna Ex 8
I Exam twist — scope reading dekhke registers reverse-engineer karo har formula ko invert karo Ex 9
Figure — Timers — PWM generation, input capture, output compare

Example 1 — Cell A: forward PWM design


Example 2 — Cell B: pulse-width design (servo)


Example 3 — Cell C: degenerate duties (0%, 100%)


Example 4 — Cell D: toggle mode square wave

Figure — Timers — PWM generation, input capture, output compare

Example 5 — Cell E: input capture, no overflow


Example 6 — Cell F: input capture ACROSS an overflow

Figure — Timers — PWM generation, input capture, output compare

Example 7 — Cell G: 16-bit timer ki limiting frequencies


Example 8 — Cell H: real-world word problem (LED dimming)


Example 9 — Cell I: exam twist (scope se reverse-engineer)


Kaun sa cell kaun sa hai — decision flow

pin waveform chahiye

signal measure karna hai

target ek percent hai

target ek pulse width hai

sirf ek square wave chahiye

c2 greater than c1

c2 less than c1

Start: kya given hai?

Design mode Time to Pin

Capture mode Pin to Time

Solve ARR then CCR equals duty times ARR plus 1

Set CCR equals width in ticks

Toggle mode divide match rate by 2

Delta equals c2 minus c1

Delta equals difference mod ARR plus 1

Check degenerate 0 and 100 percent


Active recall


Connections

  • Parent topic (Hinglish) — wo machinery jin par ye examples exercise karte hain.
  • Clock Tree and Prescalers — jahan se aur tidy-tick choices aate hain.
  • GPIO and Alternate Functions — wo pin jo har PWM/toggle example drive karta hai.
  • Interrupts and NVIC — Cell F wrap case ke liye overflow-counting.
  • Servo and ESC Control — Example 2 ki pulse-width interpretation.
  • Motor Control and H-Bridges — Example 1 & 8 style duty control at speed.
  • Encoder Mode — curious logon ke liye ek capture cousin.