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. */
}
}
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.
/************************************************************************
* DESCRIPTION: Main entry point of the FreeRTOS shell demo.
************************************************************************/
int ulCallCount=0;
#define mainAUTO_RELOAD_TIMER_PERIOD pdMS_TO_TICKS(2000)
static void prvAutoReloadTimerCallback( TimerHandle_t xTimer )
{
TickType_t 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 /* FAPP_CFG_FREERTOS */
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. Thanks
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.
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 configCPU_CLOCK_HZ
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: