This application note provides a short description of how to use the ADC, Timer and GPIO peripherals to display a variable voltage on a bar of LEDs. It introduces the main features of the STM8S-DISCOVERY development board and provides information on hardware requirements, application principle, and software description.
The document details an application where the average voltage from a variable resistor (RV1) is measured using the ADC1 peripheral triggered by TIM1. The resulting measurement is visually represented by lighting up LEDs (LD2-LD5) based on specific voltage thresholds.
The software implementation avoids standard libraries, configuring ADC1 for single conversion mode with external triggering and left alignment. TIM1 manages the wake-up of the ADC to allow stabilization time before conversion starts. GPIO pins control the output state of the four LEDs.
| External LEDs required | 4LEDs: LD2, LD3, LD4, LD5 |
|---|---|
| Filter capacitor value | 100 nF |
| ADC Clock Speed | Fmaster/8 |
No LEDs are switched on when the input voltage is between 0.0V and 0.7V.
At a voltage between 3V and 4V, LEDs LD2, LD3, and LD4 are switched on.