-1

I'm reading some data on ADC channels on dsPIC30F6014A. For that I have implemented a separate task for each ADC(say 7 channels-7 tasks).
I have created all the tasks at the start only, My heap size is 5120, I'm using heap_4.c and I have allocated stack for each task is configMINIMAL_Stack(i.e. 115).
These tasks are running continuously and periodically(just vTaskSuspend() and vTaskResume() is what I'm doing)
At start all tasks are working fine but after some time vApplicationStackOverflowHook() occurs, i.e. stack gets overflowed.

Is there any possibility of wrong handling of memory?

user9993
  • 5,833
  • 11
  • 56
  • 117

1 Answers1

3

It would seem wasteful to create a task per ADC input. What else are the tasks doing other than reading the ADC?

I would guess your task is very close to the edge of its stack and at some point you happen to get an interrupt just when you are at the maximum stack depth and that causes an overflow. You can make periodic calls to uxTaskGetStackHighWaterMark() to determine how close to the end of the stack you have reached.

Richard
  • 3,081
  • 11
  • 9
  • The application is kind of safety application. And as for ADC sampling in PIC i'm polling DONE bit, so there is slight possibility of controller being stuck at polling. Which is why i have implemented different tasks. What if i just create and delete the task when ever needed???Will it free the memory occupied by the task so that i can assign that memory to another task????Thank you – Harry Wadkar Jun 22 '17 at 05:26
  • Dynamically allocating memory in a "safety application" is not recommended! As Richard stated it is probably an interrupt occuring and pushing the stack over the limit or there is a path through the task code that uses more stack than usual. In any case the simple solution is to increase the stack size (of each ADC task). The minimal stack size is probably not big enough for your requirements. That said if you could do this all in one task then you could have a bigger stack and still use considerably less memory (and better performance) – Realtime Rik Jun 22 '17 at 07:06
  • Thanks, i checked some time ago that which task is getting into hook() by printing pcTaskName on lcd and it shows "IDL", so now i bit confused that how ideal task uses that much stack(correct me if am wrong)??? Besides that my heap is 5120 so in that how many tasks i can create with how much minimum stack size???? and one more every time when I suspend a task and resumes another task will that occupy new memory every time?????Thank you. – Harry Wadkar Jun 22 '17 at 08:33