Capacitive touch sensing on HC08

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

Capacitive touch sensing on HC08

1,715 Views
Tryhard
Contributor I

NXP Comm,

I trying to do touch sensing and simply glow an LED on touch. I am using a MC9S08PT16 controller. I am attaching the link to the datasheet for your reference. Following it, is my code.

Reference Manual (Touch is on page 517): https://www.nxp.com/docs/en/reference-manual/MC9S08PT16RM.pdf

Series Datasheet(Figure 23 is what's relevant): https://www.nxp.com/docs/en/data-sheet/MC9S08PT16.pdf

Code:

interrupt VectorNumber_Vtsi void TSI_ISR() {
TSI_CS0_EOSF = 0;
TSI_CS0_SWTS = 0;
if (TSI_CNT == 0xFFFF)
TSI_CNT |= 0;
LED_RED ^= 1;
}

void InitTSI() {

PORT_PTAIE = 0x00 | PORT_PTAIE_PTAIE6_MASK;
PORT_PTAOE = ~PORT_PTAIE;
PORT_PTAPE = 0x00;
PORT_PTAD = 0x00;

TSI_CS0_TSIEN |= 1;
TSI_CS0_TSIIEN |= 1;
TSI_PEN0_PEN0 = 0x00 | TSI_PEN0_PEN0_MASK;
TSI_CS3_TSICH = 0x00 | TSI_CS3_TSICH0_MASK;
TSI_CS0_STPE |= 1;
TSI_CS1_PS = 0x101;
TSI_CS2_EXTCHRG = 0x100;
TSI_CNT |= 0;
TSI_CS1_NSCN = 0x11111;

}

void main(void) {
int temp;
EnableInterrupts;
clock_config();
system_config();

/*include your code here */
PORT_PTDIE = 0x00;
PORT_PTDOE = ~PORT_PTDIE;
PORT_PTDPE = 0x00;
PORT_PTDD = 0x00;

InitTimer1MsTick();
wdog_disable();

InitTSI();

while (1) {

// TSI_CS0_SWTS |= 1;

if(TSI_CS0_SCNIP == 1);
temp = TSI_CNT;
TSI_CS0_EOSF = 0;
}
}

The understanding I have of touch is that, when there is touch detected, the interrupt flag is set and goes into the ISR automatically. But whats happening is, TSI_CS0_SWTS register is triggering the interrupt, in the datasheet it says its the register that starts the scan again, not sure how its linked to interrupts, because scans are just the 16 bit counter running up and down is what I've understood. Also, one more thing that I didn't understand was the difference between a port and a channel. The touch port is on A6, it mentions in the datasheet as TO1, so I initialized the port and channel both to Zero. I'm pretty sure I've had some misunderstandings with the datasheet. This is my first post on here, just registered !

0 Kudos
4 Replies

1,676 Views
ss114
Contributor I

Hi Team,

I am trying to implement capacitive touch read on MC9S08PT16. I followed the datasheet and reference manual for writing code.

I am not understanding when I touch how to read on the TSI0 pin.

can you give a sample code for reading capacitive touch read code?

my code is

void Init_touch1(void){
TSI_CS0_TSIEN |= 1;//enable TSI Module
TSI_CS0_TSIIEN |= 1;//enable interrupt,when scanning complete,generate a interrupt
//TSI_CS0_EOSF = 0;
TSI_PEN0 = 0x0f;//// enable TSI electrode 0 ~ 4
//TSI_CS3_TSICH |= TSI_CS3_TSICH0_MASK;
TSI_CS0_STPE |= 1;// enable TSI module in Stop mode for low-power
TSI_CS1_PS |= 010;//configure prescaler to 4
TSI_CS0_STM = 0;
TSI_CS2_REFCHRG = 0x04;//
TSI_CS2_DVOLT = 0x01;//
TSI_CS2_EXTCHRG = 0x04;//
TSI_CS1_NSCN = 0x0f;
}
void Touch_startscan(void){

TSI_CS3_TSICH=0001;
TSI_CS0 |=0x01;

}

 

Please share me one sample code or any link?

Tags (2)

1,667 Views
vicentegomez
NXP TechSupport
NXP TechSupport

I recomend you that you use the TSS library it has some examples and you can find it on the next link

https://www.nxp.com/design/sensor-developer-resources/touch-sensing-software:TSS

 

Also you can check the tower pt60 labs on the next link

https://www.nxp.com/docs/en/supporting-information/TWRS08PT60LAB.pdf

 

https://www.nxp.com/docs/en/supporting-information/TWR-S08PT60-LABS.zip

 

I hope this will help you

 

Regards

 

0 Kudos

1,636 Views
Tryhard
Contributor I

Hello Vicente,

Wow alot of people seem to be working on the TSI nowadays ! 

The examples were quite helpful, thank you, I did modify the code similar to that, I didnt seem to find any change in the output when touched.

Below is the code,

void InitTSI() {
//TSI Count - 320
PORT_PTAIE = 0x00 | PORT_PTAIE_PTAIE6_MASK | PORT_PTAIE_PTAIE7_MASK;
PORT_PTAOE = ~PORT_PTAIE;
PORT_PTAPE = 0x00;
PORT_PTAD = 0x00;

TSI_CS0_TSIEN |= 1;
TSI_CS0_TSIIEN |= 1;
TSI_CS0_EOSF = 0;
TSI_PEN0 |= 0xFF;
TSI_PEN1 |= 0xFF;
TSI_CS0_STPE |= 1;
TSI_CS1_PS |= 0b011;
TSI_CS0_STM = 0;
TSI_CS2_REFCHRG |= 0b011;
TSI_CS2_EXTCHRG |= 0b111;
TSI_CS1_NSCN |= 0b11111;
start = TSI_CNT;
}

interrupt VectorNumber_Vtsi void TSI_ISR() {

}

void main(void) {
EnableInterrupts;
clock_config();
system_config();

/*include your code here */
PORT_PTDIE = 0x00;
PORT_PTDOE = ~PORT_PTDIE;
PORT_PTDPE = 0x00;
PORT_PTDD = 0x00;

InitTimer1MsTick();
wdog_disable();

InitTSI();

while (1) {
TSI_CS3_TSICH |= TSI_CS3_TSICH0_MASK;

TSI_CS0_SWTS = 1;
while(!TSI_CS0_EOSF)
{
TSI_CS0_EOSF = 1;
end = TSI_CNT;
}
if(end - start > 0) {
LED_RED = 1;
__delay_ms(500);
LED_RED = 0;
__delay_ms(500);

end = 0;
}

}

}

Could you tell me what I am doing wrong ? I'm unable to understand what is wrong, (end - start) should be non-zero after touched, is what my understanding is, but it is zero. If there is a developer/senior engineer you could get me in contact with, that would be great Vicente. We could resolve this ticket asap

0 Kudos

1,688 Views
vicentegomez
NXP TechSupport
NXP TechSupport

Hi

When the device is on the TSI interrupt the MCU is only performing the interrupt task.

to start a new scan you need to put the STM bit to 0 (software trigger) and put the SWTS to 1

if you do not change the  TSICH you will scan the same pin channel. if you set the STM = 0 and the SWTS =1 in the interrupt the mcu will start the scan while you are in the interrupt, if you stay too long in the interrupt you can miss one touch during the scan or just once you to go out the interrupt it will set again and you will enter again to the interrupt.

Now the ports are A, B, C ... that normally are used when you use the GPIO function 

the TSI channel is the channel that you set on the TSICH the number of channels for the TSI module, for instance using the  MC9S08PT16 20-pin SOIC and TSSOP package

the TSI channel 9 is on the pin 9. this pin also is the PTC3 port C number 3, also is the FTM2 channel 3

FTM module 2 channel 3.

 

I hope this is clear

 

 

 

0 Kudos