目录

The Fading LED

This repository is a cross-vendor example of how to “do things in the embedded way”. A fading LED controlled over UART is implemented using microcontrollers from different vendors. The objective of this repository is demostrating that:

  • Each vendor provides its own API with its own SDK. The API can be different across vendors, but the thing it does is essentailly the same.
  • There are some “universal ways” to write an embedded program. These ways are independent of the vendor, and very different from how to write userspace programs.
  • A developer should learn how to write embedded programs, not how to use a specific family of embedded hardware from a specific vendor. Learning about different vendors and different ways of embedded programming is benificial.

Each subdirectory of this repository is an embedded project for a specific microcontroller or family of microcontrollers. The functionality of each project can be slightly different. And each project is implemented in a different way. Most of the projects require you to install the vendor’s SDK or IDE to build. Please see the README in each subdirectory for the details.

To make some effect like fading on a LED, the microcontroller need to change its brightness perodically. The microcontoller usually does not control the voltage or current of the LED, as this requires a DAC and a power ampilfier, which makes things complicated and expensive. Instead, it uses PWM waves. A PWM wave is a square wave whose period is fixed but duty (the ratio of time when it is high) can be adjusted. If a PWM wave is output to a LED, it will be turned on and off at a high frequency. If this frequency is high enough, it will seem as if it is constantly turn on at a lower brightness. By changing the ratio of time when it is on, the brightness can be changed. To make the LED controllable over UART, it needs to receive the user input from UART and parse it into parameters like the period of the fading effect and the maximum brightness.

In conculsion, it is easy to figure out what to do:

  • Generate a PWM wave.
  • Change the duty of the PWM wave periodically.
  • Receive user input from UART.
  • Parse the user input into paramaters and make the new parameters effective.

But the real problem is how to do these. It turns out there are many different ways. “The embedded way” is not a single universal pattern that rules it all, it is making use of the hardware and RTOS features and choosing a way that suits your senario best.

关于

Implementing "the fading LED" for different microcontrollers from different vendors.

1.1 MB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号