Hardware Reference
In-Depth Information
A successful compare sets the corresponding flag bit in the 8-bit TFLG1 register. An
interrupt is generated if it is enabled. An output-compare interrupt is enabled by setting the
corresponding bit in the TIE register. The same bit enables either the input-capture or output-
compare interrupt, depending on which one is selected.
The OC7 channel has the option to reset TCNT when the TC7 register matches the TCNT.
This option is enabled by setting the TCRE bit of the TSCR2 register. This feature makes the
TCNT a programmable modulus counter.
8.6.3 Applications of the Output-Compare Function
An output-compare function can be programmed to perform a variety of functions.
Generation of a single pulse, a square wave, and a specific delay are among the most popular
applications.
To generate a periodic square waveform, the user may use the output-compare function
to continuously toggle the selected Port T pin with appropriate delay added in each output-
compare operation. The first output-compare operation must be started by the main function
whereas the remaining output-compare operations may be performed by the main function
or the output-compare interrupt service routine depending on the approach. The following
example uses the interrupt-driven approach.
Example 8.4
Generate an active high 1-kHz digital waveform with a 30 percent duty cycle from the PT5
pin. Use the interrupt-driven method to check the success of the output-compare operation.
The frequency of the E-clock is 24 MHz.
Solution: An active high 1-kHz waveform with a 30 percent duty cycle is shown in Figure 8.19.
300
µ
s
700 µ s
Figure 8.19 A 1-kHz 30 percent duty cycle waveform
The logic flow of this problem is illustrated in Figure 8.20. Suppose we set the prescale
factor to 8 so that the period of the clock input to TCNT is set to 1/3
s. Then the inter-
vals of the PT0 signal to be high and low in one period would be 900 and 2100 clock cycles,
respectively.
The algorithm first pulls the PT5 pin to high in a very short period of time using the output-
compare operation and then changes the pin action to toggle and enable the OC5 interrupt. The
OC5 interrupt simply starts the next output-compare operation.
μ
 
Search WWH ::




Custom Search