Page 184 - Programming Microcontrollers in C
P. 184

Timers    169

                          At the close of this period, the initialization of the part is complete,
                          and the TCR is again reset to zero prior to execution of the code
                          identified by the reset vector. Whenever the RESET line is asserted,
                          the TOF will be loaded with zeros.
                              Any program can read the TCR, so it is possible to generate asyn­
                          chronous time events faster than the TOF or the RTIF would indicate.
                              When the processor enters the WAIT mode after execution of a
                          WAIT instruction, the CPU clock halts, but the timer clock continues
                          to execute. If the interrupts are not masked, a timer interrupt, an exter­
                          nal interrupt or a reset will cause the device to exit the WAIT mode.

                              Table 4-3: RTI And COP Rates for F  = 4.0 MHz
                                                               xtal
                              RT1           RT0            RTI Rate        Minimum
                                                                         COP Reset
                              0             0                8.2 ms         57.3 ms
                              0             1               16.4 ms        114.7 ms
                              1             0               32.8 ms        229.4 ms
                              1             1               65.5 ms        458.8 ms
                              If a STOP instruction is executed, the timer clock is halted along
                          with the CPU clock. The STOP mode is exited when an external
                          interrupt occurs or the RESET line is asserted. In this case, the part
                          performs as described above.
                              Most microcontrollers are placed in operation with no operator to
                          intervene in the event of a problem. A COP timer will provide one
                          means of recovering if the operation of the microcontroller gets lost.
                          “Gets lost”? The situation that can cause a microcontroller to get lost
                          is usually some type of voltage spike or glitch in the power supply
                          operation. The program counter usually ends up with a value outside
                          of the program, and no one knows what will happen. The COP is sim­
                          ply a timer that counts for a specified amount of time. If the COP timer
                          has not been reset before the specified time elapse, the COP timer
                          overflow causes an internal reset of the microcontroller. If the cause of
                          the problem is a drop in power or other error, in most instances forcing
                          a reset will bring the microcontroller back into normal operation.
                              The COP control register is located at address 0x7f0 in the
                          M68HC05J1. To service the COP from the program, the program
                          must merely write a zero to bit 0 of this address to reset the COP
                          portion of the timer system.
   179   180   181   182   183   184   185   186   187   188   189