.. index:: heartblink .. _heartblink: heartblink README ================================================================= :: Project: heartblink Created: Mon 1 Mar 2021 14:42:11 AEDT Doc Author 2021 by t.j.porter license: MIT, please see COPYING Purpose: Blinks/fades the blue led on a F0 Discovery board like a heartbeat. Three variations of Sine, Cosine and Triangle modulation are included. Intended Audience: anyone MCU: STM32F051 (any STM32F0xx should work) Board: STM F0 Discovery Required: arm-none-eabi, st-flash, linux, freebsd etc Literature: Code Author(s): Matthias Koch Code License: all *.s are GPL3 Binary Size: 58-60 Bytes ----------------------------------------------------------------- **Full project Tarball with ready to flash 'sine' binary:** * https://sourceforge.net/projects/mecrisp-stellaris-folkdoc/files/heartblink-03.03.21-9106.zip Description ----------- Heartblink fades a STM F0 Discovery Board LED in and out like a heartbeat. This is done in software only, no timer peripheral is used making it easily portable to other brands of Cortex-M0. Total binary size is only 58-60 Bytes. How Does It Work ---------------- A differential equation is numerically approximated (providing the sine/cosine/triangle function), the result interpreted as a floating point number and converted to integer (to get an exp(x) approximation) and fed into a sigma/delta modulator, the output of which drives the LED. The exp(x) approximation is to correct for human eyesight Comments by Crest ^^^^^^^^^^^^^^^^^ Matthias uses the minsky circle to approximate a sinus function which is faster than the proper cordic algorithm and good enough for a dimming a led. Given a pair (x, y) on the almost circle the algorithm updates this pair by adding or substracting the upper bits of the other axis shifted right a few places to each axis and he uses one of the axis as the brigthness of the led to get the nice slow fade in and out with almost linear perceived brightness Three Versions -------------- There are three different versions for you to try: * Triangle * Sine * Cosine Makefile Selection and Build ---------------------------- Selection ^^^^^^^^^ In the Makefile edit by un-commenting, and commenting as required. Select *one* of the three choices below. In this example "sine" is selected. .. code-block:: makefile SRC = sine # SRC = cosine # SRC = triangle Build ^^^^^ * Build with "make clean and make" * flash with "make flash" .. note:: Cosine and sine are the same except cosine starts with the led fully on. Sine ---- * 58 Byte binary. .. literalinclude:: projects/fo-disco-heartblink/sine.s Cosine ------ * 58 Byte binary. .. literalinclude:: projects/fo-disco-heartblink/cosine.s Triangle -------- * 60 Byte binary. .. literalinclude:: projects/fo-disco-heartblink/triangle.s