I checked core cycle count using DWT->CYCCNT. but different from my prediction. Could you tell me the cause?
My device is STM32 NUCLEO-L476RG. I just check DWT->CYCCNT. and only changed the number of times an integer assign.
m_nStart = DWT->CYCCNT;
m_nStop = DWT->CYCCNT;
printf("Cycle diff - assign 0 : %lu\n", m_nStop - m_nStart);
m_nStart = DWT->CYCCNT;
i = 10;
m_nStop = DWT->CYCCNT;
printf("Cycle diff - assign 1 : %lu\n", m_nStop - m_nStart);
m_nStart = DWT->CYCCNT;
i = 10;
i = 20;
m_nStop = DWT->CYCCNT;
printf("Cycle diff - assign 2 : %lu\n", m_nStop - m_nStart);
m_nStart = DWT->CYCCNT;
i = 10;
i = 20;
i = 30;
m_nStop = DWT->CYCCNT;
printf("Cycle diff - assign 3 : %lu\n", m_nStop - m_nStart);
m_nStart = DWT->CYCCNT;
i = 10;
i = 20;
i = 30;
i = 40;
m_nStop = DWT->CYCCNT;
printf("Cycle diff - assign 4 : %lu\n", m_nStop - m_nStart);
I expected to be proportional to the number of assignments. but result is this.
Cycle diff - assign 0 : 14
Cycle diff - assign 1 : 16
Cycle diff - assign 2 : 18
Cycle diff - assign 3 : 20
Cycle diff - assign 4 : 22
Why result like that?