Hi,

I am using the following code to print "hello world" for one second with a period of 1 milli second. So in theory, there should be 1000 hello worlds printed.

   

#define TIMERBLOCKTIME UINT32_C(0Xffff)
#define TIMER_AUTO_RELOAD_ON pdTRUE
#define MILLI_SECOND(x) ((portTickType) (x)/portTICK_RATE_MS )

applicationTimer = xTimerCreate((char* const) "Application to print hello world",

      MILLI_SECOND(1),
   TIMER_AUTO_RELOAD_ON,
   NULL,
   helloWorld);
    xTimerStart(applicationTimer,TIMERBLOCKTIME);
    vTaskDelay(1000);
    xTimerStop(applicationTimer,TIMERBLOCKTIME);

 

but it seems the xTimerStop is not able to stop applicationTimer and it keeps on printing hello world infinte time. Where as if I put time period as 2 or more milli_second, it works absolutely fine.
Can anyone help me with this?

0 (0 Voti)
RE: Why xTimerStop handler is not able to stop timer handler
Risposta
30/07/19 13.29 come risposta a Ankit Chanda.

Hello Ankit Chanda,

Regarding the timer period:

If the timer must expire after 1000 ticks, then simply set xTimerPeriod to 1000. Alternatively, if the timer must expire after 1000ms, then set xTimerPeriod to pdMS_TO_TICKS( 1000 ).  pdMS_TO_TICKS() can only be used if configTICK_RATE_HZ  is less than or equal to 1000. configTICK_RATE_HZ is defined in FreeRTOSConfig.h under xdk110/Common/config/AmazonFreeRTOS/FreeRTOS/FreeRTOSConfig.h

0 (0 Voti)
RE: Why xTimerStop handler is not able to stop timer handler
Risposta
31/07/19 15.38 come risposta a Padmapriya G.

Hi Padmapriya,

If I set the xTimerPeriod to 1000ms, it would print helloworld every 1 second. But what I want is to print helloworld every 1 millisecond for a total period of 1 second. Hence, I stop the timer after 1 second. Basically, My target is to get acceleration data at a sampling rate of 1000. So, this one is a simpler version. Its easier to implement in MITA. 
But I dont know, how shall I ipmlement this timer task. Because if I use the command every 1 millisecond, then it will loop infinitely. For example; the following code

package main;
import platforms.xdk110;
setup XDK110 {
 applicationName = "SDTest"; 
 startupDelay = 5000;  
}
setup sd : SDCard {
 var writer : string = appendingTextWrite("CollectedData.csv");
}
setup accelerometer {
    bandwidth = BW_500Hz;
    range = Range_8G;       // 8G range convienently does not require a conversion into mg
}
setup led : LED {
 var red : bool = light_up(Red);
}
every XDK110.startup{
 led.red.write(true);
}

 
every 1 milliseconds {
 var z = accelerometer.z_axis.read();
 sd.writer.write(`${z}\n`);
}

What I want is to stop the every 1 milliseconds block after 1 second. But I dont know how to do that. 

0 (0 Voti)