1. Field of the Invention
The present invention relates to preventing buffer underrun and buffer overrun errors in a data processing system.
2. Description of the Prior Art
For synchronized data transmission systems in which a transmitter receives a continuous analog signal is converted into digital signals and transmits the digital signals to a receiver, it is important that the operating frequencies of the transmitter and the receiver be as closely matched as possible. Even a tiny bit of difference in the operating frequencies of the transmitter and the receiver can cause operating errors or losses of data.
Please refer to
The receiving side 30 receives the transmitted signals through an RF circuit 36, and a baseband circuit 34 demodulates the received signals and stores the demodulated signals in a reception FIFO 38. A digital-to-analog converter 39 converts the digital samples stored in the reception FIFO 38 into analog signals and accordingly outputs an analog signal. Another crystal 32 produces a working frequency of the receiving side 30. The crystal 32 is rated at a specific frequency “f” plus a margin of error “b”, thereby having a frequency of f+b ppm.
Unfortunately, the frequencies produced by the crystals 22 and 32 are always slightly different from each other. Although crystal 22 with a frequency of f+a ppm and crystal 32 with a frequency of f+b ppm are both rated at the same frequency f, both of the crystals 22 and 32 will be slightly off from these rated frequencies. If b>a, the frequency of the receiving side 30 will be faster than the frequency of the transmitting side 20. The end result of this is that over time the receiving side 30 will empty the reception FIFO 38 of samples faster than the transmitting side 20 can supply new samples, thus creating a buffer underrun situation. On the other hand, if b<a, the frequency of the receiving side 30 will be slower than the frequency of the transmitting side 20. This causes the receiving side 30 to be unable to process the samples stored in the reception FIFO 38 as quickly as the transmitting side 20 is able to supply new samples, thus creating a buffer overrun situation.
For situations in which the transmitting side 20 needs to be perfectly synchronized with the receiving side 30, any buffer underrun or buffer overrun problems will cause data to be lost or can cause interruptions in service. Therefore, it is highly important that the working frequencies of the transmitting side 20 and the receiving side 30 be matched as closely as possible.
It is therefore an objective of the claimed invention to provide a method for reducing the clock differential in a data processing system in order to solve the above-mentioned problems.
According to an exemplary embodiment of the claimed invention, a method of preventing buffer underrun and buffer overrun errors in a data processing system is disclosed. The method includes providing a reference frequency for the data processing system, storing data samples to be processed in a first in, first out (FIFO) register, detecting a level of the FIFO register for indicating how many data samples are stored in the FIFO register, dividing the reference frequency by a divisor for producing a working frequency having a lower frequency than the reference frequency, wherein the divisor is not equal to zero and the divisor is adjusted according to the level of the FIFO register, and processing the data samples stored in the FIFO register using the working frequency.
According to another exemplary embodiment of the claimed invention, a data processing system for preventing buffer underrun and buffer overrun errors is disclosed. The data processing system includes a crystal for providing a reference frequency for the data processing system, a first in, first out (FIFO) register for storing data samples to be processed, a level register for detecting a level of the FIFO register and indicating how many data samples are stored in the FIFO register, a frequency divider for dividing the reference frequency by a divisor for producing a working frequency having a lower frequency than the reference frequency, wherein the divisor is not equal to zero and the divisor is adjusted according to the level of the FIFO register indicated by the level register, and a processor for processing the data samples stored in the FIFO register using the working frequency.
It is an advantage of the claimed invention that the divisor used by the frequency divider to produce the working frequency is adjusted according to the level of the FIFO register. In this way, both buffer underrun and buffer overrun errors can be avoided by keeping the FIFO at an optimum level.
These and other objectives of the present invention will no doubt become obvious to those of ordinary skill in the art after reading the following detailed description of the preferred embodiment that is illustrated in the various figures and drawings.
Please refer to
A crystal 62 is used to provide an initial clock frequency, which is phase shifted by a phase-locked loop (PLL) 64 for providing a reference frequency Fr to a frequency divider 66. The frequency divider 66 divides the reference frequency Fr by a divisor x to produce a working frequency Fw. As an example, reference frequency Fr could be 12 MHz, the divisor could be 250, and the working frequency Fw could be 48 kHz. The divisor x is adjustable, as will be explained below, and the divisor x is preferably a whole number.
The working frequency Fw is provided to a core processor 68, which processes data samples stored in a FIFO register 72 by operating at the working frequency Fw. In order to determine how to adjust the value of the divisor x, a level register 70 is used to monitor the FIFO level and find out how many data samples are currently stored in the FIFO register 72.
If the level register 70 indicates that the number of data samples stored in the FIFO register 72 is greater than an upper threshold, then the frequency divider 66 decreases the value of the divisor x for producing a higher working frequency Fw. In this way, the core processor 68 can process the data samples stored in the FIFO register 72 more quickly and can accordingly decrease the number of data samples stored in the FIFO register 72. As a result, a buffer overrun situation is avoided.
Conversely, if the level register 70 indicates that the number of data samples stored in the FIFO register 72 is less than a lower threshold, then the frequency divider 66 increases the value of the divisor x for producing a lower working frequency Fw. In this way, the core processor 68 will process the data samples stored in the FIFO register 72 more slowly, which will gradually increase the number of data samples stored in the FIFO register 72. As a result, a buffer underrun situation is avoided.
The present invention method is summarized in
Step 100: Read the value stored in the level register 70 to determine how many data samples are stored in the FIFO register 72.
Step 102: Determine if the value stored in the level register 70 is greater than an upper threshold. If so, go to step 104. Otherwise, go to step 108.
Step 104: Decrease the value of the divisor x, thereby increasing the working frequency Fw.
Step 106: Wait a predetermined delay period before going back to step 100.
Step 108: Determine if the value stored in the level register 70 is less than a lower threshold. If so, go to step 112. Otherwise, go to step 110.
Step 110: Since the number of data samples stored in the FIFO register 72 is neither too great nor too few, the divisor x and the working frequency Fw are not adjusted. Go back to step 100.
Step 112: Increase the value of the divisor x, thereby decreasing the working frequency Fw.
Step 114: Wait a predetermined delay period before going back to step 100.
As shown above, the present invention provides a simple way of preventing buffer underrun and buffer overrun situations from occurring in a data processing system. The present invention is useful for applications in which a continuous stream of data is received and the transmitting side of a data transmission system should be closely synchronized with the receiving side. One example of this would be for a wireless speaker system, where sound outputted by the speakers is continuously received and should be perfectly synchronized with the transmitted audio source.
Those skilled in the art will readily observe that numerous modifications and alterations of the device and method may be made while retaining the teachings of the invention. Accordingly, the above disclosure should be construed as limited only by the metes and bounds of the appended claims.