Re: Calculating the RAM usage
If you want to know when you program in not busy, you need to create a place for it to wait.
There is no way for the CPU to know if it is doing useful work.
You can google for how to check the Stack.
It usually involves filling the Stack with some value (0, 42, 99,0xFF, 0xDEADBEEF, ect)
Then the monitor routine will read the stack backwards until it finds a value that is not in the Fill.
There maybe some example in the Class B libraries.