Invoking timers after certain seconds
Hello,
I want to invoke my timer after exactly 2 sec
Folloing is the configuration in freeRTOSConfig.h
~~~
Invoking timers after certain seconds
Sorry for the apparent delay in replying – for some reason my replies via email are not showing up at the moment. My original replay suggested checking that the tick interrupt is executing at the speed you think it is. That can be done very crudely by writing a task that does nothing but toggle an LED every five seconds, then time (using a stopwatch) ten toggles to check it is approximately 50 seconds:
~~~
void vTask( void pvParameters )
{
for( ;; )
{
vTaskDelay( pdMS_TO_TICKS( 5000UL );
toggle_led(); / You will have to write this. */
}
}
~~~
Invoking timers after certain seconds
For what I am observing,
If i use
~~~
const TickTypet xTicksToWait = pdMSTO_TICKS(2000);
~~~
The timer startsafter every 400ms. To do this I am multiplying it with my desired time with 5 and now it opens after every 2 seconds. Is this has to do something with clock frequency.
Invoking timers after certain seconds
Almost certainly the tick frequency is wrong.
Invoking timers after certain seconds
From, where do you change this tick frequency.?
Invoking timers after certain seconds
Hey here is my code
~~~
/************************************************************************
* DESCRIPTION: Main entry point of the FreeRTOS shell demo.
************************************************************************/
int ulCallCount=0;
define mainAUTORELOADTIMERPERIOD pdMSTO_TICKS(2000)
static void prvAutoReloadTimerCallback( TimerHandlet xTimer ) { TickTypet xTimeNow; /* Obtain the current tick count. / xTimeNow = xTaskGetTickCount(); / Output a string to show the time at which the callback was executed. / print( “Auto-reload timer callback executing %d n”, xTimeNow ); ulCallCount++; } void fapp_main_freertos( void ) { if(xTaskCreate( fapp_task, / pointer to the task / “fapp_Task”, / task name for kernel awareness debugging / FAPP_CFG_FREERTOS_TASK_STACK_SIZE/sizeof(portSTACK_TYPE), / task stack size / NULL, / optional task startup argument / 3, / initial priority / NULL / optional task handle to create / ) != pdPASS) { fnet_println(“[FREERTOS] Failed to create task fapp_task.”); / Probably out of memory */ } else
{
/* Attempt to create the event group. */
fapp_freertos_event_group = xEventGroupCreate();
/* Was the event group created successfully? */
if( fapp_freertos_event_group == NULL )
{
/* The event group was not created because there was insufficient heap available. */
fnet_println("[FREERTOS] Failed to create event group.");
}
else
{
/* Registers the "socket layer activity" event handler.*/
fnet_socket_set_callback_on_rx(fapp_socket_rx_callback);
fnet_println("[FREERTOS] Starting scheduler.");
TimerHandle_t xAutoReloadTimer;
BaseType_t xTimer1Started;
/* Create the auto-reload timer, storing the handle to the created timer in xAutoReloadTimer. */
xAutoReloadTimer = xTimerCreate(
/* Text name for the software timer - not used by FreeRTOS. */
"AutoReload",
/* The software timer's period in ticks. */
mainAUTO_RELOAD_TIMER_PERIOD,
/* Setting uxAutoRealod to pdTRUE creates an auto-reload timer. */
pdTRUE,
/* This example does not use the timer id. */
0,
/* The callback function to be used by the software timer being created. */
prvAutoReloadTimerCallback );
if(( xAutoReloadTimer != NULL ))
{
/* Start the software timers, using a block time of 0 (no block time). The scheduler has
not been started yet so any block time specified here would be ignored anyway. */
xTimer1Started = xTimerStart( xAutoReloadTimer, 0 );
if(( xTimer1Started == pdPASS ))
{
fnet_println("[FREERTOS] Starting scheduler.");
vTaskStartScheduler();
}
}
/* The code should never reach here. */
}
}
/* The code should never reach here. */
}
endif /* FAPPCFGFREERTOS */
~~~ As, you can see. I am creating an autorelaod timer with 2000ms delay. But instead its running after 400 ms . The config tick frequeny is set to 200. increasing tick frequency is not helping me. Please tellme whats wrong. ThanksInvoking timers after certain seconds
I have changed the macro to
~~~
//PDMS to TICKS MACRO
ifndef pdMSTOTICKS
define pdMSTOTICKS( xTimeInMs ) ( (( TickTypet ) ( ( ( TickTypet ) ( xTimeInMs ) * ( TickTypet ) configTICKRATEHZ * ( TickTypet )5) / ( TickType_t )1000)) )
endif
~~~Invoking timers after certain seconds
After that its working fine
Invoking timers after certain seconds
Not sure I’m following, but it looks like you fixed the symptom rather
than the cause, so the cause will still exist. As per previous posts,
it looks like time is not passing at the frequency you think it is, and
you have changed how time is converted between ms and ticks to account
for that, rather than fix the time reading itself.
Invoking timers after certain seconds
Yes, thats true. Can you tell me whats the cause behind it. I cant understand the CAUSE The board is frdm k64
Invoking timers after certain seconds
You need to be 100% sure of the frequency of the clock that is feeding
the SysTick timer on your MCU, then set the constant configCPUCLOCKHZ
to that frequency in FreeRTOSConfig.h – not the frequency that feeds the
timer may be divided down from the frequency at which the rest of the
core executes.
You can then test very crudely by having a single task that does nothing
but toggle an LED every second, and time 60 toggles using a stopwatch.
If the timing is correct, then the stop watch you say one minute at the
end – plus or minus whatever your reaction time is hitting the stopwatch
button. Just something like this is fine if there is only one task:
void vTest( void *pvParameters ) { /* Using unmodified pdMS_TO_TICKS() macro* / const TickType_t xPeriod = pdMS_TO_TICKS( 1000 ); for( ;; ) { vTaskDelay( xPeriod ); ToggleLED(); /* write this yourself */ } }