- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I have a capsense project working on PSOC 4200M and I have used the example code. Now I want to make the code work as an interrupt so that I can run a program in my main for loop and change modes when the capsense triggers. I have no idea how to do that. Can anyone help with example code?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello MaHi_2791116
You cannot configure the CapSense component to trigger an interrupt (Hardware based interrupt) whenever a touch is detected. This is due to the fact that the touch status (whether there is a button press on the sensor or not) is determined by the CPU. You can trigger a software interrupt however, but I don't believe that is your intention.
The CapSense component will trigger an interrupt whenever the scan is complete and callback functions can be defined to check the status as soon as scan is complete. You can configure a timer to scan the sensor periodically and this interrupt can be used to monitor the status of the sensor.
Best regards
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello MaHi_2791116
You cannot configure the CapSense component to trigger an interrupt (Hardware based interrupt) whenever a touch is detected. This is due to the fact that the touch status (whether there is a button press on the sensor or not) is determined by the CPU. You can trigger a software interrupt however, but I don't believe that is your intention.
The CapSense component will trigger an interrupt whenever the scan is complete and callback functions can be defined to check the status as soon as scan is complete. You can configure a timer to scan the sensor periodically and this interrupt can be used to monitor the status of the sensor.
Best regards
Hari
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Awesome thanks for the help. I can do a software interrupt. Basically I
have a for loop with a switch statement:
switch(mode){
case 1:
flash();
break;
case 2:
circle();
break;
}
I want to make it that when the capsense is "pressed" ie like a hardware
button change the mode. I dont care how I do it.
Problem is that currently with the capsense code in the main for loop with
my switch mode cases it just locks up and nothing works - capsense or the
flashing led
Have you got any sample code I could use?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MaHi_2791116
The CapSense scanning code still needs to be present in the for loop. The execution is not blocking. You can check the switch condition without waiting for CapSense scan. An example is as shown:
for(;;)
{
/* Place your application code here. */
if(!CapSense_IsBusy())
{
CapSense_ProcessAllWidgets();
if(CapSense_IsWidgetActive(CapSense_BUTTON0_WDGT_ID))
{
mode |= 0x0F;
}
else
{
mode &= 0xF0;
}
if(CapSense_IsWidgetActive(CapSense_BUTTON1_WDGT_ID))
{
mode |= 0xF0;
}
else
{
mode &= 0x0F;
}
CapSense_ScanAllWidgets();
}
switch (mode)
{
case 0x0F:
flash();
break;
case 0xF0:
circle();
break;
case 0xFF:
flash();
circle();
break;
default:
break;
}
}
Please let us know if this implementation can work for you.
Best regards
Hari