5.5.23 · D3 · HinglishEmbedded Systems & Real-Time Software

Worked examplesWatchdog timers — purpose, feeding, types

3,615 words16 min read↑ Read in English

5.5.23 · D3 · Coding › Embedded Systems & Real-Time Software › Watchdog timers — purpose, feeding, types

Yeh page parent watchdog note ki "no case left behind" companion hai. Shuru karne se pehle, woh ek formula dobara samajhte hain jis par neeche sab kuch tika hua hai, taaki koi bhi symbol bina explanation ke na aaye.

Figure 1 ise ek picture mein dikhata hai: blue line ko se neeche ramp karte dekhein, aur har yellow dot ko ise top par snap karte dekhein — woh snap ek "feed" hai. Zero par red dashed line woh jagah hai jahan reset fire hoti hai.

Figure — Watchdog timers — purpose, feeding, types

Scenario matrix

Watchdog topic se aane wala har sawaal in cells mein se kisi ek mein rehta hai. Baad ke examples har baar announce karte hain ki woh kaun si cell fill kar rahe hain.

Cell Case class Kya test ho raha hai
A Plain timeout, saari values di hui hain Formula ka direct use
B Prescaler ke liye backwards solve karna Target paane ke liye chunna
C 8-bit vs 16-bit counter (chhota ) Counter width ka effect
D Zero / degenerate input (, ya "kabhi feed nahi") Limiting behaviour, sanity edges
E Feed-margin: kya loop time par khatam hoti hai? Worst-case loop timing
F Too-late fault (ek hang) Regular WDT slow/frozen code ko pakadta hai
G Too-early fault (window WDT) Window WDT fast/runaway code ko pakadta hai
H Real-world word problem Ek real device ke liye timeout chunna
I Exam twist (interrupt storm "healthy" lagta hai) Window kyun zaroori hai

Worked examples

Example 1 — Cell A: plain timeout

Forecast: pehle andaza lagao — kya yeh milliseconds, seconds, ya minutes mein hoga? Likh lo.

  1. ko Hz mein likho. . Yeh step kyun? Formula ko pulses-per-second chahiye, aur "k" ek ka factor chhupata hai; units saaf rakhne se 1000× errors bachte hain.
  2. Plug in karo. (yaad rahe ). Yeh step kyun? Direct application — har symbol known hai.
  3. Arithmetic. s per full count at ; times deta hai s. Yeh step kyun? Ise split karna middle number ( s) dikhata hai jo "no-prescaler" timeout hai, jise hum baad mein reuse karte hain.

Verify: Units — . ✓ Order of magnitude: tens of seconds, parent note ke wale number se match karta hai.


Example 2 — Cell B: prescaler ke liye backwards solve karna

Forecast: andaza lagao ki aapko chhota chahiye ya bada.

  1. Formula ko ke liye rearrange karo. se, isolate karo. Yeh step kyun? Hume jawab pata hai aur knob chahiye — isliye ko akela rakho.
  2. Target plug in karo. . Yeh step kyun? Yeh ideal woh hai jo aapko chahiye hoga agar prescalers continuous hote.
  3. Fixed menu par snap karo. sabse kareeb ke hai. Yeh step kyun? Hardware sirf upar define kiya gaya discrete menu offer karta hai; aapko ek ऐसी value par round karna hai jo physically exist karti ho.
  4. par real timeout check karo. . Yeh step kyun? Delivered timeout, ideal wala nahi, woh hai jo actually aapki protection karta hai.

Verify: , target se ke andar hai — kisi bhi menu prescaler se itna hi kareeb ja sakte hain. ✓


Example 3 — Cell C: 8-bit vs 16-bit counter

Forecast: kya 8-bit version chhota hoga ya lamba, aur roughly kitne factor se?

  1. 8-bit timeout. . Yeh step kyun? Chhote ke saath direct formula.
  2. 16-bit timeout, same knobs. . Yeh step kyun? Sirf woh cheez isolate karo jo badi — counter width.
  3. Ratio. . Yeh step kyun? Dikhata hai ki counter width timeout ko linearly scale karti hai — wider counter hundreds of times zyada patience deta hai.

Verify: exactly (kyunki ). ✓ Narrow counter aapko ya toh bahut baar feed karne par majboor karta hai ya huge prescaler use karne par.


Example 4 — Cell D: degenerate inputs & limits

Forecast: sabse chhote timeout ka andaza lagao aur socho kya hoga agar aap kabhi feed na karo.

  1. no-divide limit hai. . Yeh step kyun? har clock pulse pass karta hai — koi slowing nahi — isliye yeh is hardware ke timeout range ka floor hai.
  2. "Kabhi feed nahi" interpret karo. Counter simply ek baar run karta hai, bina ruke, phir ek reset trigger karta hai. Yeh step kyun? Ek watchdog jo enable hai lekin kabhi feed nahi hota woh exactly ek timeout ke baad guarantee se fire karta hai — yeh dead-man's-switch limit hai.
  3. Degenerate case ? Illegal — menu par aisa koi prescaler exist nahi karta; clock ko se divide karna meaningless hai. Yeh step kyun? Invalid input cover karo taaki reader kabhi iska expect na kare. Hardware simply offer nahi karega.

Verify: Sabse chhota timeout Example 1 ke split ke row ke barabar hai. ✓ Examples ke beech consistency formula confirm karti hai.


Example 5 — Cell E: feed-margin timing

Forecast: margin ms mein guess karo, phir doubling ke liye yes/no guess karo.

  1. Feeds ke beech worst-case time = full loop. . Yeh step kyun? Kyunki hum sirf loop ke baad feed karte hain (parent ke [!mistake] ko dekho jo bahut jaldi feed karne par hai), do feeds ke beech gap ek poori loop hai.
  2. Margin. . Yeh step kyun? Margin woh slack hai jisse pehle ek legitimate slow loop dog ko trip karti hai. Positive margin = safe.
  3. Doubling sawaal directly answer karo. task double karo → naya loop . Timeout se compare karo: , isliye haan, yeh phir bhi safe hai, naye margin ke saath . Yeh step kyun? Sawaal ne ek specific 2× scenario poocha, isliye hum woh exact case compute karte hain na ki ek general bound.
  4. Woh task kitna bada ho sakta hai trouble se pehle? Fixed tasks kha jaate hain, beech wale task ke liye bachte hain — isliye woh se badhkar tak ja sakta hai (4× blow-up) timeout edge ko touch karne se pehle. Yeh step kyun? 2× answer ko poore safe range ke andar frame karta hai, taaki reader specific case aur uska headroom dono dekhe.

Figure 2 ise ek bar ke roop mein dikhata hai: blue chunk loop hai, green chunk margin hai, aur red dashed line woh timeout hai jise dono milkar cross nahi karne chahiye.

Figure — Watchdog timers — purpose, feeding, types

Verify: ✓. Doubled loop → safe ✓. Max middle-task length ✓.


Example 6 — Cell F: ek "too-late" fault (ek hang)

= last successful feed ka time (woh aakhri moment jab counter par reload hua). Neeche saari timing se measure ki gayi hai.

Forecast: andaza lagao ki hang shuru hone ke kitne ms baad reset hota hai.

  1. Last good feed. Iteration 6 ne par finish karke feed kiya. Counter par reload hota hai. Yeh step kyun? Reset clock last successful feed se shuru hota hai, hang se nahi.
  2. Counter free-runs. Aur koi feeds nahi, counter march karta hai, poora leta hai. Yeh step kyun? Hang = feeding ruk gayi = Example 4 ka never-fed limit kick in karta hai.
  3. Reset instant. Reset par fire hoti hai. Dead time (hang start se, jo ke baad hai) at most hai. Yeh step kyun? Downtime ka guaranteed upper bound deta hai — woh number jo ek safety engineer ko care karta hai.

Figure 3: green vertical lines tak healthy feeds hain; red band bina feeds ka hang hai; red dashed line par reset mark karti hai.

Figure — Watchdog timers — purpose, feeding, types

Verify: Dead time ✓. Agar hang feed ke right baad shuru ho, worst-case downtime = ; agar loop mein der se ho, kam. Dog hamesha ek timeout ke andar recover karta hai.


Example 7 — Cell G: ek "too-early" fault (window watchdog)

Ek window watchdog feed sirf ek time window ke andar accept karta hai. Define karo, previous feed ke baad se measure karke:

  • — sabse jaldi legal feed time. se pehle feed karna ek fault hai (code bahut tez chal raha hai).
  • — sabse der legal feed time. ke baad feed karna ek fault hai (code hung, plain dog ki tarah).
  • — actual time, last feed ke baad se, jis par yeh feed hoti hai.

Rule hai . Is example mein hardware set hai taaki aur .

Forecast: legal ya reset? Aur kaun sa bound violate hota hai?

  1. Lower bound se compare karo. , aur . Kyunki , hum bahut jaldi feed kar rahe hain. Yeh step kyun? Ek window watchdog ke paas do comparators hote hain; early feed "not before " test fail karta hai.
  2. Result. se pehle feed karna ek fault treat hota hai → reset. Yeh step kyun? Lower bound ka poora point yahi hai: code jo bahut tez chal raha hai (ek interrupt storm, ek runaway loop) utna hi broken hai jitna frozen code.
  3. Plain watchdog kyun miss karta hai. Ek plain dog sirf check karta hai. Kyunki , woh fast feed happily accept kar leta aur "healthy" dekhta. Koi upper-only dog early detect nahi kar sakta. Yeh step kyun? Exactly woh gap name karta hai jo window fill karta hai — ek regular WDT ka koi lower bound hi nahi hota.

Figure 4 timeline ko last feed ke baad teen zones mein shade karta hai: ek red "too early" zone se neeche, ek green "OK window" dono bounds ke beech, aur ek red "too late" zone ke upar. par yellow dot red early zone mein padta hai.

Figure — Watchdog timers — purpose, feeding, types

Verify: → window ke bahar → reset ✓. Plain dog sirf ke saath: → accepted, bug hidden ✓ (proving window zaroori hai).


Example 8 — Cell G/D limit: bilkul boundary par

Forecast: kya endpoints andar hain ya bahar?

  1. Strict inequalities interpret karo. Bounds strict hain (, na ki ): open interval . Yeh step kyun? Boundary behaviour ek classic degenerate case hai — "exactly edge par" ko pin down karna zaroori hai.
  2. Har ek test karo. : fail karta hai (). : safe (). : fail karta hai (). Yeh step kyun? Edges par dono comparators literally apply karta hai.
  3. Design lesson. Centre () aim karo, kabhi edge nahi, taaki kuch ms ka clock jitter aapko bahar na dhakele. Yeh step kyun? Real clocks drift karte hain; dono sides par margin safe target hai.

Verify: Sirf satisfy karta hai ✓; dono endpoints strict inequalities se exclude hain ✓.


Example 9 — Cell H: real-world word problem

Forecast: andaza lagao kaunsa menu prescaler jeetega.

  1. Requirement set karo. chahiye (ek cycle) transmit ke liye slack ke saath — roughly target: itna lamba ki false-trip kabhi na ho, itna chhota ki jaldi recover ho. Yeh step kyun? Timeout feeds ke beech sabse lamba legitimate time exceed karna chahiye, warna valid long operations false resets trip kar deti hain.
  2. Base () timeout ek baar compute karo. . Yeh step kyun? Har menu value sirf is base ko se scale karti hai, isliye ise ek baar compute karne se baaki sab multiply karke mil jaate hain.
  3. ko se multiply karke menu scan karo.
    • : transmit se chhota → false resets. Reject.
    • : se comfortably upar aur se bhi upar; sane time mein recover karta hai. Accept.
    • : — hang se recover karne mein do minute se zyada; needlessly slow. Reject. Yeh step kyun? Menu walk karna dikhata hai ki sabse chhota prescaler hai jo dono legitimate operations clear karta hai, sabse tezi se safe recovery deta hai.
  4. Chuna hua timeout state karo. ke saath: . Yeh step kyun? Final deliverable — woh number jo aap actually device mein program karte ho.

Verify: deta hai ✓ aur transmit ✓; deta hai → correctly rejected ✓; deta hai , over-long ✓. Aisi reset ke baad device ko kya karna chahiye iske liye Fault Tolerance aur Safe State Design dekhein.


Example 10 — Cell I: exam twist (interrupt storm "healthy" lagta hai)

Forecast: mein feed count guess karo.

  1. Feeds count karo. Har mein ek feed, isliye mein: feeds. Yeh step kyun? Feeding ki frequency batati hai ki dog system health kaise "dekhta" hai.
  2. Plain dog ko yeh healthy kyun lagta hai. Har feed se bahut pehle hoti hai, isliye counter kabhi zero nahi pahunchta. Plain dog "alive" report karta hai — even though timing bahut tez hai. Yeh step kyun? Blind spot expose karta hai: ek plain dog jawab deta hai "kya yeh chal raha hai?" na ki "kya yeh sahi rate par chal raha hai?"
  3. Window dog reaction. Window ke saath (so ), par ek feed lower bound violate karti hai () → pehli hi fast feed par reset, aapko timing bug dhundhne par majboor karta hai. Yeh step kyun? Directly dono watchdog types ko us exact failure par contrast karta hai jo regular dog nahi dekh sakta. Yeh "window kyun exist karte hain" ki punchline hai.
  4. Resolution. System storm par reboot karta hai, apni safe state mein enter karta hai, aur developer ek reset dekhta hai jo too-early feed se traceable hai — timing bug ab visible aur fixable hai na ki silently behaviour corrupt kar raha hai. Yeh precisely woh case hai jise ek plain watchdog mask kar deta; Real-Time Operating Systems bhi dekhein jahan per-task feed timing schedule hoti hai. Yeh step kyun? Scenario close karta hai: sirf "reset hoti hai" nahi balki "bug diagnosable ban jaata hai", jo Cell I ka poora payoff hai.

Verify: feeds ✓; → window dog resets ✓; → plain dog accepts, bug hidden ✓.


Recall Quick self-test

, , ke liye timeout? ::: , 16-bit par ke kareeb paane ke liye sabse chhota menu prescaler? ::: , deta hai Equal clock aur prescaler par 16-bit se 8-bit timeout ka ratio? ::: exactly dog ke saath hang ke liye worst-case downtime? ::: (ek full timeout) Agar middle task double hokar ban jaaye dog ke under, safe hai? ::: haan — loop ban jaata hai Kaun sa watchdog woh feed pakadta hai jo bahut jaldi aati hai? ::: window watchdog (lower bound ) mein feeds agar ek ISR har mein feed kare? ::: — aur plain dog ise "healthy" dekhta hai