Home

Adjustable buzzer frequency using STM8S

image

Contents

1. 5 1 3 Application principle 6 2 Option byte configuration 7 3 Software description 8 3 1 Touch sensing library configuration 8 3 2 Standard STM8S firmware library configuration 9 3 3 Application software flowcharts 10 3 3 1 Main loop flowchart 10 3 3 2 ExtraCode StateMachine flowchart 11 4 Revision history 12 2 13 Doc ID 17979 Rev 1 ky AN3277 List of tables List of tables Table 1 Beeper configuration AA III IAA Kaa 6 Table 2 Touch sensing library configuration 8 Table 3 Document revision history ananan 12 Ly Doc ID 17979 Rev 1 3 13 List of figures AN3277 List of figures Figure 1 Application schematics RII 5 Figure 2 Main application loop flowchart 0 0000 eee 10 Figure 3 ExtraCode StateMachineflowchart 11 4 13 Doc ID 17979 Rev 1 ky AN3277 Application description 1 1 1 2 Application description Hardware required The following STM8S DISCOVERY on board resources are used e Touch sensing key TS1 e LED LD1 A piezo buzzer with an operating voltage of 5 V and which
2. Cer AN3277 di Application Note Adjustable buzzer freguency using STM8S DISCOVERY touch sensing key October 2010 Application overview This application note provides a short description of how 3BEEP application software can use a Beeper peripheral to take advantage of the STM8S DISCOVERY touch sensing key TS1 Once the STM8S105C6T6 is powered up through a USB cable connected to the host PC the LED LD1 switches on meaning that the programming has been completed successfully m Each time the TS1 key is pressed the Beeper emits a beep at different frequencies 1 KHz 2 KHz and 4 KHz respectively m The fourth time TS1 is pressed the Beeper stops emitting m A Beeper cycle can then be restarted by pressing TS1 again Alternate function remapping must be performed on the STM8S105C6T6 before the Beeper peripheral can be used in this manner This is described in UM0834 Even though the STM8S DISCOVERY is built around an STM8S105C6T6 it allows evaluation of the main features of all the STM8S MCUs Reference documents m STM8S DISCOVERY evaluation board user manual UMO081 7 m Developing and debugging STM8S DISCOVERY application code user manual UM0834 Doc ID 17979 Rev 1 1 13 www st com Contents AN3277 Contents 1 Application description 5 1 1 Hardware required 5 1 2 Application schematics
3. continued Function define statement Value Comment SCKEY P1 KEY COUNT 1 re al SS 1 SCKEY P1 PORT ADDR GPIOC_BaseAddress d E Pin 1 selected as SCKEY P1 A 0x02 SE Single channel key acquisition input SCKEY P1 DRIVEN SHIELD MASK 0x08 Pin 3 for active shield SERES PA IQUN f Key port P2 not used SCKEY_P3_COUN Key port P3 not used Multichannel key NUMBER_OF_MULTI_CHANNEL_KEYS 0 Multichannel key feature disabled GPIOA_ELECTRODES_MASK 0x00 GPIOB_ELECTRODES_MASK 0x00 GPIOC_ELECTRODES_MASK Ox0A Defines the electrode GPIOD_ELECTRODES_MASK 0x00 mask for each GPIO Electrode mask GPIOE_ELECTRODES_MASK 0x00 used GPIOF ELECTRODES MASK 0x00 Mask must be set to 0x00 GPIOG ELECTRODES MASK 0x00 for unused GPIOs GPIOH ELECTRODES MASK 0x00 GPIOI ELECTRODES MASK 0x00 3 2 Standard STM8S firmware library configuration The stm8s_conth file of the STM8S standard firmware library configures the library by enabling the peripherals used by the application The following define statements must be present A define CLK 1 enables the clock control CLK define GPIO 1 enables the GPIOs define BEEP define TIM3 enables the Beeper 1 enables the Timer 3 Doc ID 17979 Rev 1 9 13 Software description AN3277 3 3 3 3 1 10 13 Application software flowcharts This section gives an overview of the application software main loop and of the function that controls sound frequency generation Detailed infor
4. supports a frequency range of 1 KHz to 4 KHz is required to make the 3BEEP application software run on the STM8S DISCOVERY Application schematics Figure 1 shows the touch sensing key implementation principle based on the RC acquisition method For STM8S DISCOVERY implementation details refer to the board schematic provided in the STM8S DISCOVERY user manual UM0817 For detailed information about RC acquisition principle for touch sensing applications refer to AN2927 Figure 1 Application schematics PC2 load 1 0 STM8S ai17226 Doc ID 17979 Rev 1 5 13 Application description AN3277 1 3 6 13 Application principle This application uses the Beeper peripheral to output a signal on the Beeper pin for sound generation Each time the STM8S microcontroller detects a touch event on TS1 the Beeper output frequency is reprogrammed as described in Table 1 At the fourth touch the Beeper is disabled You can then restart the cycle The LED LD1 is switched on at application start up this verifies visually that the STM8S Flash memory was successfully programmed Table 1 Beeper configuration TS1 state Beeper frequency At start up No sound 1st TS1 touch 1 KHz 2nd TS1 touch 2 KHz 3rd TS1 touch 4 KHz Doc ID 17979 Rev 1 AN3277 Option byte configuration 2 Option byte configuration On the STM8S105C6T6 the Beeper output is an alternate function which is avai
5. R LIFE SUSTAINING APPLICATIONS NOR IN PRODUCTS OR SYSTEMS WHERE FAILURE OR MALFUNCTION 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 2010 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 ki Doc ID 17979 Rev 1 13 13
6. lable only after remapping As a result the alternate function remapping bit 7 AFR7 of the option byte OPT2 must be modified as follows 0 Port D4 alternate function TIM2 CH1 default 1 Port D4 alternate function Beep required For alternate function remapping details refer to UMOB834 For option byte details refer to the STM8S105xx datasheet ky Doc ID 17979 Rev 1 7 13 Software description AN3277 3 Software description The application software uses both STM8S standard and touch sensing firmware libraries to control general purpose functions and touch sensing peripherals These functions and peripherals are e Clock CLK The clock control enables and delivers the correct clock frequency to the CPU and peripherals It configures the HSI prescaler division factor from 8 to 1 e GPIOs They drive the MCU I Os to interface with external hardware They configure ports PDO and PD4 as output push pull low to drive the LED LD1 and switch it on at initialization as well as the Beeper output pin e Beeper This peripheral drives the Beeper output pin with a signal in the range of 1 2 or 4 KHz for sound generation e Timer 3 TIM3 This is a 16 bit timer with an 8 bit prescaler The touch sensing firmware library uses Timer 3 for touch sensing acquisition TIMACQ See Table 2 for the corresponding define statement in the STM8 touch sensing library It also performs LSI calibration before the LSI is used as the clock s
7. mation can be found in the STM8S DISCOVERY software user manual UM0834 Main loop flowchart Figure 2 shows the flowchart of the application software main loop Functions TSL init and TSL Action in the API of the touch sensing library initialize the library and control the state machine that sequences the touch sensing management Figure 2 Main application loop flowchart START Configures HSI prescaler division factor from 8 to 1 Clock configuration gt Reeg s MHz Configures PDO and PD4 as output push pull low to drive LED GPIO configuration LD1 and buzzer Piezo respectively LD1 is swiched on at startup The LSI clock is internally connected to TIM3 input capture Beep calibration channel 1 for calibration TSL init I Initializes memory API and struct in the touch sensing library Extracode_init Initializes TS1 key state machine Initializes iCount variable Each time a touch event occurs on TS1 the beeper frequency is reconfigured 1 KHz 2 KHz and 4 KHz and the buzzer emits a sound accordingly ExtraCode StateMachine Then the Beeper is disabled A beeper cycle can be restarted Main Touch sensing state machine performing the seguencing TSL Action 0 of the actions concerning the touch key d Doc ID 17979 Rev 1 AN3277 Software desc
8. oducts and services described herein at any time without notice All ST products are 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 AN AUTHORIZED ST REPRESENTATIVE ST PRODUCTS ARE NOT RECOMMENDED AUTHORIZED OR WARRANTED FOR USE IN MILITARY AIR CRAFT SPACE LIFE SAVING O
9. ource of the Beeper e Timer 4 TIM4 This is a basic 8 bit timer used as a generic time base TIMTICK This time base is used by the touch sensing firmware library to control the charge discharge cycles of the RC network resistor R4 plus TS1 electrode Timer 4 is also used by the application to control LD1 blinking speed It is distinct from the acquisition Timer 3 See Table 2 for the corresponding define statement in the STM8 touch sensing library 3 1 Touch sensing library configuration The STM8 TSL RC Configuration h file configures the touch sensing library Table 2 describes the main define statements required to configure the library for the STM8S DISCOVERY to control the TS1 touch sensing key The other define statements should keep their default values Refer to the STM8 touch sensing library online help for details concerning these define statements Table 2 Touch sensing library configuration Function define statement Value Comment MCU selection STM8S 1 TIMAC TIM3 Acguisition timer g TIM3 base address TIMACQ_CNTR_ADD 0x5328 Time base timer TIMTICK TIM4 LOADREF_PORT_ADDR PI BaseA Load 1 0 7 7 SIDE BaseAddiuse Port PC4 selected LOADREF BIT 0x04 8 3 Doc ID 17979 Rev 1 ki AN3277 Software description Table 2 Touch sensing library configuration
10. ription 3 3 2 Figure 3 TSL IDLE STATE ExtraCode StateMachine flowchart Figure 3 shows the detailed flowchart of the ExtraCode_StateMachine function This function implements the algorithm that controls the Beeper sound frequency according to the number of times the TS1 key is pressed When a TS1 touch event is detected the Beeper frequency configuration is changed by the main routine see Figure 3 resulting in a change to the generated Beeper sound refer to Table 1 ExtraCode_StateMachine flowchart TSL_State iCount 0 CaseO Yes iCount 1 Beeper disable iCount 1 Beeper 1 KHz Case 1 Yes iCount 2 Case2 Yes Beeper 2 KHz Default Case3 Yes iCount 3 Beeper 4 KHz iCount 0 Doc ID 17979 Rev 1 11 13 Revision history AN 3277 4 12 13 Revision history Table 3 Document revision history Date Revision Changes Initial release UM0845 has been converted into this Application 07 Oct 2019 1 note This document replaces UM0845 Doc ID 17979 Rev 1 AN3277 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 pr

Download Pdf Manuals

image

Related Search

Related Contents

Manual Coifa de Ilha - Built Eletrodomésticos  AVANT DE COMMENCER MODE D`EMPLOI  junXionboard manual  Nokia E60 Cell Phone User Manual  Philips Stereo audio cable MWA2521T  NEX-3/NEX-5/NEX-5C  Favoriser la motivation au travail  AD-4401の 優れた機能を引き継いだ 互換性重視の後継機種  Yachtspot Installation Guide v5.0  Severin BA3241 iron  

Copyright © All rights reserved.
Failed to retrieve file