5 Replies Latest reply on Nov 9, 2015 8:21 AM by userc_7511 Branched from an earlier discussion.

    FineTimer (Con't)

      Hello,

       

      Per this thread: FineTimer

       

      What would happen if I set a timer up as 2ms to read a pressure sensor. Basically I would be reading the pressure sensor (i2c) every 2 ms for approximately 2 seconds every couple of minutes? Think this is possible?

       

      I am trying to use the interrupt of the sensor but the timing seems to be out by up to 800us  worse case between samples and it is very important that I have the correct time for each data sample.

       

      Regards,

      Luke.

        • 1. Re: FineTimer (Con't)

          llynch

          If you are not in connection and not advertising, why not just forget about the 2ms timer and just read your sensor in a loop for 2 seconds, petting the watchdog each iteration in the loop. Between sensor reads you can call a function to wait so many microseconds, or you can read the realtime clock and begin the next sensor read each time the clock delta reaches 2ms.  I don't know the size of your data sample, but assuming 4 bytes, you should be able to find enough memory to buffer 1000 samples collected and then transmit them 4 at a time in a 20 byte characteristic to the client over a period of a few seconds.  This sounds like it should work.

          • 2. Re: FineTimer (Con't)

            userc_7511

            So you are suggesting when I would like read my sensor, drop the Bluetooth connection, take my reading for so many seconds then reconnect and send the data?

             

            And when i am reading the sensor you are suggesting to run in a loop for so any seconds and have a delay/wait between each read to set a sampling rate?

             

            When it comes to the wait/delay, timer, interrupts what would be the best way to control reading my sensor?

             

            Thanks,

            Luke.

            • 3. Re: FineTimer (Con't)

              Also how do you pet the watchdog?

              • 4. Re: FineTimer (Con't)
                MichaelF_56

                Application software must occasionally kick (or "pet") the watchdog to demonstrate things are still working properly.

                 

                This thread provides a basic example of turning the watchdog on and off: How to use Watchdog on Wiced smart SDK 1.1

                • 5. Re: FineTimer (Con't)

                  #include "cfa.h"

                  // This function will pet the watch dog.

                  cfa_kickWatchdog();

                   

                  Do you have a part number for the sensor? (To look at the datasheet for communication options).

                  Receiving sensor data on interrupt is the best method.

                  It might be easier to start with polling the device.

                   

                  Here is a way to wait so many microseconds or milliseconds, in case you find it useful.

                  I use a #define to make it easier to remember but you can just call the function directly:

                  #define WAIT_uS(n)   { bleapputils_delayUs( n );}

                  #define WAIT_MS(t)   { bleapputils_delayUs( t*1000 );}