Background
Currently, LED (light emitting diode) driving technology is mainly PWM (Pulse Width Modulation) mode with constant current amplitude. The gray data for adjusting the brightness of the LEDs is used for generating corresponding PWM duty ratios to adjust the brightness of the LEDs. The PWM regulation mode of the constant current amplitude has the advantages of high gray scale regulation precision and high regulation speed, and is widely applied to LED brightness regulation occasions. The PWM regulation of constant current amplitude has a significant disadvantage in that the LEDs are lit for long periods of time and dark for long periods of time. And when the brightness of the LED is reduced more, the dark time ratio of the LED is larger, the bright time ratio is smaller, and the problems of photographing distortion, flickering and the like are caused.
This problem is then ameliorated by breaking up one PWM period into multiple PWM periods and increasing the PWM frequency. As shown in patent ZL200610001583.5, a typical method divides a high-tone resolution luminance control signal into a primary light-emitting period and a secondary light-emitting period, the primary light-emitting period is divided into a plurality of small periods on average, and the secondary light-emitting period is divided and uniformly dispersed into the plurality of small periods. As shown in fig. 1, a 4-bit PWM, which has a gray scale data of 9 (binary 1001), a high level of 9 clock widths, and a low level of 7 clock widths, has the disadvantage of long-time bright and long-time dark, and the technique adopts an average division of the 4-bit PWM into 4 equal divisions, the gray scale data of 9 divided by 4 is equal to more than 2 and 1, the primary lighting period is 4 pieces of 2, i.e., 8, and the secondary lighting period is the remainder 1. The main lighting period is divided into 4 small periods, each period is lighted for 2 clock periods, and the lighting period is turned off for 2 clock periods. The secondary light emission period 1 is dispersed into 4 small periods, which are dispersed to the beginning of the 2 nd pulse as shown in fig. 1. Thus, the pulse output with 4 times of PWM frequency is obtained, and the display of the LED is more uniform. However, this approach has the disadvantage that each small period does not accurately represent the actual brightness of the LED, e.g., the original brightness of the LED is 9/16, and the brightness becomes 2/4, 3/4, 2/4, and 2/4 of the average of the 4 brightnesses after adjustment by the proprietary method. It is known that there is a fluctuation in the average current of the LED that increases and decreases. There is still some image distortion problem for photographing and video recording. And the more the LED frequency is increased, the larger the number of secondary lighting periods is, the more obvious the LED current fluctuation is, and the more serious the image distortion caused by shooting is. If the 4bit PWM gray scale number is 7, the PWM frequency is increased by 8 times, 8 small periods exist, and the gray scale number is only 7, the situation that 1 PWM small period is not bright can occur, the brightness of the LED is changed from bright 1/2 to off, then is changed to bright 1/2, the current fluctuation of the LED is large, and the problems of distortion are easy to occur in photographing and video recording. It is known that the technique is still deficient and that the higher the PWM frequency is, the more significant the deficiency of the technique is.
Disclosure of Invention
Aiming at the problems in the prior art, the invention provides an LED dimming method, which realizes mixed dimming by combining two dimming modes of PWM dimming and LED current amplitude dimming, so that the brightness of each PWM period LED is the same, the brightness reflects the real brightness, and the PWM frequency can be increased arbitrarily.
In order to achieve the above purpose, the technical scheme adopted by the invention is as follows:
a method of dimming an LED comprising the steps of:
s10, acquiring input m-bit wide gray data a and n-bit wide duty ratio data d0, wherein the m-bit wide gray data a is used for controlling the amplitude of pulse current, and the n-bit wide duty ratio data d0 is used for setting the frequency and duty ratio output of PWM pulses in cooperation with clock frequency;
s20, continuously detecting whether the input duty ratio data d0 changes, if not, maintaining PWM pulses with the same duty ratio, and controlling an m-bit current source to output corresponding pulse current amplitude according to the gray data a with m-bit width;
if yes, the duty ratio of the PWM pulse is matched and adjusted in real time according to the variable duty ratio data d1, meanwhile, the gray data a with m bit width is adjusted into gray data a1 with m bit width through operation, an operation formula is a1=ad0/d 1, a1 is an integer, the remainder is b, then the m-bit current source is controlled to output corresponding pulse current amplitude according to the gray data a1 with m bit width, and the remainder is partially overlapped on the pulse current amplitude.
Specifically, the frequency of the PWM pulse is 2 of the set clock frequencyn One-half of the total weight of the product.
Specifically, the maximum display brightness of the LED is 2m *I*d0/2n Wherein I represents a unit current, and the current brightness of the LED is a.I.d 0/2(m+n) 。
Specifically, the method for superposing the remainder part on the pulse current amplitude comprises the following steps:
the duty data d1 is counted down by 1, and when the count value is equal to the remainder b, the m-bit wide gradation data a1 is incremented by 1 until the pulse ends.
Alternatively, the m-bit wide gradation data a1 is added by 1, then the remainder b is decremented by 1, and the m-bit wide gradation data is restored to the a1 value and outputted after the count is 0.
Further, when the duty ratio data is unchanged and the gray data is changed, judging whether the gray data value is smaller than a set value, if yes, actively lowering the duty ratio data to improve a new gray data value and improve pulse current amplitude output.
Another object of the present invention is to provide an LED dimming device, comprising:
the judging unit is used for receiving the input n-bit duty cycle data d0 and judging whether the n-bit duty cycle data d0 changes or not in real time;
the pulse output unit is used for receiving the n-bit duty ratio data transmitted in real time by the judging unit, forming PWM pulses with corresponding frequency and duty ratio by combining the clock frequency set by the clock unit, and outputting the PWM pulses to the constant current switch to control the on and off of the constant current switch;
a gray level operation unit for receiving the input m-bit gray level data a and performing operation a1=a×d0/d1 when the n-bit duty ratio data is changed to d1, so as to obtain new integer m-bit gray level data a1 and remainder b; and
and the gray control unit is used for controlling the corresponding m-bit current source switch to adjust the pulse current amplitude by outputting the received input m-bit gray data a when the n-bit duty ratio data is unchanged, controlling the corresponding m-bit current source switch to adjust the pulse current amplitude according to the m-bit gray data a1 output obtained by the gray operation unit when the n-bit duty ratio data is changed, and superposing the pulse current amplitude according to the remainder obtained by the gray operation unit.
Compared with the prior art, the invention has the following beneficial effects:
the invention adjusts the brightness of the LEDs by utilizing the gray data of the LEDs through a mixed PWM mode of adjusting the amplitude of PWM pulse current and adjusting the duty ratio, has the advantages that the average current of the LEDs in each PWM period is the same, the brightness of the LEDs in each PWM period is equal to the target brightness of the LEDs, can obtain more stable LED display effect, has stable average current and almost no fluctuation, can obtain the effect similar to a still picture when displaying an image picture, and can easily eliminate the water ripple phenomenon appearing in photographing and video recording. When the LED is displayed in low gray, the PWM frequency is ensured to be unchanged when the LED is displayed in low gray by reducing the duty ratio and the current amplitude, so that an excellent LED low gray display effect can be obtained. And the PWM frequency can be arbitrarily increased, and the problem of image distortion can not be generated in high-speed photographing and video recording.
Detailed Description
The invention will now be further described with reference to the accompanying drawings and examples, embodiments of which include, but are not limited to, the following examples.
As shown in fig. 2, the LED dimming method includes the steps of:
s10, acquiring input m-bit-wide gray data a and n-bit-wide duty ratio data d0, wherein the m-bit-wide gray data a is used for controlling the amplitude of pulse current, and the n-bit-wide duty ratio data d0 is used for setting the frequency and duty ratio output of PWM pulses in cooperation with clock frequency. Based on the two set values, the maximum display brightness of the LED is 2m *I*d0/2n Wherein I represents a unit current, and the current brightness of the LED is a.I.d 0/2(m+n) . The m-bit wide gray scale data corresponds to an m-bit current source in a circuit. The frequency of the PWM pulse is 2 of the set clock frequencyn One-half, i.e. the frequency of the PWM pulse is determined according to the n-bit wide duty cycle data and the set clock frequency, e.g. the 8-bit duty cycle data, the clock frequency is 2MHz, and the PWM pulse frequency is 7.8kHz. The duty cycle data d0 represents the size of the duty cycle, for example d0=200, and the corresponding duty cycle is 200/256.
S20, continuously detecting whether the input duty ratio data d0 changes;
if the duty ratio is not changed, maintaining PWM pulses with the same duty ratio, and controlling an m-bit current source to output corresponding pulse current amplitude to the LED according to the gray data a with m-bit width; the brightness of the LED is adjusted by adjusting the current amplitude in this way, and the duty ratio is kept unchanged.
If the duty ratio is changed, the duty ratio of the PWM pulse is matched and adjusted in real time according to the changed duty ratio data d1, meanwhile, the gray data a with m bit width is adjusted into the gray data a1 with m bit width through operation, the operation formula is a1=a×d0/d1, a1 is an integer, the remainder is b, then the m-bit current source is controlled to output corresponding pulse current amplitude according to the gray data a1 with m bit width, and the remainder is overlapped on the pulse current amplitude and is output to the LED lamp, so that the dimming of the LED is realized.
The method for superposing the remainder part on the pulse current amplitude value can be as follows: the duty data d1 is counted down by 1, and when the count value is equal to the remainder b, the m-bit wide gradation data a1 is incremented by 1 until the pulse ends. It may also be: and adding 1 to the gray data a1 with m-bit width, then carrying out 1-down counting on the remainder b, and restoring the gray data with m-bit width to the value of a1 after counting to 0 and outputting.
From the formula of operation a×d0/d1 of the gradation data, it is known that when the new duty ratio d1 is smaller than d0, the new gradation data a1 is larger than the original gradation data a. I.e. decreasing the duty cycle may increase the pulse current amplitude driving the LED. The duty ratio can be adjusted timely as required in the MPWM dimming process, for example, when the duty ratio data is unchanged and the gray data is changed, whether the gray data value is smaller than a set value is judged, if yes, the duty ratio data is actively adjusted to be low, so that a new gray data value is improved, and the pulse current amplitude output is improved. In addition, the duty ratio data can be set to change along with the change of the gray data in the MPWM dimming process, for example, the duty ratio of the gray data is increased, and the duty ratio of the gray data is decreased. And meanwhile, the corresponding new gray data output is adjusted according to the change of the duty ratio so as to ensure that the brightness of the LED corresponds to the gray data.
As shown in fig. 3, the present embodiment further provides an LED dimming device, which includes a judging unit, a pulse output unit, a gray level operation unit and a gray level control unit, wherein,
the judging unit is used for receiving the input n-bit duty cycle data d0 and judging whether the n-bit duty cycle data d0 changes or not in real time;
the pulse output unit is used for receiving the n-bit duty ratio data transmitted in real time by the judging unit, forming PWM pulses with corresponding frequency and duty ratio by combining the clock frequency set by the clock unit, and outputting the PWM pulses to the constant current switch to control the on and off of the constant current switch;
a gray level operation unit for receiving the input m-bit gray level data a and performing operation a1=a×d0/d1 when the n-bit duty ratio data is changed to d1, so as to obtain new integer m-bit gray level data a1 and remainder b;
and the gray control unit is used for controlling the corresponding m-bit current source switch to adjust the pulse current amplitude by outputting the received input m-bit gray data a when the n-bit duty ratio data is unchanged, controlling the corresponding m-bit current source switch to adjust the pulse current amplitude according to the m-bit gray data a1 output obtained by the gray operation unit when the n-bit duty ratio data is changed, and superposing the pulse current amplitude according to the remainder obtained by the gray operation unit.
Unlike the prior art gray data used to adjust the PWM duty cycle, the gray data of the present invention is mainly used to adjust the amplitude of the LED pulse current, but at the same time the gray data can also adjust the PWM duty cycle. In the present invention, the pulse output unit determines the pulse output of the PWM based on the output of the judging unit, and if the duty ratio data is not the duty ratio d0 set in the initialization, the PWM pulse duty ratio output is set based on the new duty ratio data d1. If the duty ratio data is the same as the duty ratio d0 at the time of initialization, the PWM pulse duty ratio output is set in accordance with d 0. If the duty ratio data is not changed and still is d0, the gray level operation unit does not work, the gray level control unit directly forwards the m-bit gray level data a to output, and the output controls the m-bit switch and controls the connection and disconnection of the current source with the multiplied increment. The pulse output unit outputs PWM pulses with corresponding duty ratio to control the on and off of the constant current switch. And the corresponding m-bit current source is output to the LED, so that the brightness control of the LED is realized. The LED can be dimmed in a manner that the duty cycle is not changed to directly adjust the size of the current source when the brightness of the LED is higher, and in a manner that the PWM duty cycle is reduced to increase the pulse current amplitude when the brightness of the LED is lower. Specifically, when the duty ratio needs to be adjusted, for example, when the external data updates the n-bit duty ratio data or the m-bit gray scale data is smaller than a certain value, the n-bit duty ratio data is modified to decrease the duty ratio. The judging unit detects that the duty ratio data is changed, the duty ratio data is changed to d1, and the pulse output unit starts counting and outputting PWM pulses with corresponding duty ratio by d1 in the next PWM period. Meanwhile, the gray level operation unit performs operation output on gray level data, the gray level data a is multiplied by the original duty ratio data d0, and then the gray level data a is divided by the new duty ratio data d1 through a divider. New gradation data a1 and remainder b are obtained, wherein remainder b is smaller than d1. The gray control unit receives the information of the duty ratio change, switches the m-bit gray data into new a1 data to be output, counts d1 at the same time, and adds 1 to the new gray data a1 to be output when the count is the same as the remainder. The same gray control unit outputs new m-bit gray data a1 or a1+1 to control m-bit switches, thereby controlling the disconnection and connection of m multiplied current sources. The pulse output unit outputs a new duty ratio pulse to control the on and off of the constant current switch, controls the current of the constant current source to be output to the LED lamp, and realizes the dimming of the LED.
The invention further specifically describes the implementation process of the LED dimming method by combining the PWM signal change condition through the following embodiment.
Example 1
As shown in fig. 4, the pwm_0 pulse waveform with a current amplitude of 8 and a duty cycle of 9/16 has an LED average current of 8×9/16=4.5×i. After the LED dimming method of the present invention is adopted, for example, the pwm_s1 output current amplitude is 9, the duty ratio of each PWM waveform is 2/4, and the average current of the LED is 9×2/4=4.5×i. The average current of the LEDs is the same, the brightness of the LEDs is the same, and the PWM frequency of the LEDs is 4 times of the original PWM frequency. If the PWM frequency needs to be increased, the PWM frequency can be increased to 8 times as shown in PWM_s2, one PWM period is formed every 2 clock periods, the PWM duty ratio is 50%, and the current amplitude is 9. The average LED current per cycle is considered 9*I/2=4.5×i. It will be appreciated that since the average current of the LEDs is the same for each PWM period, the brightness of the LEDs remains the same as long as the same duty cycle is maintained. The frequency of the PWM can be greatly increased, theoretically up to half the clock frequency. This is not achieved by the prior art.
Example 2
As shown in fig. 5, the duty cycle becomes large. For example, a PWM_s3 has a current amplitude of 9 x I, 2-bit duty cycle data of 2, and a period of 2-bit duty cycle PWM of 22 =4 clock cycles. Duty cycle data 2 illustrates a high level of 2 clock cycles. The average current of the LEDs is 9×i×2/4=4.5×i, and each period is the same. If the 2-bit duty cycle data is adjusted to 3, the high level pulse of the PWM is output for 3 clock cycles, and the frequency is unchanged. Meanwhile, the gray data is calculated by a x d0/d1 to obtain 9*2/3=6, namely the current amplitude of PWM is 6*I. The PWM after the duty ratio change is shown as PWM_s4, the current amplitude is lower, and the LED is turned on for a longer time.
Example 3
As shown in fig. 6, the duty cycle becomes smaller. For example, a pwm_s5, the current amplitude is 5×i, and the 2-bit duty cycle data is 3. Duty cycle data 3 illustrates the high level as 3 clock cycles. The average current of the LEDs is 5×3/4=15×i/4, and each cycle is the same. If the 2-bit duty cycle data is adjusted to 2, the high level pulse of the PWM is output for 2 clock cycles, and the frequency is unchanged. Meanwhile, the gray data is calculated by a x d0/d1 to obtain 5*3/2=7x1. The PWM after the duty ratio change is as shown in pwm_s6, the current amplitude is output 7*I first, meanwhile, the 2 of d1 is counted down by 1, when 1 clock period is reduced by 1, the remainder is 1, the current amplitude is output by adding 1, and the current value is output 8*I. And then continues until PWM is off, and so on. The average current of pwm_s6 is (7×2+1) ×i/4=15×i/4. The average current remains unchanged and the LED brightness remains unchanged.
Example 4
Another way of processing the remainder in the case where the duty ratio becomes smaller is shown in fig. 7. The current amplitude of pwm_s5 is still 5×i, and the 2-bit duty cycle data is 3. The average current of the LEDs is 5×3/4=15×i/4, and each cycle is the same. After 2-bit duty cycle data is adjusted to 2, the gray data is calculated by a×d0/d1 to obtain 5*3/2=7residual 1. As shown in pwm_s7, the current amplitude is output with current amplitude (7+1) i= 8*I after 1 is added, and the remainder 1 is counted down by 1, and when 1 clock period is reduced by 1, the current amplitude is equal to 0, the current amplitude is output after 1 is reduced, and the current value is output 7*I. And then continues until PWM is off, and so on. The average current of pwm_s7 is (8*2-1) I/4=15I/4. The average current remains unchanged and the LED brightness remains unchanged.
Through the arrangement, the LED dimming method can obtain a more stable LED display effect, the average current of the LED is stable and almost has no fluctuation, and an effect similar to a still picture can be obtained when an image picture is displayed, so that the water ripple phenomenon of photographing and video recording can be easily eliminated. When the LED is displayed in low gray, the PWM frequency is ensured to be unchanged when the LED is displayed in low gray by reducing the duty ratio and the current amplitude, so that an excellent LED low gray display effect can be obtained. And the PWM frequency can be arbitrarily increased, and the problem of image distortion can not be generated in high-speed photographing and video recording.
The above embodiments are only preferred embodiments of the present invention, and not intended to limit the scope of the present invention, but all changes made by adopting the design principle of the present invention and performing non-creative work on the basis thereof shall fall within the scope of the present invention.