To recognize the different patterns of the UI applications, both an algorithm running on a microcontroller or a finite
state machine (FSM) running directly on the sensor (when available) can be used.
This article gives some configuration examples for using the FSM for this purpose.
Table of the contents
- Why it is important to implement In-Ear Detection
- Application Scenario: the Qvar sensor
- Electrode Design
- FSM Configuration and Description
- Output Example
- Appendix: FSM Details (with pseudo-code)
In-ear detection has become a standard feature of TWS (True Wireless Stereo) headsets. This feature can provide users with a very user-friendly experience. When the user brings the headphones, the music will continue to play. When the user removes the headphones, the music will be suspended. In addition to this feature it can also save power and increase the use time for headphones. In-ear detection can be considered as similar to a long touch gesture where the device touches the inside of the ear and the Qvar is able to detect it.
Qvar stands for electric charge (= Q) variation (= var). It is an electrical potential sensing channel able to measure the quasi-electrostatic potential changes, enabling applications such as:
- contact and no-contact human motion detection and human motion gait analysis;
- human presence detection;
- user interface (UI);
- water detection.
An electrostatic charge is expected on a material whenever it comes into contact with another material or a solid or liquid surface. The level of charge is usually unpredictable, but it can be detected by means of an electrode and an electronic signal conditioning circuit. A signal is derived from the electronic circuit due to the fluctuations in the electric field resulting from the passage of the charged particles. When a sensor works by electrostatic induction, the sensing principle may be explained in terms of an equivalent capacitive sensor. This is because the charged object can be modelled as a plate of a capacitor while the electrode itself is modelled as the other plate. The movement of the charged object with reference to the electrode changes the distance between the two plates and hence the value of the capacitance. Similarly, the quantity of charge on the object may change with time and hence the voltage across the plates.
It is well known that electrode features such as size, shape and material are important factors that may produce different Qvar channel results. For instance, it exists a linear relationship between sensitivity and the electrode area. The sensitivity of the sensor is asymptotically increased with the area of the electrode. It is also well known that electrode features such as size, shape and material are important factors that may produce different Qvar channel results. For instance, it exists a linear relationship between sensitivity and the electrode area. The sensitivity of the sensor is asymptotically increased with the area of the electrode.
The electrode used in this application is shown in the figure below, it uses Q+ and GND pins to detect the charge variation and enables the INT2 interrupt to rise when Qvar detects the presence of the human body in contact with the electrode. It is printed on a flex board with the contact surfaces (in copper) exposed. In this way, in order to detect a touch gesture, it can be put in the area of the device that should be touched by the user. The goal of the design is to let the user touch both the Q+ and GND area at the same time. For this reason, many different designs are possible. The exposed copper areas at the tip of the board are the actual electrodes. When both of these electrodes are pressed, the sensor measures a high charge variation and the output signal is almost saturated. This saturated signal is comparable to the press of a button.
For the in-ear detection application, the LSM6DSV16X was used. In this configuration the accelerometer ODR is 30 Hz, the Qvar ODR is 240 Hz, while the current consumption is 195 μA for the accelerometer, 15 μA for the Qvar and 4 μA for the FSM, for a total of 214 μA. The threshold applied to the Qvar data is set to 32000 LSB. Since the sensitivity of the external sensor (in this case Qvar) is kept to its default value (which is 0.0015, equal to 1624h in half floating-point, HFP for short), the FSM THRESH1 value is set to 48.000.
The in-ear detection state machine configuration the LSM6DSV16X is described in the following table.
In particular, the instruction for 10h to 1Dh are further explained here below:
- PP = 10h SINMUX command with argument 02h is performed without without needing a sample set. It is used to select the “external sensor” as input of the state machine. Since the QVAR_EN bit of the CTRL7 (16h) register is set to 1, the Qvar sensor is selected. In this case, the Qvar data is available as +X axis of the external sensor. PP = PP + 2.
- PP = 12h SELMA command is performed without without needing a sample set. The MASKA (80h) is selected. PP = PP + 1.
- PP = 13h SRP command is performed without without needing a sample set. The RESET POINTER is set to the next state, 14h. PP = PP + 1.
- PP = 14h LNTH1 | TI3 condition is performed with the need for a sample set. If Qvar data is lower than or equal to THRESH1, then PP = RP. If Qvar data is greater than THRESH1 for 10 consecutive samples, then the PP is increased (PP = PP + 1).
- PP = 15h SELMB command is performed without needing a sample set. MASKB (01h) is selected. PP = PP + 1.
- PP = 16h OUTC command is performed without without needing a sample set. An interrupt is generated, and the OUTS register is updated according to the selected temporary mask (01h). PP = PP + 1.
- PP = 17h SELMA command is performed without needing a sample set. MASKA (80h) is selected. PP = PP + 1. AN5755 Register configuration for FSM usage AN5755 - Rev 1 page 13/21.
- PP = 18h SRP command is performed without needing a sample set. The RESET POINTER is set to the next state, 19h. PP = PP + 1.
- PP = 19h GNTH1 | TI3 condition is performed with the need for a sample set. If Qvar data is greater than THRESH1, then PP = RP. If Qvar data is lower than or equal to THRESH1 for 10 consecutive samples, then the PP is increased (PP = PP + 1).
- PP = 1Ah CRP command is performed without needing a sample set. The RESET POINTER is cleared to its default value, 10h. PP = PP + 1.
- PP = 1Bh SELMC command is performed without needing a sample set. MASKC (00h) is selected. PP = PP + 1.
- PP = 1Ch CONTREL command is performed without needing a sample set. An interrupt is generated, and the OUTS register is updated according to the selected temporary mask (00h). PP = RP.
The following plots are examples of a signal response when the device is plugged in and removed from the ear (on the left) and when the device is just picked up from a desk (on the right). On the left side, the signal saturates when the device is in contact with the skin inside the ear, and the FSM returns 1 until the electrodes are removed from the ear, while on the right side the signal fluctuates when the device is handled but it does not saturate, so the FSM output does not rise.
Here below the detailed sequence of the commands to be written in the memory for enabling the FSM through Qvar can be found:
1. Write 00h to register 10h // Set accelerometer sensor in power-down mode
2. Write 00h to register 11h // Set gyroscope sensor in power-down mode
3. Write 80h to register 01h // Enable access to embedded function registers
4. Write 01h to register 05h // EMB_FUNC_EN_B (FSM_EN) = ‘1’
5. Write 4Bh to register 5Fh // EMB_FUNC_ODR_CFG_B (FSM_ODR) = '01' (26 Hz)
6. Write 01h to register 46h // FSM_ENABLE = '01h'
7. Write 01h to register 0Fh // FSM_INT2 = '01h'
8. Write 40h to register 17h // PAGE_RW: enable write operation
9. Write 11h to register 02h // Enable access to embedded advanced features registers, PAGE_SEL = 1
10. Write 7Ah to register 08h // PAGE_ADDRESS = 7Ah
11. Write 00h to register 09h // Write 00h to register FSM_LONG_COUNTER_L
12. Write 00h to register 09h // Write 00h to register FSM_LONG_COUNTER_H
13. Write 01h to register 09h // Write 01h to register FSM_PROGRAMS
14. Write 01h to register 09h // Dummy write in order to increment the write address
15. Write 00h to register 09h // Write 00h to register FSM_START_ADDRESS_L
16. Write 04h to register 09h // Write 04h to register FSM_START_ADDRESS_H
17. Write 41h to register 02h // PAGE_SEL = 4
18. Write 00h to register 08h // PAGE_ADDRESS = 00h
19. Write 71h to register 09h // CONFIG_A
20. Write 00h to register 09h // CONFIG_B
21. Write 1Eh to register 09h // SIZE
22. Write 00h to register 09h // SETTINGS
23. Write 10h to register 09h // RESET POINTER
24. Write 00h to register 09h // PROGRAM POINTER
25. Write 00h to register 09h // THRESH1 LSB
26. Write 52h to register 09h // THRESH1 MSB
27. Write 80h to register 09h // MASKA
28. Write 00h to register 09h // TMASKA
29. Write 01h to register 09h // MASKB
30. Write 00h to register 09h // TMASKB
31. Write 00h to register 09h // MASKC
32. Write 00h to register 09h // TMASKC
33. Write 00h to register 09h // TC
34. Write 0Ah to register 09h // TIMER3
35. Write 23h to register 09h // SINMUX
36. Write 02h to register 09h // 02h
37. Write 66h to register 09h // SELMA
38. Write 33h to register 09h // SRP
39. Write 73h to register 09h // LNTH1 | TI3
40. Write 77h to register 09h // SELMB
41. Write 99h to register 09h // OUTC
42. Write 66h to register 09h // SELMA
43. Write 33h to register 09h // SRP
44. Write 53h to register 09h // GNTH1 | TI3
45. Write 44h to register 09h // CRP
46. Write 88h to register 09h // SELMC
47. Write 22h to register 09h // CONTREL
48. Write 00h to register 09h // STOP
49. Write 01h to register 02h // Disable access to embedded advanced features registers, PAGE_SEL = 0
50. Write 00h to register 17h // PAGE_RW: disable write operation
51. Write 00h to register 01h // Disable access to embedded function registers
52. Write 02h to register 5Fh // MD2_CFG (INT2_EMB_FUNC) = '1'
53. Write 74h to register 10h // CTRL1_XL = '74h' (normal mode, 30 Hz)
54. Write B0h to register 16h // CTRL7 = ‘B0h’ (Qvar enabled, Zin = 235 MΩ)