The Multifunction Timer (MFT) used in low-end Motorola microcontrollers (68HC7O5J1A, 68HC705K1, etc.) is much more simplified when compared to its predecessors. It doesn’t perform the three traditional main timer functions: Timer Overflow (TOF), Input Capture (ICF), and Output Compare (OCF). Instead, the MFT provides only the Timer Overflow feature. The absence of the Input Capture (ICF) capability, with its easily manipulated change of the positive and negative edges of the captured signal, makes accurate pulse-width measurement non-obvious.
The idea described here demonstrates a way to overcome this deficiency of low-end MFT using a simple software solution. The Pulse Width Detector measures the width of an input pulse (W), compares it with the given value (WO), and indicates the result by illuminating one of corresponding LEDs: “More”, “Equal”, or “Less” (see the figure). The assembler program for the Pulse Width Detector is given (see the listing).
The Pulse Width Detector takes advantage of the fact (unfortunately, not mentioned in all Motorola manuals) that, when Port A pins are employed as edge-sensitive external interrupt inputs, these pins can be used simultaneously as regular level-sensitive input pins.
Using this method, the measurement procedure becomes straightforward. The rising edge of a measured pulse on pin A0 causes an interrupt. The interrupt service routine activates the counter W, which counts until a high level exists on pin A0. The falling edge of the measured pulse stops the counting, and counter W contains the pulse-width information.
This kind of detector was used in Armatron’s wireless data-transmission system to recognize pulse-width variations from W*TR to (W+1)*TR, where W (the contents of the counter W) = 0,1,2,....255. TR (time resolution) is determined by period of the timer W increment, which depends on the counter loop duration (9 µs) and the constant N (end of the loop condition). The time resolution should be chosen according to design objectives. In our detector, N = 55, which yields TR = (9 µs × 55) + 0.5 µs = 0.5 ms. The maximum time measured is limited only by the number of counter W stages used.
Because this idea requires only one external interrupt pin, the techniques are usable with most microcontrollers. Other possible applications are multiwidth pulse detection, pulse-width decoding, width-to-digit conversion, and so on.