简体   繁体   中英

HW Timer (PWM) or SW Timer to control a LED

As the title says, is it generally good practice to use General Purpose Timers for dimming a LED (PWM with variable duty cycle) or is it better to use OS scheduling/tasks when available (RTOS ecc)? I recently saw an example of a blinking led using the RTOS internal timers and i was wondering if the period of the timer can be fastened up to the point where you can dim a led (~2Khz).

Regards,

Pulsing a LED in software could flicker if some other task were to interfere with its scheduling, and you won't get much fine control over brightness. So if PWM hardware is available (and it can work with that pin, and isn't needed for something else), I would use the hardware.

A common pattern is to use PWM to control the visible brightness of the LED, then to have a regularly scheduled sofware task to vary it smoothly (to produce fades, blinks and so forth), based on a counter and some state/variables which might be controlled by other tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM