Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


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 ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

NXP tweet showing LPC5500 (ARMv8-M Cortex-M33) running FreeRTOS.

Meet Richard Barry and learn about running FreeRTOS on RISC-V at FOSDEM 2019

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

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

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

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner