November 2011 Doc ID 022506 Rev 1 1/10
AN4014
Application Note
Adjustable LED blinking frequency
using a potentiometer and STM8SVLDISCOVERY
Application overview
This document introduces a very simple application example which is ideal for beginners to
learn about the STM8SVLDISCOVERY and its programming environment.
This application adjusts the blinking frequency of a string of 4 LEDs using a potentiometer.
The ADC measures the analog voltage present at the potentiometer bridge, and the blinking
frequency of the LEDs is adjusted accordingly.
This application automatically starts as soon as the STM8SVLDISCOVERY is powered-up
through a standard USB cable connected to the host PC, and the LEDs start blinking at a
speed dependant on the potentiometer position.
Note: Additional hardware is required to run this application.
Built around the STM8S003K3T6, the STM8SVLDISCOVERY allows evaluation of the main
features of all the STM8S Value line MCUs.
Reference documents
STM8SVLDISCOVERY user manual (UM1482)
STM8SVLDISCOVERY getting started (UM1480)
Developing and debugging your STM8S application code user manual (UM0834)
STM8S003 datasheet
STM8S reference manual (RM0016)
www.st.com
Contents AN4014
2/10 Doc ID 022506 Rev 1
Contents
1 Application description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Hardware required . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Application schematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Application principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 Software description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Touch sensing library configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.2 Standard STM8S standard firmware library configuration . . . . . . . . . . . . . 8
2.3 Application software flowcharts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.1 Main loop flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3.2 ExtraCode_StateMachine flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12