# 6.4. Resource Usage

This section provides reference data for resource usage, covering program and data memory and CPU usage.

Please note: Resource usage is dependent on a number of factors, and may be different than the data shown below. These factors include:

- Compiler version
- Compiler optimization levels
- Compiler flags
- Settings in motorBench™ Development Suite
- Settings in MCC
- MCAF parameter values

## 6.4.1. Test case

In the publicly-available collateral for motorBench™ Development Suite 2.0 is a completed sample project called `sample-motorBench-project-completed-mclv2.zip`. This represents the output of motorBench™ Development Suite for the Nidec Hurst DMA0204024B101 motor used with the MCLV-2 development board. The source code was built using XC16 1.35 with `-O1` and `-O2` compilation levels for the dsPIC33EP256MC506, and with `MCAF_TEST_PROFILING` and `MCAF_TEST_HARNESS` enabled.

### 6.4.1.1. Program and data memory

Resource usage statistics for program and data memory were derived from the map file.

### 6.4.1.2. CPU usage

CPU usage was determined with a variant of MCAF R3 modified to transmit CPU cycle count data via the UART, at various points in the motor control ISR, for a 20kHz PWM ISR, using the dsPIC33EP256MC506 running at 70MIPS.

CPU cycle count was measured over approximately 4 seconds, with the motor starting up, running, and slowing to a stop. The resulting time inside the motor control ISR was sorted from low to high, with the worst-case and 99.9% percentile computed. For example, 4 seconds of data at 20kHz represents 80,000 data points, so the 99.9% percentile represents the 80th-highest sample of CPU usage. This represents conservative estimates of CPU usage for estimating remaining CPU capacity in aggregate over time, and exclude timing spikes which may occur when long execution paths coincide in the same ISR cycle. The worst-case CPU usage should be used to determine that the ISR does not overrun available time limits. Variation in CPU time is due to a number of factors, including:

- Branches (`if` statements) may take alternate and unequal execution paths
- Some algorithms run at submultiples of the ISR, so for example the PLL position estimator has a portion of code that runs once every 8 ISR cycles
- During different states of the state machine, different parts of the code are enabled or disabled

Main loop CPU usage was not profiled but is minimal (estimated at < 0.1 MIPS); not much code runs in the main loop.

## 6.4.2. Usage statistics

Statistic | MCAF R3, XC16 1.35 `-O1` | MCAF R3, XC16 1.35 `-O2`
--- | --- | ---
Program memory (bytes)
Excluding X2Cscope | 20367 | 21744
X2Cscope module | 12831 | 12831
Total | 33198 | 34575
Data memory (bytes)
Excluding X2Cscope | 1342 | 1340
X2Cscope module | 5466 | 5466
Total | 6808 | 6806
CPU ISR usage (% at 70MIPS, 20kHz ISR)
Worst-case | 64.1% | 62.9%
99.9% percentile | 63.8% | 62.6%