EDN logo


Design Ideas: March 17, 1994

Circuit measures software-execution time

Yongping Xia,
EBT Inc, Torrance, CA


Figure 1Especially helpful for developing real-time application programs, the circuit in Fig 1 plugs into a PC printer port and measures the execution time of a piece of software. The CD4536 is a 16/24-bit binary counter with a built-in oscillator. This counter has an 8-bit prescaler, which the chip bypasses if the 8_BY pin is high. When this is the case, the CD4536 is a 16-bit counter, and its A through D inputs select which bit is connected to output DO. If the 8_BY pin is low, the CD4536 is a 24-bit counter and the inputs select which 9 to 24 bits connect to output DO. Setting the R pin high clears the counter, and setting CINH high inhibits the counter. With the components values shown in the figure, the oscillation frequency is around 100 kHz. The printer port can directly power the CD4536 because it needs only several milliamps.

A PC printer port has an 8-bit output port. As Fig 1shows, D0 to D3 select the counter's output bit, D4 disables the counter, D5 sets the bypass function, D6 resets the counter, and D7 powers the chip. The printer port uses input pin 11 to read the selected bit off the counter.

Listing 1's C program controls the test. First, the program finds the PC's printer port address. This address is its output-port address, and address+1 is the input-port address. After clearing the counter and enabling the clock, the program lets the counter free-run for 1 msec and then reads the counter bit-by-bit. The resultant number indicates how many clock cycles occur during 1 msec and determines the oscillation frequency. Next, the program sets the CD4536 to be a 24-bit counter, clears the counter, starts the clock, runs the test procedure, and stops the clock. If the reading is too small, the program sets the CD4536 to a 16-bit counter and reruns the test. Based on the known clock frequency and counter number, calculating the execution time of the tested procedure is easy. Since the maximum counter number and clock are 24 bits and 10 µsec, respectively, the maximum execution time this circuit can measure is 160 seconds. EDN BBS /DI SIG #1388





| EDN Access | feedback | subscribe to EDN! |
| design features | design ideas |


Copyright © 1995 EDN Magazine. EDN is a registered trademark of Reed Properties Inc, used under license.