AN3280
Application Note
Displaying variable voltage on a bar of LEDs
using STM8S-DISCOVERY
Application overview
This application note provides a short description of how to use the ADC, Timer and GPIO
peripherals.
Once the STM8S105C6T6 has been powered-up through a USB cable connected to the
host PC, the Timer triggers the ADC according to a user-defined period to convert the
analog voltage provided by variable resistor RV1. The resulting average voltage
measurement is represented on the LED bar.
Even though the STM8S-DISCOVERY is built around an STM8S105C6T6, it allows
evaluation of the main features of all the STM8S MCUs.
Reference documents
■
■
STM8S-DISCOVERY evaluation board user manual (UM0817).
Developing and debugging your STM8S-DISCOVERY application code user manual
(UM0834).
October 2010
Doc ID 17983 Rev 1
1/13
www.st.com
Contents
AN3280
Contents
1
Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1
1.2
1.3
Hardware requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2
Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1
Application software flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.1.1
2.1.2
2.1.3
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
ADC1 interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
TIM1 capture/compare interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2/13
Doc ID 17983 Rev 1
AN3280
List of tables
List of tables
Table 1.
Table 2.
Voltage and LED correspondence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Doc ID 17983 Rev 1
3/13
List of figures
AN3280
List of figures
Figure 1.
Figure 2.
Figure 3.
Figure 4.
Figure 5.
Application schematic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ADC1 acquisition principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
ADC1 EOC interrupt flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
TIM1 capture/compare flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4/13
Doc ID 17983 Rev 1
AN3280
Application description
1
1.1
Application description
Hardware requirements
No on-board resources are used.
External resources needed are:
●
●
●
●
4 LEDs: LD2, LD3, LD4, LD5
1 x 10 KΩ variable resistor: RV1
4 x 1 KΩ resistors: R1, R2, R3, R4
1 x 100 nF capacitor: C1
1.2
Application schematic
Capacitor C1 filters the voltage spike on PE6.
Resistors R1, R2, R3 and R4 limit the current going into LD2, LD3, LD4 and LD5
respectively.
Figure 1.
Application schematic
C1
Doc ID 17983 Rev 1
5/13