Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

changing tick frequency

Posted by kyromaster on March 30, 2016

I'm rather new to FreeRTOS and I have a problem. I'm using an atmega328p with FreeRTOS 8.3.2. with 16MHz and 1000 ticks per second. All my delays are like (x / portTICKPERIODMS) where x is the delay in ms. But when I lower the tick value, e.g. to 100 ticks per second, everything runs much faster. I've read some topics about tick timing but I'm still not sure what's wrong here. Can you help me? Thanks a lot :)


changing tick frequency

Posted by davedoors on March 30, 2016

8.3.2

guess you mean 8.2.3

(x / portTICKPERIODMS)

Use pdMSTOTICKS(x) instead.

The tick frequency can only be changed at compile time. If you use the pdMSTOTICKS or portTICKPERIODMS macros for all timing then you should be good for tick speeds up to 1KHz.


changing tick frequency

Posted by kyromaster on March 30, 2016

I tried with a very small example:

~~~~

include "Arduino.h"
include "arduinofreertoscompatibility.h"
include "digitalflip.hpp"
define LED_PIN 13

void blinkThread(void* arg) {

while (true) {
	ARDUINO_START();
	digitalFlip(LED_PIN);
	ARDUINO_END();
	vTaskDelay(pdMS_TO_TICKS(1000));
}

}

int main() { init(); initVariant();

if defined(USBCON)
USBDevice.attach();
endif
Serial.begin(9600);
pinMode(LED_PIN, OUTPUT);
Serial.println(F("Creating blink thread"));
if (xTaskCreate(blinkThread, NULL, configMINIMAL_STACK_SIZE * 2, NULL, 2, NULL) != pdPASS) {
	Serial.println(F("Couldn't create blink thread"));
	exit(-1);
}
Serial.println(F("Setup finished, starting FreeRTOS scheduler"));
vTaskStartScheduler();

} ~~~~

this should blink 1 time per second, but blinks much faster.


changing tick frequency

Posted by rtel on March 30, 2016

I'm afraid I'm not familiar with using FreeRTOS in an Arduino environment, perhaps the following post will help? http://interactive.freertos.org/entries/109124706-Arduino-AVR-FreeRTOS


changing tick frequency

Posted by kyromaster on March 30, 2016

the ARDUINOSTART() and ARDUINOEND() macros disable and enable the scheduler. that's what I found as recommendation. strange thing is that when I change to:

~~~~ void blinkThread(void* arg) {

while (true) {
    ARDUINO_START();
    digitalFlip(LED_PIN);
    ARDUINO_END();
    vTaskDelay(1000);
}

} ~~~~ everything works fine. so I guess there's something wrong with the pdMSTOTICKS macro. I configured freertos with:

~~~~

define configCPUCLOCKHZ ( ( unsigned long ) F_CPU )
define configTICKRATEHZ ( ( TickType_t ) 1000 )

~~~~


changing tick frequency

Posted by rtel on March 30, 2016

Its possible you are simply getting a numeric overflow as it is likely your tick count value is only 16-bits. You could set configUSE16BIT_TICKS to 0 in FreeRTOSConfig.h, which will then make the ticks 32-bit, at some processing overhead expense as you only have an 8-bit device.

Also, try declaring a const variable that has the delay you need, then you will see what the value actually is. Also it will be more efficient as the pdMSTOTICKS() macro will only evaluate once, rather than each time you call vTaskDelay().


changing tick frequency

Posted by kyromaster on March 30, 2016

I changed configUSE16BIT_TICKS to 0. and the function to:

~~~~ void blinkThread(void* arg) {

while (true) {
	const TickType_t delayInTicks = pdMS_TO_TICKS(1000);
	Serial.println(delayInTicks);
	vTaskDelay(delayInTicks);
}

} ~~~~ I get the correct number, e.g. 1000 with 1000 ticks per second and 100 with 100 ticks per second. but the loop speed is still faster the less ticks I have per second. With 1000 ticks the timing is right, also in other projects. If it helps I can upload the project as an AVR Studio solution.

Attachments


changing tick frequency

Posted by kyromaster on March 31, 2016

would be nice if someone could test the attached project


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists