How to find CPU Load for microcontrollers

Thread Starter

Vihaan@123

Joined Oct 7, 2025
223
Is it possible to find the CPU load for example PIC controllers? I mean i want to know if the controller is executing every task properly or not? It is just a vague idea to find out the CPU load and from that i can assess the overall system performance.
 

panic mode

Joined Oct 10, 2011
4,902
simple way is to use counter... its value is to be incremented at some point in the program, the faster the execution, the faster counter value changes. in fact that is how every platform measures performance, they are called "performance counters". that is what you see in task manager...
 

sagor

Joined Mar 10, 2019
1,049
Most PICs, especially the smaller ones, simply "Loop" forever, so they are executing code 100% all the time. That can be by design as there is nothing else for the PIC to do other than run continuously.
Some PICs can be put into a sleep mode to save power. At that point, they are not "running" per say, just idle and waiting for a wake up interrupt...
 

joeyd999

Joined Jun 6, 2011
6,231
In the cooperative multitasking framework that I use to develop my PIC projects, during debug I'll sometimes toggle a pin on when useful work is being done and off otherwise (i.e. during idle periods when no work is being done). The result is a (noisy) PWM output that exactly gauges MCU instruction cycle utilization -- at a cost of exactly 2 instruction cycles per task.
 

BobTPH

Joined Jun 5, 2013
11,480
Set up a small idle loop that executes when no other task is executing.

Set up a periodic timer interrupt that checks the return address in the handler. The percentage of times that the return address is not within the idle loop is the cpu utilization.
 

atferrari

Joined Jan 6, 2004
5,004
I work with PICs.

One pin is dedicated to output a short pulse every time the software clock elapses a period. This is running since I start developing a new design and kept unchanged forever.

Other pin/s is/are dedicated to show the start and / or the end of specific subroutines/s.
 

Irving

Joined Jan 30, 2016
5,039
In the cooperative multitasking framework that I use to develop my PIC projects, during debug I'll sometimes toggle a pin on when useful work is being done and off otherwise (i.e. during idle periods when no work is being done). The result is a (noisy) PWM output that exactly gauges MCU instruction cycle utilization -- at a cost of exactly 2 instruction cycles per task.

I work with PICs.

One pin is dedicated to output a short pulse every time the software clock elapses a period. This is running since I start developing a new design and kept unchanged forever.

Other pin/s is/are dedicated to show the start and / or the end of specific subroutines/s.
Probably not an option for Vihaan, the board he is working with pre-exists and he doesn't have direct access to the hardware.
 

Irving

Joined Jan 30, 2016
5,039
Hola Irving
Cannot see what you say in the OP.
That's because its not in the OP. ;) Elsewhere Vihaan shared some info on the hardware he's working with; it is likely he has no physical access to the MCU to access pins etc. and a number of questionable architecture and hardware decisions have been made without understanding or consideration of the system requirements or the software regime.
 
Last edited:
Top