Hardware Reference
In-Depth Information
The following C statements achieve the same goal:
OC7M 5 0x1C;
OC7D 5 0x14;
The ability to control multiple output-compare pins is very useful in applications that
require multiple actions to be triggered simultaneously in the near future.
Example 8.10
Suppose that there is an application that requires the following operations to be triggered
50 ms later:
Turn off the light controlled by the TC5 pin
Turn on the temperature sensor controlled by the TC4 pin
Turn off the heater controlled by the TC3 pin
Turn on the music controlled by the TC2 pin
Write an instruction sequence to perform the desired operation.
Solution: The values to be written into OC7M and OC7D are $3C and $14, respectively. Set the pre-
scaler to TCNT to 64. Then the value to be added to create a 50-ms delay can be computed as follows:
Delay 5 (24,000,000 4 64) × 0.05 5 18,750
The following instruction sequence can perform the desired operations 50 ms later:
movb
#$90,TSCR1
; enable TCNT and fast timer flag clear
movb
#$06,TSCR2
; set prescaler to 64
movb
#$3C,OC7M
; allow OC7 to control TC5, TC4, TC3, and TC2 pins
movb
#$14,OC7D
; pin actions for TC5, TC4, TC3, and TC2
ldd
TCNT
; start an OC7 operation with 50 ms as delay
addd
#18750
;
std
TC7
; start the OC7 operation
Two output-compare functions can control the same pin simultaneously. Thus, OC7 can
be used in conjunction with one or more other output-compare functions to achieve even more
time flexibility. We can generate a digital waveform with a given duty cycle by using the OC7
and any other output-compare function.
Example 8.11
Use OC7 and OC0 together to generate a 2-kHz digital waveform with a 40 percent duty
cycle on the PT0 pin. Assume that the E-clock frequency is 24 MHz.
Solution: We set the prescale factor to 8. The period of a 2-kHz waveform is 0.0005 s. The period
of this signal corresponds to 0.0005
(24,000,000 4 8) 5 1500 cycles. The high interval in one
period of the waveform is 600 clock cycles, whereas the low interval is 900 clock cycles.
The idea in using two OC functions in generating the waveform is as follows:
Use OC0 (or OC7) to pull the PT0 pin to high every 1500 clock cycles.
Use OC7 (or OC0) to pull the PT0 to low after it is high for 600 clock cycles.
×
Search WWH ::




Custom Search