AN370
Rev. 1.0
31
7.2. Button Service Module and Master Time
The Button Service Module implementing Button Service Routine (BSR) is responsible for debouncing (referred to
as qualifying) button pushes/releases on the GPIO button inputs. Once a button push/release has been qualified, a
record of it is stored in the Push Tracking Structure (PTS) FIFO. From there an application can decide what actions
to take based on the button push/release.
The stored structure tracks all the button pushes and releases.
7.2.1. Button Service Module Key Terms
Table 4 lists key terms used in describing the Button Service Module.
7.2.2. Qualifying Button Pushes
When a button is pushed or released, the voltage on that pin will most likely fluctuate for some time before settling
at the desired level denoting the push/release. In order to correctly identify single button changes the buttons must
be debounced. Debouncing is done in the BSR module. Two factors govern the debouncing process.
1. Push Qualification Threshold (PQT) .. determines the number of same consecutive readings of the button
inputs needed to qualify as a button push/release. The PQT is supplied to the BSR module via the vBsr_Setup()
function.
2. Debounce Sampling Interval (DBI) .. user application determined interval between calls to the vBsr_Service()
function. The DBI is just a concept and there is no configurable parameter for it. It is up to the user application to
call the vBsr_Service() at a rate the user wants to sample buttons. Every call to vBsr_Service() samples the
button input GPIOs.
Note:
It is fully up to the user application to implement mechanism to call the
vBsr_Service()
routine in a periodic fashion in
time. The user is free to use the real time clock RTC timer for invoking interrupt or any of the two generic timers TMR2 or
TMR3 to implement periodic calling of the
vBsr_Service()
routine from a timer ISR, for example.
Table 6. Button Service Module
Term Definition
Push Tracking Structure (PTS)
FIFO that stores qualified button pushes. The PTS contains information
on button vectors and timestamps stored in tBsr_PtsElement structures.
Each element in the PTS corresponds to a qualified button push/release
and occupies two bytes. A push/release is qualified by debouncing firm-
ware used to determine when an actual button push has occurred on
GPIO pins. The depth of the PTS is configurable by the user via the
vBsr_Setup() routine during initialization.
PTS Element
Single entry in the PTS made of an instance of the tBsr_PtsElement
which contains a button vector and a timestamp.
Button Vector
Byte in which each bit corresponds to the respective GPIO, except bit 5
which corresponds to GPIO8. If the bit is 1, a press was detected on that
button, so the button connected the GPIO to the ground. Button vectors
are located in the bottom byte of the word which is returned from
wBsr_Pop() and wBsr_GetCurrentButton().
Note:
In 10-pin package the button vector bits 7:5 are not used.