Modifying touch.c

Status
Not open for further replies.

ljdankov

Member
I have been working with some capacitive strain sensors and would like to adjust the touch.c file to get higher sensitivity in my ranges of interest. In some previous posts, adjusting parameters in touch.c in accordance with the parameters given in the k20 reference documentation, at: https://www.nxp.com/docs/en/reference-manual/K20P64M72SF1RM.pdf is recommended as an option. However I am somewhat going in circles with exactly how changing specific values will effect sensitivity output as the numbers I have plugged in are not matching up to the notes in touch.c file.

In touch.c comments, it is mentioned that default settings give approx 0.02 pF sensitivity and 1200 pF range, and that time to measure 33 pF is approx 0.25 ms and time to measure 1000 pF is approx 4.5 ms, and output is about 50*C_elec pF.

Looking at the spec sheet for k20, I understand the following values to be 'fixed':
deltaV=500mV
cRef=1pF

The following values can be adjusted in touch.c in order to change speed, sensitivity and range:
#define CURRENT 2 // 0 to 15 - current to use, value is 2*(current+1)
#define NSCAN 9 // number of times to scan, 0 to 31, value is nscan+1
#define PRESCALE 2 // prescaler, 0 to 7 - value is 2^(prescaler+1)
I noticed that Iref could also be modified by changing value in TSI0_SCANC = TSI_SCANC_REFCHRG(3) , but I assume you hard coded it for a reason.

When I plug the default values into the formula from the K20 reference documents, I am not getting the values you list in touch.c comments:
Time=2*PRESCALE*NSCN*C_electrode*deltaV/CURRENT=2*2^(2+1)*C_electrode*1*500/(2*(2+1)
Time(33pF)= .33 ms, time(1000 pF)=13.3 ms

Sensitivity=cRef*CURRENT/(Iref*PRESCALE*NSCAN)=1*2*(2+1)/(8*2^(2+1)*10)=0.0125pF

Output = Iref*PRESCALE*NSCN*C_elec/(cRef*Ielec)=C_elec*8*2^(2+1)*10/(1*2^(3+1))=80*C_elec pF

Given how far these numbers are from the ones listed in comments, I wanted to make sure I actually understand how these formula work before I start modifying the touch.c file.
 
The decision to hard-code parameters was done for simplicity. The goal was (and still is) to give the sort of simple, easy to learn & understand API that people expect when using Arduino. Following that philosophy, the idea is that the code is open source. The defines are meant to help advanced users who dig into the core library code.

Code published by silicon vendors usually has opposite goals, typically to expose & demonstrate as much hardware functionality as possible. Afterall, they want to show you what their product can do and make a sale. But in the process, typically they create complex APIs and mountains of documentation. Teensy tries to mostly follow Arduino's way, which may seem foreign if you're used to "professional" packages.

Sorry, I don't have an answer for you specifically about those Freescale equations. My only advice is to experiment with the code.

Just to be clear, unless a bug is found and a clear test case is posted, I have no intention to work with this code again in the foreseeable future. I have far too many other developments pending...
 
Fair enough. I completely understand having many projects going on at once. I did want to inquire though is there anything I need to do other than update the defines and then load any sketch code onto the teensy as the defines new values should be pushed to k20? I have tried a few different values, but code output does not seem to change.
 
A while ago, I played around with touch.c and a Teensy LC and found it working as expected and described by the ref manual. I even traced the triangle waves at the corresponding TSI pins with an oscilloscope which was less easy, since a 1:1 probe adds more than 100pF and a 1:10 probe still between 15 and 25pF.
 
Status
Not open for further replies.
Back
Top