Abstract:
A system and method generate a pulse width modulated signal having variable duty cycle resolution. A hardware uses minimal hardware to improve the PWM duty cycle resolution up to 0, such that highest possible resolution of a waveform can be obtained, including a sine wave. An embodiment of the invention uses a microcontroller, a divide by W counter, a delay circuit, a flip-flop, and a logic gate.

Description:
PRIORITY CLAIM 
   This application claims priority from Indian patent application No. 2280/Del/2005, filed Aug. 25, 2006, which is incorporated herein by reference. 
   TECHNICAL FIELD 
   The instant invention relates to a system and method for generating a pulse width modulated signal having variable duty cycle resolution. 
   BACKGROUND 
   Pulse width modulation (PWM) is a commonly used technique for generating precisely timed, repetitive digital waveforms. Resolution of a PWM waveform plays an important role in the quality of output generated. The granularity or resolution of the device output state depends upon the resolution of the PWM output used to control the device. For a given range of output states, higher resolution in the PWM translates into higher resolution of the device being controlled thereby. Resolution enhancements have typically relied upon hardware alterations on the controller side to provide for more PWM states at the output. However, such hardware based approaches are typically fraught with significant cost penalties and use of non-standardized components. 
   General-purpose microcontrollers are used for generation of Pulse Width Modulation (PWM) waveforms for different applications. Sine wave generation is one of the most useful applications where the PWM function of timers can be used. Sine wave resolution can be improved by improving PWM duty cycle resolution. One of most useful applications is Uninterruptible Power Supplies (UPSs) where sine wave resolution is important. Also in some applications if AC Mains frequency changes to a large extent, it may cause temporary or permanent damage to the operating device. During the change in AC Mains frequency, it is necessary to track the same. 
   While any variety of digital waveforms can be generated by periodically writing to the various ports of digital ICs, using timer output capture and the like, these all require direct CPU time for each output pulse. A great advantage of PWM is that once the registers are set up and enabled, the PWM waveforms are generated without any CPU overhead, so valuable CPU time can be utilized for other tasks. 
   However there are certain drawbacks to the same. Resolution of the pulse width modulated signal, which must be significantly higher than the input frequency, typically does not approach that of the input itself. A further problem that reduces available PWM accuracy and resolution is associated with timer interrupt latency inherent in current microprocessor-based control schemes. That is, transitions of the pulse width modulated signal from high to low and low to high are handled by a pulse width timer interrupt routine in software. Depending upon the instructions being executed when a pulse width timer interrupt occurs, four to seven microseconds can elapse before the software interrupt routine is executed. There is thus a quasi-random timing error of up to three microseconds, which can be viewed as noise on the PWM signal that adversely affects system performance, particularly in high response systems. 
   U.S. Pat. No. 5,023,535 entitled “HIGH RESOLUTION PULSE WIDTH MODULATION” provides a high-resolution pulse width modulation waveform using software, but the change in high time of pulse width modulated waveform is in multiple (s) of a microprocessor/microcontroller clock period. 
   A system that addresses the foregoing problems in the art and provide resolution up to a fraction of the time period of Central Processing Unit (T CPU ) is required. 
   SUMMARY 
   One aspect of the present invention makes use of only minimal hardware and thus provide a very cost effective solution. No computation algorithm required, which makes this technique efficient without any software overhead; 
   One aspect of the invention is to provide a system and method with improved resolution of the pulse width modulated signal. 
   Yet another aspect of the invention is to provide a PWM waveform whose resolution can be a fraction of T CPU  according to the application requirement. 
   According to one aspect of the invention, a system for generating a Pulse Width Modulated signal having variable duty cycle resolution comprises a microcontroller for generating a master clock output; a divide by W counter having its input connected to said master clock output of said microcontroller providing a divided clock output; a delay circuit having its input connected to the output of said divide by W counter for introducing a delay in said divided clock output; a flip flop having its data input connected to a second output of said microcontroller and its clock being connected to the output of said delay circuit for shifting said second output of said microcontroller; and a logic gate receiving the outputs of said flip flop and said second output of said microcontroller for providing an improved resolution PWM waveform. 
   The delay circuit may include a multiplier block that feeds back the signal M number of times to introduce the desired delay. The system provides a PWM waveform with resolution up to a fraction of the time period of a clock during Central Processing Unit (T CPU ). The flip-flop may be a D-flip-flop. The logic gate may be an OR gate. The second signal on the second output may be a pulse width modulated signal. 
   A method for generating a Pulse Width Modulated signal having variable duty cycle resolution includes the steps of generating a master clock output; providing a divided master clock output; delaying said divided master clock output; shifting a pulse width modulated signal using said delayed signal as clock; and performing a logic operation on said pulse width modulated signal and shifted pulse width modulated signal to obtain an improved resolution PWM waveform. 
   The method can provide a PWM waveform with resolution up to a fraction of the time period of Central Processing Unit (T CPU ). 
   The logic operation may be an OR operation. 

   
     BRIEF DESCRIPTION OF THE DRAWINGS 
     The invention will now be described with reference to the accompanying drawings. 
       FIG. 1  relates to the block diagram of a PWM system in accordance with the instant invention. 
       FIG. 2  illustrates the waveforms of PWM in accordance with the instant invention. 
       FIG. 3  shows the flowchart of the steps of the method in accordance with the invention. 
   

   DETAILED DESCRIPTION 
   The following discussion is presented to enable a person skilled in the art to make and use the invention. Various modifications to the embodiments will be readily apparent to those skilled in the art, and the generic principles herein may be applied to other embodiments and applications without departing from the spirit and scope of the present invention. Thus, the present invention is not intended to be limited to the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein. 
   Resolution of a PWM output is the granularity with which the duty cycle can be modulated. The PWM duty cycle resolution determines the amount of precision with which the duty cycle can be changed. For example, a 10-bit resolution allows 1024 possible values for the duty cycle where an 8-bit resolution only allows 256 values. The PWM duty cycle resolution is defined as:
 
Resolution=1/number of divisions available in one PWM cycle
 
   If an X-bit Auto Reload Timer (ART) is used, the resolution of PWM without using the novel apparatus will be:
 
Resolution=1/(2 x −Auto-Reload Value)
 
where X represents the number of bits.
 
   It will be seen by the foregoing description that by using this invention, if a delay is δ(t), and F COUNTER =F CPU /W and T CPU =N*δ(t), the resolution will be
 
Resolution=1/((2 X −Auto-Reload Value)* W*N )
 
where F COUNTER  is the frequency of the divide by W counter, F CPU  is the frequency of the microcontroller, W is the count of the divide by W counter, T CPU  is the time period of the microcontroller clock and, N is the ratio of time period of CPU to the total delay.
 
   If δ(t) approaches 0, N will approach infinity and resolution will also approach zero. But using the present invention, the change in a high time of a pulse width modulated waveform is in multiples of δ(t), where δ(t) is the delay provided by the delay circuit, which may be tending to 0. Thus, by using this invention, one can get continuous change in high time of a pulse width modulated waveform. Thus, the resolution is ideally improved to its highest value, which is 0. 
     FIG. 1  is a block diagram of one embodiment of the present invention. It consists of a microcontroller  1 , the outputs of which are connected to the inputs of a divide by W counter  2 , a flip-flop  5  and feedback path  4  of delay circuit respectively. The output of the divide by W counter  2  is connected to a delay circuit  3 , which in turn is connected to a flip-flop  5 . The output of the flip-flop  5  is further connected to one of the inputs of an OR gate  6  while the other input of OR gate  6  is connected to one of the outputs of the microcontroller  1 . 
   A common power supply of 5V can be used for driving all the external components as well as the microcontroller  1 . The microcontroller  1  produces a Master Clock Out (MCO) signal and a Pulse Width Modulator (PWM) out signal which are synchronized at the edges. Further, the microcontroller  1  generates a control signal for controlling the delay in MCO out signal depending upon user application. This control signal manages the delay produced in the delay circuit  3  according to a user application. 
   The value of W in the divide by W counter  2  is a fixed value for a particular configuration of microcontroller  1  and the delay circuit  3 . A low frequency output signal X of the divide by W counter  2  is delayed M times by the delay circuit  3  and fed to the clock input of the flip-flop  5 . The flip-flop  5  outputs a signal B that is a shifted PWM signal A. The OR gate  6  performs an OR operation on the shifted PWM signal B and the normal PWM out signal A and provides the PWM out signal with a changed duty cycle by M*δ(t)/T PWM . If M varies from 1 to N*W, the improvement in resolution will be N*W times. It means:
 
 T   COUNTER   =T   X   =N   1 *δ( t ) where N1= N*W  
 
 T   CPU   =N *δ( t )
 
   An embodiment of the invention will now be described using an 8-bit PWMART timer for PWM duty cycle resolution computation. However, the invention is not restricted to the same. The parameters in case of an 8-bit PWMART timer are as follows: 
   f CPU  is 8 MHz f COUNTER  is 4 MHz Auto-Reload value is 00h, duty cycle register value is 80h, the value of N is 8 and resolution will be Resolution=1/( 2 N−Auto-Reload Value)=1/256. 
   According to the aforesaid values W=f CPU /f COUNTER =2. 
   If δ(t) is 10 ns, N=T CPU /δ(t)=12.5. T COUNTER  is divided into W*N=2*12.5=25 parts, so, the resolution improved is 25 times. The improvement in resolution directly depends on W and N. 
   An embodiment of the invention will now be explained using the waveforms with reference to  FIG. 2 . For the purpose of explaining the waveforms, the value of M is taken as 1. The microcontroller  1  provides the Master Clock Out (MCO) signal and Pulse Width Modulator (PWM) out signal A which are synchronized at the edge of PWM out signal A. The signal X obtained from divide by W counter  2  is a reduced frequency signal as compared to the MCO signal having its rising edge synchronized with the edge of the MCO signal. The signal X is delayed by the delay circuit  3  to provide an output signal Y that acts as the clock of the flip-flop  5 . The flip-flop  5  produces the output signal B that is shifted input signal A. The OR gate  6  in turn performs an OR operation on the two signals, namely A &amp; B to, provide the final output. 
     FIG. 3  shows a flowchart in accordance with one embodiment of the invention. The microcontroller generates a PWM pulse signal (A) whose resolution is to be improved and also generates an MCO signal  30 . The MCO signal (Fcpu) is passed through the divide by W counter to obtain the divided output signal X  31 . The output signal X is passed to the delay circuit, which is controllable by microcontroller user application, to get, delayed Fcpu/W  32 . This delayed signal represented by Y is used as a clock in the D flip-flop  5  to get the shifted PWM signal (B)  33 . The signals A and B are ORed to get the desired signal with improved PWM resolution  34 . 
   Embodiments of the present invention can be utilized in a variety of different types of electronic systems, such as for the generation of sinusoidal signals in a UPS or other type of system, or to generate a PWM signal for use in other applications as well. 
   From the foregoing it will be appreciated that, although specific embodiments of the invention have been described herein for purposes of illustration, various modifications may be made without deviating from the spirit and scope of the invention.