659 views|2 replies

7171

Posts

195

Resources
The OP
 

"Time Analysis of Embedded Software" Chapter 5 Software Time Analysis Methods - Running Time Measurement Learning [Copy link]

This chapter mainly studies the measurement of running time.

The oldest method of timing analysis is runtime measurement using port pins.

Use an oscilloscope or logic analyzer to visualize and measure the signals at the port pins to test the total execution time.

This is actually very commonly used. If you want to measure the time taken by a piece of code, the most common method is to use this old port measurement method.

In the application of STM32, SEV is specially introduced. This SEV is much simpler than the configuration of ATMEGA8's PORTB as an example in the book. You can directly call sev() to pull the port high and low. The sev function only takes one clock cycle. Assuming the clock is 100MHz

One clock cycle is 10ns. If it is STM32F4, the main frequency is close to 180M, then the time taken is even shorter.

GPIO_InitStruct.Pin = GPIO_PIN_10;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Pull = GPIO_PULLDOWN;

GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;

GPIO_InitStruct.Alternate = GPIO_AF15_EVENTOUT;

HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

The second method:

Time measurement method without using ports and instruments

Port pins or external measurement methods are not always available. External measurement equipment may not be available at hand, so other convenient operation methods need to be used, such as hardware timers as the basis for measurement.

After configuring the timer period, the timer value is stored at the beginning of the measurement element and read out at the end of the measurement element. The difference between these two values is the total running time.

Take STM32 as an example

start_cnt=__HAL_TIM_GET_COUNTER(&TIM1_Handler); //获取定时器的值,开始计时

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_SET);

delay_ms(20);

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_1,GPIO_PIN_RESET); /

delay_ms(20);

end_cnt=__HAL_TIM_GET_COUNTER(&TIM1_Handler); //获取结束时的定时器的计数值

The difference between end_cnt and start_cnt is the running time

This post is from Automotive Electronics

Latest reply

The running time length in real-time systems must be paid attention to  Details Published on 2024-7-6 10:23

203

Posts

0

Resources
2
 
The running time length in real-time systems must be paid attention to
This post is from Automotive Electronics

Comments

Yes, this is a very important time to focus on.  Details Published on 2024-7-6 11:16
 
 

7171

Posts

195

Resources
3
 
combat posted on 2024-7-6 10:23 The running time length in real-time system must be paid attention to

Yes, this is a very important time to focus on.

This post is from Automotive Electronics
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list