This section illustrates the usage of interrupts during qt_measure_sensors call. The library disables interrupts for time-critical periods during touch sensing. These periods are generally only a few cycles long, and so host application interrupts should remain responsive during touch sensing. However, any interrupt service routines (ISRs) during touch sensing should be as short as possible to avoid affecting the touch measurements or the application responsiveness.
Interrupts are disabled once for each signal count/burst pulse and this is typically 65 instruction cycles when Delay cycles (QT_DELAY_CYCLE=1).
The number of times interrupts are disabled during one measurement will depend on signal count of a channel as well as the number of channels and port configuration like interport (SNS and SNSK on different port)/intraport (SNS and SNSK on same port).
Channel0 is formed by PA0 and PA1 pin with signal count 300.
Channel1 is formed by PA2 and PA3 pin with signal count 200.
Channel2 is formed by PA4 and PA5 pin with signal count 250
Channel3 is formed by PA6 and PA7 pin with signal count 150
In the above case, the no of times interrupts disabled will be 300 (maximum signal count) as all four channels burst together in case of intraport.
Channel0 is formed by PA0 and PB0 pin with signal count 300.
Channel1 is formed by PA1 and PB1 pin with signal count 200.
Channel2 is formed by PA2 and PB2 pin with signal count 250
Channel3 is formed by PA3 and PB3 pin with signal count 150
In the above case, as bursting happens in odd and even pairs, so maximum signal counts in case of both even and odd channels will be taken. Maximum signal count out of even channels channel0 and channel2 is 300 and maximum signal count out of odd channels channel1 and channel3 is 250. So total number of times interrupts disabled will be (300 + 250 = 550).
The recommended maximum ISR execution time is 1msec. If ISR time exceeds 1 ms then it may result in charge leakage which will further lead to rise in signal value. Noise observed in the signal value will increase. The 1msec ISR limit applies to the total time spent in an ISR during one acquisition period, and applies only to QTouch and QMatrix. One acquisition period is the time to complete one burst sequence. This will be the time required to do the 300 pulses situation in the first example above. In the second example above the 1msec limitation applies to the 300 and then the 250 pulses; 1msec of total ISR can occur during the 300 and another 1msec ISR can occur during the 250. This is all about self discharge happening while doing a burst. In the example below it would be perfectly OK to have a 1msec ISR happening every 5 msec.
If the ISR load is constant and synced with the acquisition (meaning the ISR takes a constant amount of time and executes in the same amount of time during each burst sequence), the signal will not suffer at all since the self discharge will be the same every time the acquisition is run. If there is a strong variation in the total ISR execution time during acquisition this will appear as noise in the signal due to the variable self discharge of the sample cap.
The time to execute one measurement will depend on various parameters like sampling capacitor, operating voltage, and different software parameters like QT_DELAY_CYCLES, CPU frequency.
Sampling Capacitor = 10 nF
CPU Frequency = 4 MHz
VCC = 5V
QT_DELAY_CYCLES = 1
Note that none of the API functions should be called from a user interrupt.