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

Arduino Due Interrupt Problems using RTOS

Posted by Santhosh on August 24, 2013
Hello All,

I'm able to run three different tasks using RTOS but have problems when i have to Blink an Led on an interrupt.The LED blinks with interrupts perfectly fine without the RTOS.When i introduce the task with interrupts none of the other tasks work ,the interrupt first triggers once the code is loaded and all the other tasks freeze .When i disable the task with interrupts the other tasks work fine .I guess there's an issue on the software side ,i have posted the code please let me know where i'm going wrong .

 #include 
#include

Servo servo;
#undef F
#define F(str) str

float temp=0;
float val=0;

int in1Pin = 22;
int in2Pin = 23;
int state=LOW;
int interuptpin=24;

xSemaphoreHandle sem=NULL;

static void CriticalTask(void *pvParameters) {

portTickType xLastWakeTime;

xLastWakeTime = xTaskGetTickCount();

for (;;) {

vTaskDelayUntil( &xLastWakeTime,20);

analogReadResolution(10);
val=analogRead(A0);
temp = ( 3.3 * val * 100.0) /1024;

if(temp>20.00)
{

digitalWrite(in1Pin,HIGsH);
digitalWrite(in2Pin,LOW);

}
else
{
digitalWrite(in1Pin,LOW);
digitalWrite(in2Pin,LOW);

}

}
}


static void ServoMotor(void *pvParameters) {

servo.attach(9);

for (;;) {
servo.write(90);

vTaskDelay((1000L * configTICK_RATE_HZ) / 1000L);

servo.write(0);

vTaskDelay((1000L * configTICK_RATE_HZ) / 1000L);

}
}

static void vLEDFlashTask(void *pvParameters) {
pinMode(13, OUTPUT);

// Flash led every 200 ms.
for (;;) {
// Turn LED on.
digitalWrite(13, HIGH);

// Sleep for 50 milliseconds.
vTaskDelay((50L * configTICK_RATE_HZ) / 1000L);

// Turn LED off.
digitalWrite(13, LOW);

// Sleep for 150 milliseconds.
vTaskDelay((150L * configTICK_RATE_HZ) / 1000L);
}
}

static void LedTurnOn(void *pvParameters) {
pinMode(25, OUTPUT);
for (;;) {

xSemaphoreTake(sem,5);

state = !state;
digitalWrite(25,state);

}
}

void InteruptHandler()
{
static signed portBASE_TYPE xHigherPriorityTaskWoken;
xHigherPriorityTaskWoken = pdFALSE;
Serial.println("\n Inside Interrupt");
xSemaphoreGiveFromISR(sem,&xHigherPriorityTaskWoken);

}


void setup() {

Serial.begin(9600);

pinMode(in1Pin, OUTPUT);
pinMode(in2Pin, OUTPUT);
pinMode(interuptpin,INPUT);

attachInterrupt(interuptpin,InteruptHandler,CHANGE);

sem = xSemaphoreCreateCounting(1, 0);

/* xTaskCreate(ServoMotor,
(signed portCHAR *)"ServoTask",
configMINIMAL_STACK_SIZE + 50,
NULL,3,NULL);*/

xTaskCreate(vLEDFlashTask,
(signed portCHAR *)"Blinker",
configMINIMAL_STACK_SIZE + 50,
NULL,
1,
NULL);


/*xTaskCreate(CriticalTask,
(signed portCHAR *)"Critical task",
configMINIMAL_STACK_SIZE + 50,
NULL,
4,
NULL); */


xTaskCreate(LedTurnOn,
(signed portCHAR *)"Working With Interrupt",
configMINIMAL_STACK_SIZE + 50,
NULL,
2,
NULL);
noInterrupts();
vTaskStartScheduler();
interrupts();
}

void loop() {
// put your main code here, to run repeatedly:

}

RE: Arduino Due Interrupt Problems using RTOS

Posted by Richard on August 24, 2013
A quick scan of your code does not show anything obviously wrong - if the application was running 'bare metal' (say using Atmel Studio rather than the Arduino IDE), but I'm not familiar with the internal workings of the Arduino system. There could be a start up code issue perhaps, or a clash between a resource used by FreeRTOS and a resource used by Arduino, or even a problem because it is C++.

However, in this case you are starting the scheduler from the setup() function. If doing that is appropriate and the call passes then nothing past vTaskStartScheduler() will be called because the tasks will be running, meaning your call to interrupts() will never be executed, loop() will never be executed, and the internal Arduino polling scheduler will never execute.

If you wanted loop() to be executed you could put it in the idle task hook.

You could alternatively switch to Atmel Studio, the ASF Wizard has a FreeRTOS project that targets the Duo hardware.

Regards.

RE: Arduino Due Interrupt Problems using RTOS

Posted by Santhosh on August 25, 2013
I had read through the couple of forum posts stating that the interrupts must not be triggered at the start of the scheduler , so i disabled interrupts .usually the call to interrupts will not be reached once the tasks are in place .


[ 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