Kwikstik touch sensors

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

Kwikstik touch sensors

883 Views
derill03
Contributor I

Hello, I was wondering if someone could help me out a little bit with reading the touch sensors on the kwikstik.

 

So far what ive done is set:

 

TSIO_GENCS = 0x80

TSIO_PEN = 0xffff       just to ensure i turn on the right touch pad cause its hard to understand which TSI pin is = E3,E4,E5,E6 on kwikstik although i do know that E3 = PTA24, E4 = PTA25, E5 = PTA26, E6 = PTA27

 

I assume im gonna have to monitor GPIOA_PDIR for PTA24,25,26,27 when i touch E3,4,5,6 but again im not super sure

 

Can anyone help me understand better how to monitor the sensor pad so i can make an event happen when pad is touched?

 

 

 

Here is how im writing the values, and they do go into the address locations correctly:

 

VAL1:         .word 0x140
VAL2:         .word 0x403A0  //turn on portA and TSI clocks
VAL3:         .word 0x20000
VAL4:         .word 0x1
VAL5:         .word 0xfffff
VAL6:         .byte 0x06
VAL7:         .word 0x80
VAL8:         .word 0xffff
VAL9:         .word 0x35

 

LDR R1,SIM_SCG5     // turn on clock for PORTA and TSI
      LDR R2,VAL2
      STR R2,[R1]
      
      LDR R1,TSIO_GENCS     
      LDR R2,VAL7
      STR R2,[R1]
      
      LDR R1,TSIO_PEN     
      LDR R2,VAL8
      STR R2,[R1]
      /////////////////////////////////////////

     This is to turn on PORTA_17 for use toggling LED

      ///////////////////////////////////////////////////////////

      LDR R1,PORTA_PCR17  // set MUX bit to a "1" to set PORTA_17 as GPIO ALT 1 and set DSE bit to a "1" for high drive strength  
      LDR R2,VAL1
      STR R2,[R1]

0 Kudos
3 Replies

590 Views
mjbcswitzerland
Specialist V

Hi

 

On the Kwikstik only the buttons E1 and E2 are connected to ports which support touch senor inputs. To use these in touch sensor mode their pull-ups resistors need to be removed from the hardware.

 

The others do operate as touch senor inputs but only when used together with Freescale's library code which emulates this operation.

 

Since you are interested in using the touch sensor peripheral (and not the touch senor library code) you will need to restrict work to E1 and E2 and remove the two pull-up resistors.

 

The simplest method is to simply poll the values (rather than work with the interrupt mechanism) since this requires very little code. However it is first necessary to calibrate the inputs since the values measured will depend on the layout of the pads and also the configuration of the touch sensor itself (the calibration values also change depending on whether the silicone cover is used or not). A re-calibration at each reset is a simple method of ensuring that it works (but assumes that no one is pressing the key already at reset).

 

Below is some simple code (you will need to convert to assembler) that initialises and start a first conversion:

 

POWER_UP(5, SIM_SCGC5_TSI);                             // power up the touch sense input module_CONFIG_PERIPHERAL(B, 0,  PB_0_TSI_CH0);           // select TSI channel 0 on PB0  (alt. function 0)_CONFIG_PERIPHERAL(A, 4,  PA_4_TSI_CH5);           // select TSI channel 5 on PA4  (alt. function 0)
TSI0_PEN = (TSI_PEN_PEN0 | TSI_PEN_PEN5);           // enable channels 0 and 5
TSI0_THRESHLD0 = ((0x0100 << 16) | (0x0230));   // provisional threshold levelsTSI0_THRESHLD5 = ((0x0100 << 16) | (0x0230));TSI0_SCANC = (TSI_SCANC_SMOD_CONTINUOUS | TSI_SCANC_AMCLKS_BUS_CLK | TSI_SCANC_AMPSC_128);TSI0_GENCS = (TSI_GENCS_STM_SW_TRIG | TSI_GENCS_SWTS | TSI_GENCS_TSIEN | TSI_GENCS_PS_32);

 

This is suitable for the two buttons on the Kwikstik. The operating speeds are chosen quite randomly but the initial threshold values are typical values with this setting.

 

To calibrate, allows several measuremenst to be made and set a threshold based on these (eg. with these settings the threshold can be set at about 0x15 above the average during calibration - this works well from experience).

 

Each measurement value is read by using

 

value = TSI0_CNTR1;

and

value = TSI0_CNTR5;

 

To start the next cycle, the following command can be used:

 

TSI0_GENCS = (TSI_GENCS_STM_SW_TRIG | TSI_GENCS_SWTS | TSI_GENCS_TSIEN | TSI_GENCS_PS_32); // re-trigger touch senor measurement

 

Regards

 

Mark

 

0 Kudos

590 Views
derill03
Contributor I

This is what i got for an assembly conversion, i wasnt sure if the value for THRESHLD_x was correct i basically shifted 0x100 16 places to the left and or'ed it with 0x0230 to get 0x40230, im also not sure what COUNTER value is gonna be but right now it is always zero, any help?

 

 

.section .sdata
         .align 2
VAL1:         .word 0x140
VAL2:         .word 0x403A0  //turn on portA and TSI clocks
VAL3:         .word 0x20000
VAL4:         .word 0x1
VAL5:         .word 0xfffff
VAL6:         .byte 0x43
VAL7:         .word 0x80
VAL8:         .word 0x21
VAL9:         .word 0x35
VAL10:        .word 0x40230
VAL11:        .word 0x11
VAL12:        .word 0x50080
      .text
      .align 4

SIM_SCG5:    .word 0x40048038
PORTA_PCR17: .word 0x40049044
PORTA_PCR4: .word 0x40049010
PORTB_PCR0: .word 0x40049044
GPIOA_PDDR: .word 0x400ff014
GPIOA_PDIR: .word 0x400ff010
GPIOA_PTOR: .word 0x400FF00C
GPIOA_PCOR: .word 0x400FF008
MCG_C1:     .word 0x40064000
TSIO_GENCS: .word 0x40045000
TSIO_PEN:   .word 0x40045008
TSIO_THRESHLD0: .word 0x40045120
TSIO_THRESHLD5: .word 0x40045134
TSIO_SCANC:  .word 0x40045004
TSIO_CNTR1:  .word 0x40045100
TSIO_CNTR5:  .word 0x40045108

          .global main
main:
      LDR R10,VAL5
      LDR R5,GPIOA_PDIR
      LDR R6,GPIOA_PDDR
      LDR R7,GPIOA_PTOR
      LDR R8,VAL3
      LDR R9,VAL3
      
      LDR R1,SIM_SCG5     // turn on clock for PORTA and TSI
      LDR R2,VAL2
      STR R2,[R1]
      
      LDR R1,PORTA_PCR17  // set MUX bit to a "1" to set PORTA_17 as GPIO ALT 1 and set DSE bit to a "1" for high drive strength  
      LDR R2,VAL1
      STR R2,[R1]
      
      LDR R1,PORTA_PCR4  //   
      LDR R2,VAL6
      STR R2,[R1]
      
      LDR R1,TSIO_PEN     
      LDR R2,VAL8
      STR R2,[R1]
      
      LDR R1,TSIO_THRESHLD0     
      LDR R2,VAL10
      STR R2,[R1]
      
      LDR R1,TSIO_THRESHLD5     
      LDR R2,VAL10
      STR R2,[R1]
      
      LDR R1,TSIO_SCANC
      LDR R2,VAL11
      STR R2,[R1]
      
again: LDR R1,TSIO_GENCS     
      LDR R2,VAL12
      STR R2,[R1]
      LDR R2,TSIO_CNTR5
      LDR R3,[R2]
      CMP R3,#0
      BNE again

0 Kudos

590 Views
mjbcswitzerland
Specialist V

Hi

 

Check that you have removed the pull-up resistors from the hardware otherwise things won't work.

 

Note that the threshold register is not actually used with this method - it is only used as varable for comparing the read value with to decide whether it is a press or not.

 

Check the amount of time that the touch sensor needs to complete its reading. I suspect that your polling loop is too fast - I just check once every 25ms or so (try a delay).

 

Regards

 

Mark

 

 

0 Kudos