Generate frequencies with arbitrary relationships
Sanjay Gupta, NIIT Ltd, New Delhi, India -- EDN, 3/16/2000
The circuit in Figure 1 and the program in Listing 1 use an Atmel 89C2051 µC to generate a variety of frequencies that have no specific relationship to each other. The example given here generates the following eight frequencies: 500, 700, 1000, 1050, 1100, 1500, 1700, and 2000 Hz. The program delivers these frequencies on eight I/O pins (P17 to P10, respectively) of the µC. The program associates each of these I/O pins with an internal-RAM address (f1 through f8).The interrupt routine in Listing 1 takes 492 oscillator periods to complete. At 24 MHz, this interval corresponds to 20.5 µsec. The internal timer T0 of the µC generates an interrupt every 25 µsec. During each interrupt cycle, each of the counts (f1 through f8) decrements by one. Whichever count decreases to zero, the corresponding output pin toggles and that count value reinitializes. Average accuracy improves as the magnitude of the required output frequency decreases (Table 1). You can also obtain more accuracy by using the following techniques:
- Increase the processor-clock frequency, thereby reducing the time it takes to execute the interrupt routine.
- Reduce the number of clock cycles in the interrupt routine.
If you need to generate fewer frequencies, for example, the last six from the preceding list, then the time taken to complete the interrupt cycle reduces to 372 cycles (15.5 µsec). So you can program timer T0 to generate an interrupt every 18 µsec instead of 25 µsec. Table 2 shows the new accuracy figures with fewer frequencies. Click here to download Listing 1. (DI #2500).
















