PWM - Control the brightness of LED with buttons

Publisher:dong125612Latest update time:2018-05-07 Source: eefocusKeywords:PWM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I wrote a blog post about PWM a year ago, the link is as follows:


http://hi.baidu.com/do_sermon/item/ff523b0a8b9d3d173b53ee74


An oscilloscope is used in this paper to display waveforms with different duty cycles.


In fact, LED can also be used to show the changes in PWM parameters through brightness. The actual test shows a very good effect. However, when using PROTEUS for simulation experiments, we can only see severe flickering and basically no change in brightness.


Recently, it has been discovered that adding a large capacitor can reduce the flicker of the LED and make the brightness more stable. In this way, the brightness changes can be directly observed using PROTEUS software.


The circuit is shown in the figure below. The capacity of the large capacitor (C6) in the figure is 4700uF, which can be adjusted at will, and the actual circuit does not need it.

The duty cycle parameter in the figure is 10, and the LED (D1) is displayed in the "half-bright" state.


PWM - Control the brightness of LED with a button - Non-famous blogger - Electronic Information Corner



The C program was published last year, and can be found in the link above. It has been slightly modified as follows:


#include

unsigned char a, b;

sbit K1 = P3^2; //Define two keys to adjust the duty cycle

sbit K2 = P3^3;

//------------------------------------------------

void delay(unsigned int i)

{

    unsigned char j;

    while(i--) for(j = 0; j < 60; j++); 

}

//------------------------------------------------

void main()

{

    TMOD = 0x01; //T0 timing mode 1

    TH0 = (65536 - 500) / 256; //500us@12MHz

    TL0 = (65536 - 500) % 256;

    TR0 = 1;

    ET0 = 1;

    EA = 1;


    a = 0;

    b = 10;

    while(1) {

      if(!K1) {delay(20); if(!K1) {b++; if(b > 19) b = 19; while(!K1);}}

      if(!K2) {delay(20); if(!K2) {b--; if(b < 1) b = 1; while(!K2);}}

      //The above two lines are to check the key, delay debounce, modify the duty cycle, and wait for the key to be released, b = 1~19


      P0 = ((b / 10) << 4) + b % 10; //Display duty cycle level

    }

}

//------------------------------------------------

void time0() interrupt 1

{

    TL0 = (65536 - 493) % 256; //Compensation interrupt entry time

    TH0 = (65536 - 493) / 256; //500us@12MHz

    a--; //a = 1~20

    if(a == 0) {a = 20; P2 = 0;} //Period = 20*500us

    if(a <= b) P2 = 255; //output to oscilloscope

    P1 = ~P2; //Output to LED, low level light

}

//------------------------------------------------


In this program, the PWM cycle is shorter than last year's. Last year, it was designed to be 1s in response to the requests of netizens, which was a bit long and not very practical.

This time, we don't need external interrupts to input keystrokes, but use the key query method instead.


When the duty cycle is adjusted using the buttons, the LED can display different brightness. Several screenshots are as follows:


PWM - Control the brightness of LED with a button - Non-famous blogger - Electronic Information Corner


PWM - Control the brightness of LED with a button - Non-famous blogger - Electronic Information Corner


When the PWM parameters are slightly smaller, the brightness is somewhat insufficient, which can be compensated by appropriately reducing the resistance of some current limiting resistors.


The LED used to display PWM has intermittent current, so its current limiting resistor can be smaller than usual, around 100 ohms, which is an empirical data.


When making a physical circuit, you don't need a large capacitor, so you don't have to spend money to buy it, haha


Keywords:PWM Reference address:PWM - Control the brightness of LED with buttons

Previous article:PWM - breathing light
Next article:595 output drives the digital tube to flash

Recommended ReadingLatest update time:2024-11-16 14:41

The essential difference between three-in-one SMD and three-in-one SMD LED display
1.3-in-1 SMD refers to the synthesis of three red, green and blue light points encapsulated in the same light-emitting tube. Since they are encapsulated in the same light-emitting tube, they look like a point when viewed closely, and a line when separated. The price of 3-in-1 is high, and the best ones are
[Power Management]
Disadvantages and Problems of Electrolytic Capacitor-Free LED Light Engines
So far, there is no very strict and precise definition of "light engine", so many readers still don't know what a light engine is. Someone defines it as " LED light engine refers to an overall combination of LED package (assembly) or LED array (module), LED driver , and other brightness, thermal, mechanical and el
[Power Management]
Disadvantages and Problems of Electrolytic Capacitor-Free LED Light Engines
Anhui Dijing's efficient and high-precision Mini LED sealing device solution
At present, with the rapid development of Mini LED display technology, Mini LED display products have begun to be used in ultra-large-screen high-definition displays, such as monitoring and command, high-definition broadcasting, high-end cinemas, medical diagnosis, advertising display, conferences and exhibitions, off
[Mobile phone portable]
Anhui Dijing's efficient and high-precision Mini LED sealing device solution
Convert a Buck Regulator into a Smart Dimmable LED Driver
LEDs are expected to transform the lighting industry with their long life and low power consumption, but a major barrier to their rapid adoption is the high cost of the LEDs themselves. The cost of LED luminaires (complete electric lighting equipment) varies, but LEDs typically account for about 25% to 40% of the tota
[Power Management]
Convert a Buck Regulator into a Smart Dimmable LED Driver
STM32 realizes arbitrary angle phase-shifted full-bridge PWM
MCU:STM32F334C8T6 Recently, for some reasons, a PWM waveform with arbitrary phase shift is needed to drive a full-bridge circuit. This article records the implementation process. Similar to a full-bridge rectifier, replacing the four diodes with switching devices creates a full-bridge inverter. The two bridge arms nee
[Microcontroller]
STM32 realizes arbitrary angle phase-shifted full-bridge PWM
Changyang Technology: Mini LED reflective film base films are all produced by the company
On November 24, Changyang Technology stated on the interactive platform that the company's reflective film uses polyester chips as the main raw material, adopts advanced process formula, and is made into a film through drying, melting, extrusion, casting and stretching. The Mini LED reflective film base film is produc
[Mobile phone portable]
Analyze the development trend of LED lighting design and development
Room lighting is inseparable from lamps, and lamps are the concentrated reflection of lighting. They are not only tools to complete the functions of room buildings and create visual conditions, but also part of room decoration, and the unity of lighting technology and architectural art. Modern lamps not only play a lig
[Power Management]
Design of control system for robot's dexterous hand based on PIC microcontroller
The research field of contemporary robots has moved from fixed-point operations in structured environments to autonomous operations in non-structured environments. The robot dexterous hand is equivalent to a group of robots installed on the robot arm that can independently realize fine operation movements. It is a t
[Microcontroller]
Design of control system for robot's dexterous hand based on PIC microcontroller
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号