2009-07-07 04:38 AM
Execution Time
2011-05-17 04:16 AM
Hello,
I need to know execution time of few opération to do an integration. I want to stock the time value in a variable. Which will be use after. I think i must use interupts of timers but i don't success to identify this founction in the exemples. Someone ever done this works ? if yes can i see the code ? Thanks. Jean-Claude [ This message was edited by: jean-claude.vedy-renexter on 07-07-2009 12:54 ]2011-05-17 04:16 AM
Being an electrical/electronic engineer I usually toggle a port pin and use an oscilloscope to measure execution/delay/interrupt times.
2011-05-17 04:16 AM
The easiest way to do this is to use the SysTick timer, which doesn't require much to setup and doesn't have to be cascaded while still giving a good range. You can use either clock ticks or clock ticks / 8 to measure the period. You don't have to use interrupts - you only have to read the counter before and after and take the difference, with some care taken to handle the case where the counter overflowed.
Try this:Code:
int32_t clock_ticks; // Enable SysTick with (AHB / 8) clock, use 0x5 for AHB STK_CTRL = 0x1; clock_ticks = STK_VAL; // Perform your operation here clock_ticks = (STK_VAL - clock_ticks) & 0xFFFFFF; // Do something to report clock_ticks, ie look at the value in a // debugger, print it over USART, etc You can find the addresses of STK_CTRL and STK_VAL in the STM32 programming manual (document PM0056). The & 0xFFFFFF should take care of overflow. The number can be interpreted as (1 / clock_speed) * 8 * clock_ticks seconds. So if your clock speed is 72MHz and clock_ticks is 1000 then it means your operation took (1 / 72000000) * 8 * 1000 = 1.11111e-4 seconds, or about 111 microseconds. If you use STK_CTRL = 0x5 then take out the * 8 in the calculations.