# How to monitor stack usage in a PIC24?

**URL:** <https://forums.freertos.org/t/how-to-monitor-stack-usage-in-a-pic24/2838>\
**Category:** Kernel\
**Created:** [March 15, 2010, 3:49pm UTC](https://forums.freertos.org/t/how-to-monitor-stack-usage-in-a-pic24/2838 "2010-03-15T15:49:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 15, 2010, 3:49pm UTC](https://forums.freertos.org/t/how-to-monitor-stack-usage-in-a-pic24/2838/1 "2010-03-15T15:49:03Z")

</div>

**[renald\_travis](https://sourceforge.net/u/renald_travis/)** wrote on [Monday, March 15, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/7dda1273/#9b98):

Hi everyone,  
I am a newbie to freeRTOS. I did a baseline software development for a project using freeRTOS on a microchip PIC24F.&nbsp; The system seems to be working fine with its current heap and stack values. I know that I just got lucky with my numbers. I would like to do a thorough stack and heap analysis as part of my optimization. First, I want to do a stack requirement analysis. Is there any demo code for the PIC24F processor that clearly tells me how to use pxCurrentTCB for the purpose? Also, How do I find out the amount of heap being used by my code?

I would really appreciate any help

Thanks!  
Sid

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [March 15, 2010, 4:00pm UTC](https://forums.freertos.org/t/how-to-monitor-stack-usage-in-a-pic24/2838/2 "2010-03-15T16:00:44Z")

</div>

**[davedoors](https://sourceforge.net/u/davedoors/)** wrote on [Monday, March 15, 2010](https://sourceforge.net/p/freertos/discussion/382005/thread/7dda1273/#61d2):

> First, I want to do a stack requirement analysis.

See [http://www.freertos.org/uxTaskGetStackHighWaterMark.html](http://www.freertos.org/uxTaskGetStackHighWaterMark.html)

> How do I find out the amount of heap being used by my code?

If you are using heap\_1.c or heap\_2.c then simply call xPortGetFreeHeapSize().
