design background:
Breathing lights are widely used in mobile phones and have become one of the selling points for the new brands of mobile phones. If the phone there are unprocessed notifications, such as missed calls, text messages, and so did not check, breathing light will be completed gradually changed from light to dark under control, I feel like people breathe, play a notification The role of reminders.
Â
Design principle : Â
The theory of breathing lamp design is mainly PWM knowledge. PWM ( Pluse Width Modulation ) Pulse Width Modulation is a method of digitally encoding an analog signal level. Through the use of a high resolution counter, the duty cycle of the square wave is modulated to encode the level of a particular analog signal. It is widely used in many fields such as measurement, communication, power control and conversion, and LED lighting. As the name suggests, it is a signal with an adjustable duty cycle. What is the duty cycle?
The duty cycle ( Duty Cycle or Duty Ratio ) can be interpreted as the ratio of the duration of a positive pulse sequence to the total pulse period in a pulse sequence (square wave). It can also be understood as the ratio of the effective time of release of energy by the circuit to the total release time.
How does PWM achieve dimming? To adjust the brightness variation of the LED , it is actually to regulate the current flowing through the LED . When the current increases, the brightness of the LED increases and vice versa. However, since the current is an analog signal, PWM is used at this time . As shown in the figure below:
Instead of a sine wave, a series of pulses of unequal amplitude is used. The width of the pulse varies according to the amplitude of the sine wave a . The amplitude is high and the pulse width is the opposite. Â Â Â
The PWM modulation frequency required for most loads is higher than 10Hz . To achieve the effect of a breathing lamp , the modulation frequency must be increased . Usually the modulation frequency is between 1Khz and 200Khz . In the LED control, the PWM acts on the power supply. The pulse width modulation pulse frequency is usually greater than 100Hz , and the human eye will not feel flicker. Here we take the PWM modulation frequency of 1KHz and the PWM period is 1ms .
When the pulse frequency is constant, the greater the duty cycle of the output pulse, the higher the effective level of the output, and the brightness of the LED will be different depending on the duty cycle . If the duty cycle is 0 , then the LED does not light, when it is 100% , the LED is the most. We let the duty cycle change from 0 to 100% , and then change from 100% to 0 , then we can realize the breathing lamp. effect.
The design of a respiratory cycle of the lamp for 2s, the duty cycle divided by "suction" and the duty Save "call" modes, each of 1s, a PWM cycle of 2 ms, so that each pattern contains 1000 The PWM cycle divides each PWM cycle into 1000 copies, which is 2 us per time period .
Â
Design architecture diagram :
Clock 50M
Design code :
Design module
0 Â Â Module huxi_led_state ( clk , led , rst_n );
1 Â Â Input clk ;
2 Â Â Input rst_n ;
3 Â Â
4   Output  Reg led ;
5 Â Â
6 Â Â Parameter T = Â 100_000 ;
7 Â Â
8 Â Â Localparam s0 = Â 1'b0 ;
9 Â Â Localparam s1 = Â 1'b1 ;
10 Â
11  Reg  [ 25 : 0 ] lw ;
12  Reg  [ 25 : 0 ] hw ;
13 Â
14  Reg  [ 16 : 0 ] count ;
15 Â
16 Â // Generate 2MS pulses
17  Always  @( posedge clk or  negedge rst_n)
18 Â If (! rst_n )
19 Â Begin
20 Â Count <= Â 1'b0 ;
twenty one  End
twenty two  Else
twenty three  Begin
twenty four  If ( count == T -  1 )
25 Â Begin
26 Â Count <= Â 1'b0 ;
27 Â End
28 Â Else
29 Â Begin
30 Â Count <= count + Â 1'b1 ;
31 Â End
32 Â End
33 Â
34 Â wire flag;
35 Â Assign flag =( count == T - Â 1 ) Â ? Â 1'b1 : 1'b0 ;
36 Â
37 Â Reg state ;
38 Â
39 Â // Generate PWM waves by adding or subtracting high and low levels in one cycle
40  Always  @( posedge clk or  negedge rst_n)
41 Â If (! rst_n )
42 Â Begin
43 Â Lw <= T - Â 100 ;
44 Â Hw <= Â 100 ;
45 Â State <= Â 1'b0 ;
46 Â End
47 Â Else
48 Â Begin
49  Case  ( state )
50 Â S0 : begin
51 Â If ( flag && Â ( lw > Â 100 )) Â Â Â // Judge the low time
52 Â Begin
53 Â Lw <= lw - Â 100 ;
54 Â Hw <= hw + Â 100 ;
55 Â State <= s0 ;
56 Â End
57  Else  If ( flag &&  ( lw ==  100 ))
58 Â Begin
59 Â Hw <= hw - Â 100 ;
60 Â Lw <= lw + Â 100 ;
61 Â State <= s1 ;
62 Â End
63 Â Else
64 Â Begin
65 Â Hw <= hw ;
66 Â Lw <= lw ;
67 Â State <= s0 ;
68 Â End
69 Â End
70 Â S1 : begin
71 Â If ( flag && Â ( hw > Â 100 )) Â Â Â // Judge the high time
72 Â Begin
73 Â Hw <= hw - Â 100 ;
74 Â Lw <= lw + Â 100 ;
75 Â State <= s1 ;
76 Â End
77  Else  If ( flag &&  ( hw == Multimedia Wiring Harness
The multimedia wiring harness apply to Audio,Video,Radio, LVDs,Flat RCA,USB.
Yacenter has experienced QC to check the products in each process, from developing samples to bulk, to make sure the best quality of goods. Timely communication with customers is so important during our cooperation.
If you can't find the exact product you need in the pictures,please don't go away.Just contact me freely or send your sample and drawing to us.We will reply you as soon as possible.
Electric Fan Wiring Kit,Socket Fan Wiring Harness,Custom Pc Wiring Harness,Multimedia Wiring Harness
Dongguan YAC Electric Co,. LTD. , https://www.yacentercns.com