FineTimer (Con't)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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.

0 Likes
5 Replies
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

ehoffman

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.

0 Likes
Anonymous
Not applicable

Also how do you pet the watchdog?

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

0 Likes
Anonymous
Not applicable

#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 );}

0 Likes