Gadfly Synchronization (Microcontrollers)

11.5

In the gadfly synchronization technique,

the program continually “asks” one or more devices what they are doing (such as by continually testing the timer flag bit). This technique is named after the great philosopher, Socrates, who, in the Socratic method of teaching, kept asking the same question until he got the answer he wanted. Socrates was called the “gadfly of Athens” because he kept pestering the local politicians like a pesky little fly until they gave him the answer he wanted (regrettably, they also gave him some poison to drink). This bothering is usually implemented in a loop, called a gadfly loop. in which the microcomputer continually inputs the device state of one or more I/O systems until it detects DONE or an error condition in one of the systems. Gadfly synchronization is often called polled synchronization. However, polling means sampling different people with the same question —not bothering the same person with the same question. Polling is used in interrupt handlers discussed in the next section; in this text, we distinguish between a polling sequence and a gadfly loop.
A gadfly loop is illustrated by the flow charts shown in Figure 11.6b. The processor keeps testing a status port, which is set by the device when it is done with the request for the input, after which data can be read from the input port.
tmp4D-61_thumb[1]tmp4D-62_thumb[1]
You can stop this program after it has counted the pulses and examine accumulator D.
Status Port
Figure 11.8. Status Port
We next illustrate the use of gadfly synchronization by implementing a variation of a traffic light controller, as it was described in Section 11.3. But each time another vector element is to be output, a switch is closed and PORTT bit 0 sees a falling edge. See Figure 11.8. Moving the switch to the bottom contact causes exactly one falling edge. The capacitor holds the voltage on the port input bit when the switch is in between the top and bottom contact. To output the vector, execute the C procedure:
tmp7D-2_thumb[1]


The gadfly loop waits until a hardware-generated edge occurs,

while the delay loop waits a prescribed number of instruction executions. In general, delay loops do not require as much hardware as gadfly loops, because a gadfly loop needs a status bit in hardware and a means to set it. However, gadfly synchonization can wait exactly as long as an I/O device needs, when hardware causes the edge to occur, while a delay loop is generally timed to provide a delay that is the worst-case delay needed for the device.

Next post:

Previous post: