# Motor Controller Firmware Execution Timing Information

The high dynamic nature of the motor drive circuit imposes a strict requirement on the realtimeness of the firmware. We must ensure that we can run everything within a single FOC commutation loop.

We performed several measurements on the Recoil firmware code running on the motor controller to profile the execution time.

The timing information is measured with a Siglent SDS 1202X-E oscilloscope via a GPIO header on the motor controller board.

The system clock is configured as 160 MHz. The compiler optimization is set to `-O2`.

## Current Control

Entire loop

### Encoder reading

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FzI3zqdesBuBPrEc1LOiO%2Fi2c_encoder.png?alt=media&#x26;token=e8f78038-0cd9-4d95-9792-73992b1e1f39" alt=""><figcaption></figcaption></figure>

The delta time between issuing **HAL\_I2C\_Master\_Receive\_IT** and receiving the interrupt is 78 us.

Hence, the maximum frequency it can run at is 12 kHz.

### Clarke transform

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FUaS0W0z7rZGMlXO4i706%2FFOC_clarkTransform.png?alt=media&#x26;token=c0e0f4a8-1260-4334-9bc4-dc4c68381b5b" alt=""><figcaption></figcaption></figure>

### Park transform

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FKHRgIYi0NW5RHpkeX8WL%2FFOC_clarkTransform.png?alt=media&#x26;token=cafd56f5-34ca-40ae-a3ad-668937b883e0" alt=""><figcaption></figcaption></figure>

### V\_D V\_Q target calculation

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2F4lLh1Cy0KeVjcPuR3WE1%2Fv_dq_target.png?alt=media&#x26;token=31cb2faa-addc-4411-8223-9a6446f21dd8" alt=""><figcaption></figcaption></figure>

### Overmodulation

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FgS49ndkdnrbUwpLXRC7a%2Fovermodulation.png?alt=media&#x26;token=d3058276-63a2-4d8f-9493-8734d83c4a6a" alt=""><figcaption></figcaption></figure>

### Inverse park transformation

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FLyMk2Pe6DM1LilC4upj6%2FinvPark.png?alt=media&#x26;token=f20726a1-8ed5-4636-944e-1c41e42971d0" alt=""><figcaption></figcaption></figure>

### SVPWM

<figure><img src="https://2396875388-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FJ943fa7TiyZgDTAM8Bt7%2Fuploads%2FFM1LMJeaCoWuJHYWBofL%2Fsvpwm.png?alt=media&#x26;token=8d82c6ef-1643-4035-a8ad-e1d70596e746" alt=""><figcaption></figcaption></figure>
