3 Replies Latest reply on May 4, 2020 9:57 PM by AH_96

    Efficiently Reading Raw Counts from a CapSense Touchpad widget

    JeSi_4326976

      Hi,

      I am using CSX touchpads in my projects as they are the only ones who are immune to ghost touches (unlike CSD touchpads, correct me if I'm wrong).

       

      In order to retrieve a full map of where the touchpad touches are applied, similarly to the touchpad map tap in the capsense tuner GUI, I retrieve the raw counts of each sensor individually. This works great, but the way APIs are built, I cannot iterate efficiently through all the sensing elements. I have to write the same function for every element:

      CapSense_GetParam(CapSense_TOUCHPAD0_RX0_TX0_RAW0_PARAM_ID, &taxel_raw_values[curr_elem]);

      CapSense_GetParam(CapSense_TOUCHPAD0_RX0_TX1_RAW0_PARAM_ID, &taxel_raw_values[curr_elem]);

      etc...

       

      my last project was a 5x5 touchpad, so typing everything wasn't so bad, but my next one will be 7x7, so this would mean a ridiculously long and ugly code. Is there a way to iterate through all of the elements in a clean way like a for loop? I have something like this in mind:

       

      for(int i = 0; i < nbElements; i++)

           CapSense_GetParam(CapSense_TOUCHPAD0_`i points to the right ID macro at each loop`_RAW0_PARAM_ID, &taxel_raw_values[i]);

       

       

      Or another option, which I don't really like as it wastes memory, would be to map the ID macro values in an array:

       

      ulong elements_IDs[TAXELS_NB];

       

      elements_IDs[0] = CapSense_TOUCHPAD0_RX0_TX0_RAW0_PARAM_ID;

      elements_IDs[1] = CapSense_TOUCHPAD0_RX0_TX1_RAW0_PARAM_ID;

       

      Then I can just iterate through elements_IDs when reading.

       

      Is there a better way to do this? Thanks for your help!!

        • 1. Re: Efficiently Reading Raw Counts from a CapSense Touchpad widget
          AH_96

          Hi JeSi_4326976

           

          You can access the raw counts through the dsRam structure. The code for this would be:

          raw = CapSense_dsRam.snsList.touchpad0[index].raw[FreqIndex];

           

          Note that FreqIndex, the index at the end is if MFS is enabled to read the raw counts of each individual frequency. The one that is applicable for you would be "index". There are rows*cols number of memory allocated and you can easily loop through them.

           

          Please make sure that the contents of the Ram structure are not modified.

           

          Do let us know if this helps...

           

          Thanks,
          Hari

          1 of 1 people found this helpful
          • 2. Re: Efficiently Reading Raw Counts from a CapSense Touchpad widget
            JeSi_4326976

            Hi AH_96,

             

            This is exactly what I was looking for! Thank you so much

             

            I just need a few last guidelines. I read the sensors this way:

            uint elements_IDs[TAXELS_NB];

             

               for (int i = 0; i < TAXELS_NB; i ++)

                {

                    elements_IDs[i] = CapSense_dsRam.snsList.touchpad0[1].raw;

                }

             

            Then, I try reading one sensor element (#24, randomly picked) from UART to make sure I get correct and changing values

             

            UART_UartPutChar(elements_IDs[24]);

             

             

            1. I did not hear about multi-frequency scanning before. I have read the CE227719 – CapSense with MultiFrequency Scan example and I see it can be quite useful for countering noise! I just wonder what it means by:

            prevent false touch detection in the presence of external noise at a particular frequency

            I was just wondering if you had an example in mind of something that would generate noise at a given frequency, but not at another?

             

            2. I just wanted to make sure that my synthax for reading the raw counts is ok. PSoC creator gives me a warning for incompatible from pointer to integer conversion assigning to 'uint' from 'uint[16]'

             

            3. I am just starting to use PSoC 4, before I used PSoC 6 and used printf with the retargetIO library for my UART components. on PuTTY, my line UART_UartPutChar(elements_IDs[24]); doesn't print anything so I wanted to convert my UART putchar to an hex value, but I do not know how to do this with this API. I also cannot find the API list containing this function, I got it from the SCB_UartComm example. It seems like there is no peripheral driver library for psoc 4? Is There a way I can turn my putchar values to hex? And also, just in case, do you happen to know how to activate printing raw uart values on PuTTY or teraterm, and not just ASCII characters? (I cannot find anywhere online where they explain how to do it).

             

            Thank you so much for your help!

            • 3. Re: Efficiently Reading Raw Counts from a CapSense Touchpad widget
              AH_96

              Hi JeSi_4326976,

               

              1. You can consider the simplest example as a communication happening within the system. Let us assume that you have a consistent I2C communication occurring at 1MHz and your capsense is also configured at 1MHz. In that case, this noise will get coupled onto CapSense sensors and will appear as errors or false touches in application. In fact, it is not just the 1MHz. Any harmonics of this also contributes to this noise.

              There are practical scenarios where there will be noise from motor, induction coils etc where a hardware design might not give full immunity. The frequencies of scanning are chosen such that they are not harmonics and hence, this noise is eliminated.

               

              2. The syntax is not correct since CapSense_dsRam.snsList.touchpad0[1].raw is an array pointer that you are trying to assign to a variable. The correct syntax would be

              elements_IDs[i] = CapSense_dsRam.snsList.touchpad0[1].raw[0];

               

              3. The easiest way to do this is to use sprintf to load the message into a char array and print it as a string.

              char msg[10];

              sprintf(msg, "%d", elements_IDs[0]);

              UART_UartPutString(msg);

               

              Thanks,
              Hari