This tutorial shows how to use the hardware floating-point module present on STM32F4 devices. We will demonstrate the use of floating point by producing a “breathing LED effect” – gradually turning the LED on and off. The LED itself cannot be ‘partially on’, however if we quickly turn it on and off (>100Hz) having it on X% of the time, it will look like the LED is at the X% of its maximum brightness:

The proportion of the time when the LED is on is called duty cycle. To achieve the “breathing effect” we will adjust the duty cycle gradually according to the sine waveform:

The PWM pulse width will hence be calculated as T·(1 +

sin(arg)) / 2, where T is the PWM period and arg is a floating-point counter that we keep increasing in small increments.