Pages: [1]   Go Down
Author Topic: Arduino Due Interrupt Problems using RTOS  (Read 1138 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 .

Code:
#include <FreeRTOS_ARM.h>
 #include <Servo.h>
 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;

/* critical Task */

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);
     
     }
       
  }
}

/* Medium Priority Task */

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);
 
  vTaskStartScheduler();
 
}

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

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any solution for this problem ? , this was put up in freertos forum and the response was below https://sourceforge.net/projects/freertos/forums/forum/382005/topic/8647858
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I read just now your post.
Make me a flavour, could you rewrite your code without the servos library (and his function)??
Then check if it runs.

I suppose there is a conflict between FreeRTOS and Servo library
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, sanpai,

Did you solved this problem?
I'm also having problem with FreeRTOS freeze on Due.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again,
please: if you are using a servo library (just declared) try to remove it.
I m quite sure there is a bug but I need your help to find it out.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 11
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Again,
please: if you are using a servo library (just declared) try to remove it.
I m quite sure there is a bug but I need your help to find it out.

Unfortunately, I tried to use AccelStepper, not Servo, like original poster.
Quite possible I will have to write my own step motor library optimized for FreeRTOS / Due.
Logged

Pages: [1]   Go Up
Jump to: