Home
Adjustable LED blinking speed using STM8SVLDISCOVERY
Contents
1. AN3996 Sf Application Note Adjustable LED blinking speed using STM8SVLDISCOVERY October 2011 Application overview This application note provides a short description of the demonstration firmware Discover which is preprogrammed in the Flash memory of the STM8S003K3T6 microcontroller This demonstration firmware makes use of the STM8S basic 8 bit timer configured as a time base generator to change the blinking speed of LED LD1 each time the push button B1 is pressed Once the STM8SVLDISCOVERY is powered up through a standard USB cable connected to the host PC LED LD1 starts blinking slowly meaning that the programming has been completed successfully This demonstration software is available from http www st com stm8svldiscover y It is provided to allow you to learn reuse and modify the application source code Built around the STM8S003K3T6 the STM8SVLDISCOVERY allows evaluation of the main features of all the STM8S00xxx line MCUs Reference documents m STM8SVLDISCOVERY user manual UM1482 m STM8SVLDISCOVERY getting started UM1480 m Developing and debugging your STM8S DISCOVERY application code user manual UM0834 m STM8S003 datasheet m STM8S reference manual RM0016 Doc ID 022386 Rev 1 1 10 www st com www BDTIC com ST AN3996 Contents 1 Application description 5 1 1 Hardware required ye ob ears e
2. 2 2 Application software flowcharts This section gives an overview of the application software main loop as well as of the function that controls LD1 blinking speed 2 2 1 Main loop flowchart Figure 1 shows the flowchart of the application software main loop Figure 1 Main application loop flowchart Configures PDO as output push pull low GPIO Configuration to drive LED LD1 and PB7 as input floating with interrupt Configures external interrupt sensistivity PB7 to falling edge only NES Starts timer TIM4 configured as timebase for LED toggling speed Increments variable BlinkSpeed modulo 3 each time a push button event occurs on B1 According to the value of BlinkSpeed Configuration 4 Configuration Blinking_StateMachine makes the LED blink at different rates or switches it off ai17220b Doc ID 022386 Rev 1 7 0 www BDTIC com ST Software description AN3996 2 2 2 8 10 Blinking StateMachine flowchart Figure 2 shows the detailed flowchart of the Blinking StateMachine function part of the main routine Blinking StateMachine function implements the algorithm that controls the LED blinking speed depending on the state selected by the push button At application start up the state machine is in its default state LD1 toggles every 1 s period then BlinkSpeed is incremented at each push button detection In state 1 and state 2
3. of the state machine the programmed blinking frequency is changed LD1 is switched off in state 0 LED LD1 blinking frequency is defined using the 8 bit timer TIM4 configured as a time base generator to assert an update interrupt every 4ms The toggling period depends on the value of PeriodNumber This variable defines the number of times the timer interrupt is to be asserted reach overflow before toggling the LED LD1 As a result LED blinking frequency can only be a multiple of 4 ms see Table 1 Figure 2 Blinking StateMachine flowchart 1 pressed BlinkSpeed 3 BlinkSpeed 07 yes case 0 LD1 switched off BlinkSpeed 1 yes case 1 Delay 200 ms BlinkSpeed 2 yes case 2 Delay 100 ms LD1 toggles Delay 1 s ai17221b Doc ID 022386 Rev 1 ky www BDTIC com ST AN3996 Revision history 3 Revision history Table 2 Document revision history Date Revision Changes 31 Oct 2010 1 Initial release Doc ID 022386 Rev 1 9 10 www BDTIC com ST AN3996 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products a
4. LDISCOVERY Application schematics Refers to UM1482 STM8SVLDISCOVERY for implementation details Application principle This application uses the 8 bit timer TIM4 as a time base generator to control LED LD1 blinking speed Each time the STM8S Value microcontroller detects an event on push button B1 the delay a multiple of the TIM4 time base between each toggle of the LED is adjusted to change the blinking frequency accordingly At application start up the blinking period is configured to 1 second and LD1 toggles at this rate every second This configuration allows to check visually that the STM8S Flash memory was successfully programmed Each time a push button event is detected on B1 LD1 blinking frequency is increased according to the settings described in Table 7 At the third press the LED is switched off You can then restart the blinking cycle Table 1 LED LD1 configuration Push button B1 LD1 Toggling period At application start up only Toggles 1 sec 1st press Toggles 200 ms 2nd press Toggles 100 ms 3rd press Switched off N A Doc ID 022386 Rev 1 5 10 www BDTIC com ST Software description AN3996 2 2 1 6 10 Software description The application software uses the STM8S standard firmware library to control general purpose functions and peripherals Clock CLK The clock control enables and delivers the correct clock frequency to the CPU and peripherals At power on the m
5. UNCTION MAY RESULT IN PERSONAL INJURY DEATH OR SEVERE PROPERTY OR ENVIRONMENTAL DAMAGE ST PRODUCTS WHICH ARE NOT SPECIFIED AS AUTOMOTIVE GRADE MAY ONLY BE USED IN AUTOMOTIVE APPLICATIONS AT USER S OWN RISK Resale of ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2011 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 10 10 Doc ID 022386 Rev 1 ky www BDTIC com ST
6. ae 5 1 2 Application schematics sss e eR RR ERR RE ERRERRERESQA E 5 1 3 Application principle uisus e Pa En der Y que 5 2 Software description a RR 6 2 1 STM8S standard firmware library configuration 6 2 2 Application software flowcharts 7 2 2 1 Main loop flowchart 7 2 2 2 Blinking StateMachine 8 3 REVISION aca doa On I RO CC e leac a Ca 9 2 10 Doc ID 022386 Rev 1 ky www BDTIC com ST AN3996 List of tables List of tables Table 1 LED ED configuration pem 5 Table 2 Document revision history 9 ky Doc ID 022386 Rev 1 3 10 www BDTIC com ST List of figures AN3996 List of figures Figure 1 Main application loop flowchart 7 Figure 2 Blinking StateMachine 8 4 10 Doc ID 022386 Rev 1 ky www BDTIC com ST AN3996 Application description 1 1 1 2 1 3 Application description Hardware required The following STM8SVLDISCOVERY on board resources are used LED LD1 User push button B1 No additional hardware is required to make this application software run on the STM8SV
7. aster clock source is automatically selected as HSI clock with prescaler division factor equal to 8 This setup is not changed by the application code fuAsTER 2 MHz GPIOs The GPIOs drive the MCU I Os to interface with external hardware They configure port PDO as output push pull low to drive LED LD1 and PB7 as input floating with external interrupt to interface with the push button B1 This interrupt is controlled by the Interrupt Controller EXTI The external interrupt controller is configured to control the external interrupt sensitivity on the push button connected to PB7 It is configured to trigger an interrupt each time a falling edge and only a falling edge is detected on PB7 TIM4 TIM4 is a basic 8 bit timer used as a 4 ms time base This time base is used by the application to control LD1 blinking speed TIM4 is configured by the application as follows Up Counting mode TIM4 PSCR 5 gt Counting frequency is 62 5 KHz Fck fuAsTER 2 PSCR 2 0 4 ARR OxFA 250 cycles STM8S standard firmware library configuration The stm8s conf h file of the STM8S standard firmware library is used to configure the library by enabling the peripheral functions used by the application The following define statements must be present define 1 enables GPIOs define EXTI 1 enables EXT1 define TIM4 1 enables TIM4 Doc ID 022386 Rev 1 ky www BDTIC com ST AN3996 Software description
8. re sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services described herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this document refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT UNLESS EXPRESSLY APPROVED IN WRITING BY TWO AUTHORIZED ST REPRESENTATIVES ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN MILITARY AIR CRAFT SPACE LIFE SAVING OR LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALF
Download Pdf Manuals
Related Search
Related Contents
NGS Purple Microhub SecureBill User Guide Avaya 6408D+ Telephone User Manual 新 潟 中 央 郵 便 局 ほ か 8 局 汚 水 槽 ・ 雑 排 水 槽 点 検 Dataflex 97.935 mpe - galletti K-GAP(かごしまの農林水産物認証制度)と 他 W28L100-CHL1 .cdr Campainha sem fios JA-189J Copyright © All rights reserved.
Failed to retrieve file