Page 125 - Embedded Microprocessor Systems Real World Design
P. 125

tents of Data Out into the “D” flip-flop. Only DO  is used to transfer data; the other
                 bits are unused.
                   After writing a bit  to the device, the  CPU must read  the contents of  the flip
                 flop to avoid losing that bit. After all the bits are transferred, the chip select signal
                 is  driven  high  to  terminate  the  cycle. Note  that  reading  the  data bit  from  the
                 flip-flop does not generate  a clock to the Microwire device; only write cycles do
                 that.
                   If you don’t want to read the data after each bit is written, you could replace the
                 “D” flip-flop with a shift register and read the entire register when the entire data
                 stream has been written. The length of the shift register must be the same as the
                 number of bits to be written/read  from the device.
                   If you are writing to a device that is write-only, you would not need the “D” flip-
                 flop or the tristate buffer. Although this approach still requires that the CPU do
                 bit-by-bit transfers, it is somewhat faster than requiring the CPU to generate each
                 signal transition as would be required in a port-bit implementation.





                 Timer Basics


                 Timers are a crucial part of many embedded systems. Figure 3.5A shows a simple
                 timer like you might find in a microcontroller. This timer consists of a simple, load-
                 able %bit counter. You  could build  this from  a couple  of  74HC161  counters or
                 equivalent PLD logic.
                   The microprocessor can write  a value  to  the  timer  that  is transferred  to  the
                 counter outputs. If the counter is an UP counter (as shown), it counts up. A DOWN
                 counter counts down. A typical timer embedded in a microcontroller or in a timer
                 IC will have some means to start the timer once it is loaded, typically by  setting a
                 bit in a register. The clock input to the counter may be a derivative of the micro-
                 processor clock or it may be a signal applied to one of the external pins. A real
                 timer will also provide the outputs of the counter to the microprocessor so it can
                 read the count, but for simplicity that has been left off Figure 3.5A.
                   If  the microprocessor loads this timer with a value of OxFE  and then starts the
                 timer, it will  count from FE  to FF on the next clock. On the second clock, it will
                 count from FF to 00 and generate an output. The output of the timer may  set a
                 flip-flop that the microprocessor can read, or it may generate an interrupt to the
                 microprocessor, or both. The timer may stop once it has generated an output, or
                 it may  continue  counting from 00 back  to FF. The problem with  a continuously
                 running timer is that it will count from the loaded value the first time it counts up,
                 but the second time it will start from 00.



                 Hardware Design 2                                                    107
   120   121   122   123   124   125   126   127   128   129   130