Skip to main content
VHado
Associate
September 20, 2019
Question

How to set Prescaler and Period value for F767ZI to calculate the execution time of the function?

  • September 20, 2019
  • 3 replies
  • 2423 views

0690X00000ARTJhQAP.png

This is my clock configuration.

This is setting for TIM1,

 htim1.Instance = TIM1;
 htim1.Init.Prescaler = 7999;
 htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
 htim1.Init.Period = 1999;
 htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
 htim1.Init.RepetitionCounter = 0;
 htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
 if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
 {
 Error_Handler();
 }
 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
 if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
 {
 Error_Handler();
 }
 sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
 sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
 if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
 {
 Error_Handler();
 }

This is how I'm measuring the time for function,

 TIM1 -> CR1 |= TIM_CR1_CEN;
status = RSA_Encrypt(&PubKey_st, Message, sizeof(Message), output);
sprintf((char*)buf1,"ET:%d.%3d S \r\n",(uint)TIM1->CNT/1000 , (uint)TIM1->CNT%1000 );
 HAL_UART_Transmit(&huart3, (uint8_t*)buf1, 15, 100);

What is wrong with the timer? it say it takes 8 seconds to complete the 2048 RSA encryption decryption! As I change the values of prescaler and period the timing changes.

Can anybody plz tell me what would be the exact values of those?

I don't want any other techniques to measure the execution time. This is what I suppose to make it run.

Any kind of help is appreciated.

This topic has been closed for replies.

3 replies

Tesla DeLorean
Guru
September 20, 2019

Use TIM2, set the Period to maximal, ie 0xFFFFFFFF

Set the prescaler to the clock frequency MHz-1

ie 99 for 100 MHz TIMCLK

Then CNT will count off in microseconds.

You could also use DWT_CYCCNT to time things in CPU cycles.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
September 21, 2019

As a sanity check use

uint32_t start, total;

start = HAL_GetTick();

...

total = HAL_GetTick() - start;

printf("Expired Time %d ms\n", total);

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
VHado
VHadoAuthor
Associate
September 22, 2019

Thank you so much.. Going with HAL_GetTick().