Real-time keeping on STM8S and STM8A devices
and usage of auto-wakeup unit (AWU) and beeper
Introduction
The purpose of this application note is to explain how to keep real-time information on a
STM8S or STM8A device maintained in low power mode.
Only simple solutions which do not require any additional hardware are described in this
application note. They are suitable for applications which do not need a very accurate realtime measurement.
To benefit fully from the information in this application note, the user should be familiar with
the STM8S and STM8A microcontroller architecture and with the basics of C language.
For further information on the STM8S and STM8A family features, pinout and electrical
characteristics, please refer to the STM8S and STM8A datasheets.
An STM8S and STM8A firmware package is delivered with this application note. It contains
the complete C source code of an example described in this application note, so that the
user can compile, link or modify it as necessary.
This document and its associated firmware package, are written to accompany the STM8S
and STM8A firmware library. It includes many examples describing how to use the STM8S
and STM8A timers, the clock system, the beeper and the auto-wakeup unit mentioned in
this application note.
Related documents (available for download from www.st.com):
AN2780 associated firmware package
STM8S and STM8A firmware library
AN2822 “STM8S and STM8A high speed internal oscillator calibration”
AN2857 “STM8S and STM8A family power management”
AN2645 “Migration and compatibility guidelines for STM8S and STM8A microcontroller
applications”
1.1 Time base common to auto-wakeup unit and beeper
This application note focuses on solutions using one of the following STM8S and STM8A
peripherals: auto-wakeup unit or beeper. These peripherals share a common 128 kHz clock
(LS clock) which can be driven either by a low speed internal RC oscillator (LSI) or by a high
speed external crystal/ceramic resonator (HSE), depending on the CLKAWUSEL option bit
(see Figure below).
Figure 1.Time base block diagram for AWU and beeper
The HSE and LSI clock sources have different characteristics:
●The HSE source has the advantage of performing more accurate measurements but
the power consumption is higher (increased by about 0.5 mA) as the system must keep
the HSE clock running while it stays in low power mode. The HSE clock can be divided
by setting the PRSC option bits to get a LS clock frequency close to 128 kHz or a lower
frequency.
●The LSI clock system guarantees a much lower power consumption (consumption of
about 5 µA) but it has the disadvantage of being less accurate and highly temperaturedependent (about ±12.5% within the whole temperature range).
The time interval measurement accuracy can be improved by measuring the LSI
frequency internally. This can be performed by connecting the LSI clock to a given timer
input capture through the switch controlled by the MSR bit in the AWU_CSR register
and by setting properly the timer system for input capture capability. TIM3 is the
dedicated timer for this LSI measurement in most STM8S and STM8A devices. TIM1 is
used if TIM3 is not present. Some examples of input capture setting can be found in the
STM8S and STM8A firmware library.
Note:If the LSI clock frequency is measured while the microcontroller is driven by the HSI clock
(internal high speed oscillator), it is possible to achieve a greater accuracy by calibrating the
HSI clock before measuring the LSI frequency. The user can find further information on HSI
calibration in the AN2822 application note
(STM8S and STM8A high speed internal
oscillator calibration).
Doc ID 14759 Rev 25/20
Real-time measurement capabilityAN2780
counter
AWU counters
6-bit prog
AWUTB[3:0]
15 time bases
AWU interrupt
AWUEN & HALT/WAIT
APR[5:0]
~ 128 kHz LS clock
1.2 Solution using the auto-wakeup unit in Active-halt mode
1.2.1 Introduction
The basic software principle is to keep track of the number of elapsed time intervals
detected by the AWU. The accumulated time can easily be converted from this data by
loading a structure keeping real-time information either on request or at regular intervals.
1.2.2 Description
The auto-wakeup unit (AWU) provides an internal wakeup time base that is used when the
MCU goes into Active-halt mode. The measurement of this wakeup time can be used to
keep real-time information but some limitations must be considered, as described in the
following sections.
Figure 2.AWU block diagram
Note:As the AL bit in the CFG_GCR register cannot be used in low power mode, when the device
6/20 Doc ID 14759 Rev 2
The AWU time intervals depend on the prescaler value defined in the APR bits of the
AWU_APR register and on the AWUTB bits programmed in the AWU_TBR register. To enter
Active-halt mode, the auto-wakeup unit must be enabled by setting the AWUEN bit in the
AWU_CSR register before HALT instruction execution.
The AWU counters are running and counting only when the device is in Active-halt mode.
They are stopped when the CPU is in Run mode and initialized again when the
microcontroller enters Active-halt mode. This means that the total period is the sum of the
AWU interval (AWU timeout) and the duration of the AWU interrupt routine.
goes back from an interrupt, the user must handle by software the device return to Halt
mode.
Loading...
+ 14 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.