Getting Started with TSI0 on TWR-K70F120M

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting Started with TSI0 on TWR-K70F120M

961 Views
thomasolenik
Contributor III

I'm just getting started with the TWR-K70F120M and am have a little trouble finding much information on how to use the touch electrodes on the board. From the schematic I can see that they are connected to TSI0 channels 5, 7, 8, 9.  I'm looking for a little more description for how to use this input type in code.  I'm also looking for guidelines on settings.  I've reviewed the help files, but the help on this topic really only gives the options available.

For the pin signal property, I named each channel touchDx where x is the number given on the board.  So if I want to poll for what touch pad is touched, do I just do something simple like:

if(touchD7)

{

     /*code here*/

}

Or

switch(TSI0)

{

     case touchD7:

}

Or are there a few more steps involved?

Labels (1)
0 Kudos
Reply
1 Reply

820 Views
Edrianocarlos
Contributor IV

Hi i am not familiar with k70. but have used then i k60 and kl25.

the peripheral is very simple. all you have to do is enable the clock for the module.

SIM_SCGC5 |= SIM_SCGC5_TSI_MASK; // HABILITA CLOCK

Configure the frequencies and the vth for the oscillator. in this way you can literally read the capacitance of the electrode.

TSI0_GENCS |= (TSI_GENCS_ESOR_MASK

| TSI_GENCS_MODE(0x00) // SEM DETECÇÃO DE RUIDO

| TSI_GENCS_REFCHRG(5) // 8 micro-amp

| TSI_GENCS_DVOLT(0) // voltage rails

| TSI_GENCS_EXTCHRG(5) // charge/discharge current

| TSI_GENCS_PS(6) // FREQUENCIA DIVIDIDA POR 16

| TSI_GENCS_NSCN(0) //

// | TSI_GENCS_TSIIEN_MASK //SEM INTERRUPÇÃO

| TSI_GENCS_STPE_MASK

// | TSI_GENCS_STM_MASK // TRIGGER POR SOFTWARE

// 0 = software

);

TSI0_GENCS |= TSI_GENCS_TSIEN_MASK; // enable TSI

then you can start and poll de electrode.

  TSI0_DATA = (5 << TSI_DATA_TSICH_SHIFT);

  TSI0_DATA |= TSI_DATA_SWTS_MASK; //

  while(!(TSI0_GENCS & TSI_GENCS_EOSF_MASK));

  TSI0_GENCS |= TSI_GENCS_EOSF_MASK;

  capacitor.eletrodos[2] = (TSI0_DATA & TSI_DATA_TSICNT_MASK);

0 Kudos
Reply