Embedded Microcomputer Systems Lecture 16.1 Dan, I was going use input capture and build you a "Universal Remote" yippie But the thought of you having universal control over anything is too much for me to handle. oh, man! JwV Lecture 16 objectives are to use: • Input capture to generate edge based interrupts; • Input capture to measure period; • Input capture to measure pulse width; CCPx pins used for input capture: e.g., CCP0=PD4 See book section 8.1 Period Measurement Select clock period, t because measurement resolution TIMER0_TAILR_R = 0xFFFF by Jonathan W. Valvano Embedded Microcomputer Systems Lecture 16.2 Choose edge (rise/fall) Arm interrupt on capture ISR Poll to see which channel (if needed) Now = captured time Period = Now-Last Last = Now Acknowledge interrupt Save/process Period Figure 6.1. Ping))) sensor signals. See PingDocs.pdf for an explanation of this figure. 1) make the SIG pin an output; 2) issue a 5 s output pulse; 3) switch the SIG pin to back to an input; and 4) measure the tIN. Rising edge, record TAR Falling edge, calculate tIN. For HCSR04, skip steps 1,3 by Jonathan W. Valvano Embedded Microcomputer Systems Lecture 16.3 +3.3V TLC2274 or OPA2350 Microcontroller +3.3V 5k V1 R2 V2 + Input capture QRB1134 2V +3.3V 100 R1 light V2 V1 3.3V 2V 0V Use AddPeriodicThread to detect period too long (speed to slow) Tachometer data collected with a 15-slot disk powered at +9V. IR sensor interface on left by Jonathan W. Valvano Embedded Microcomputer Systems Lecture 16.4 What does this circuit do? 100k 3.3V 10k Vin Vout 10k 3.3V 10k See two examples InputCapture_4F120 count edges PeriodMeasure_4F120 16-bit period measurement. How to choose the resolution Determine the minimum and maximum robot speed Convert speed to tachometer period For example Period P resolution Speed Speed 7100 4 10 3.521127 211.2676 holes/rotation usec rps RPM by Jonathan W. Valvano Embedded Microcomputer Systems Lecture 16.5 Should you filter the tachometer? Reduce noise (good) Increase lag (very very bad) Raw IIR filter, y(n) = (y(n-1)+x(n))/2 FIR filter, y(n) = (x(n)+x(n-1))/2 Median of x(n),x(n-1),x(n-2) 7600 7550 Period (10 s) 7500 7450 7400 7350 7300 7250 7200 7150 7100 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 Sample number How to detect a speed too slow (period too large)? Clear a counter on each tachometer edge Increment the counter on each rollover 0000 to FFFF If counter >= 2, then wheel is stopped by Jonathan W. Valvano
© Copyright 2026 Paperzz