Hello Community,

I want to access the Accelerometer sensor a thousand times a second and print the result on the console in a first step.

I configured the sensor with 500Hz Bandwidth and 16G.

To call the read function of the sensor I used a timer task with is called every 1 ms: See the code below:

TimerHandle_t timerHandle = xTimerCreate("AC", 1, pdTRUE, NULL, ACCallback);
xTimerStart(timerHandle, 0);
static void ACCallback(TimerHandle_t xTimer){
	(void) xTimer;
	CmdProcessor_enqueue(appCmdProcessor, readAc, NULL, 0);
}
static void readAc(void *param1, uint32_t param2) {
	(char *) param1;
	(int) param2;

	Accelerometer_XyzData_T bma280 = {INT32_C(0), INT32_C(0), INT32_C(0)};
	memset(&bma280, 0, sizeof(Accelerometer_XyzData_T));
	returnValue = Accelerometer_readXyzGValue(xdkAccelerometers_BMA280_Handle, &bma280);

	if(RETCODE_OK == returnValue) {

		unsigned long milliSeconds = ((unsigned long)(xTaskGetTickCount()) / portTICK_RATE_MS) % 1000;
		unsigned long time = (unsigned long) GetUtcTime();
		//printf - Statement
	}
}

Can you please help me to increase the performance.

 

I also want to use other sensors. I know that the I2C bus is limiting the overall data transfer. How can I access the other sensors. Also with a timer task?

 

Thank you

 

Ismail

0 (0 Votes)
RE: Call of Accelerometer 1000 times per Second
Answer
11/14/17 2:37 PM as a reply to Ismail Tufan.

Hello Ismail,

with your current application, you have a situation where every reading of the accelerometer sensor is put through a number of functions before it is actually executed. To make this faster, change the setup from Timer -> CmdProcessor to just a task. Using a task which loops forever, doing nothing but calling readAc(). This will have the advantage that you have this one task calling readAc() and nothing else going on besides that. For more information on tasks, please refer to the FreeRTOS Guide at xdk.io/guides.

Another optimization would be to change:

Accelerometer_XyzData_T bma280 = {INT32_C(0), INT32_C(0), INT32_C(0)};
memset(&bma280, 0, sizeof(Accelerometer_XyzData_T));

to

static Accelerometer_XyzData_T bma280 = {INT32_C(0), INT32_C(0), INT32_C(0)};

For one, you don't have to use memset at all, since you initialize the data with 0-values anyway.

And secondly, initializing the variable every time is not neccessary, which is why static comes in handy. This lets the application initialize the data-struct only once and reuse it with every call of the function. This may not be much, but it might slightly reduce delay.
 

Adding other sensor should be similar to the accelerometer. You can find codes, examples and explanation for all the sensors (except the acoustic sensor) in the Sensor Guide at xdk.io/guides.

Please tell me if this was helpful, and do not hesitate to ask further questions.

Kind regards,
Franjo

0 (0 Votes)
RE: Call of Accelerometer 1000 times per Second
Answer
11/15/17 4:17 PM as a reply to Franjo Stjepandic.

Hi Franjo,

thank you very much for your help. Helped me a lot and it is much appreciated.

Ismail

0 (0 Votes)
RE: Call of Accelerometer 1000 times per Second
Answer
11/16/17 2:27 PM as a reply to Ismail Tufan.

Hello Ismail,

I am always glad to help.

Feel free to ask further questions at any time.

Kind regards,
Franjo

0 (0 Votes)