日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 單片機 > 單片機
[導(dǎo)讀] 在實際的項目開發(fā)過程中,常常遇到需要得到一段代碼的運行時間,通常的方法是用示波器來測量,這篇博文將用SysTick來實現(xiàn)精確測量程序運行的時間。STM32F4的內(nèi)核定時器SysTick是一個24位的定時器,需要

在實際的項目開發(fā)過程中,常常遇到需要得到一段代碼的運行時間,通常的方法是用示波器來測量,這篇博文將用SysTick來實現(xiàn)精確測量程序運行的時間。STM32F4的內(nèi)核定時器SysTick是一個24位的定時器,需要注意最大的測量時間。


1,開發(fā)環(huán)境

1,固件庫:STM32F4xx_DSP_StdPeriph_Lib_V1.8.0

2,編譯器:ARMCC V5.06

3,IDE:Keil uVision5

4,操作系統(tǒng):Windows 10 專業(yè)版


2,程序源碼

MeasureTime.h文件

  1. /**

  2. ******************************************************************************

  3. *@fileMeasureTime.h

  4. *@authorXinLi

  5. *@versionv1.0

  6. *@date24-October-2017

  7. *@briefMeasureprogramruntimemodule.

  8. ******************************************************************************

  9. *@attention

  10. *

  11. *

    Copyright©2017XinLi

  12. *

  13. *Thisprogramisfreesoftware:youcanredistributeitand/ormodify

  14. *itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby

  15. *theFreeSoftwareFoundation,eitherversion3oftheLicense,or

  16. *(atyouroption)anylaterversion.

  17. *

  18. *Thisprogramisdistributedinthehopethatitwillbeuseful,

  19. *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof

  20. *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe

  21. *GNUGeneralPublicLicenseformoredetails.

  22. *

  23. *YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense

  24. *alongwiththisprogram.Ifnot,see.

  25. *

  26. ******************************************************************************

  27. */

  28. #ifndef__MEASURETIME_H

  29. #define__MEASURETIME_H

  30. #ifdef__cplusplus

  31. extern"C"{

  32. #endif

  33. /*Headerincludes-----------------------------------------------------------*/

  34. #include"stm32f4xx.h"

  35. /*Macrodefinitions---------------------------------------------------------*/

  36. /*Typedefinitions----------------------------------------------------------*/

  37. /*Variabledeclarations-----------------------------------------------------*/

  38. /*Variabledefinitions------------------------------------------------------*/

  39. /*Functiondeclarations-----------------------------------------------------*/

  40. /*Functiondefinitions------------------------------------------------------*/

  41. /**

  42. *@briefStartmeasuretime.

  43. *@paramNone.

  44. *@returnNone.

  45. */

  46. __STATIC_INLINEvoidMeasureTimeStart(void)

  47. {

  48. SysTick->CTRL|=SysTick_CLKSource_HCLK;/*SettheSysTickclocksource.*/

  49. SysTick->LOAD=0xFFFFFF;/*Timeload(SysTick->LOADis24bit).*/

  50. SysTick->VAL=0xFFFFFF;/*Emptythecountervalue.*/

  51. SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;/*Startthecountdown.*/

  52. __nop();/*Waitingforamachinecycle.*/

  53. }

  54. /**

  55. *@briefStopmeasuretime.

  56. *@param[in]clock:Systemclockfrequency(unit:MHz).

  57. *@returnProgramruntime(unit:us).

  58. */

  59. __STATIC_INLINEdoubleMeasureTimeStop(uint32_tclock)

  60. {

  61. uint32_tcount=SysTick->VAL;/*Readthecountervalue.*/

  62. SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk;/*Closecounter.*/

  63. doubletime=0.0;

  64. if(clock>0)

  65. {

  66. time=(double)(0xFFFFFF-count)/(double)clock;/*Calculateprogramruntime.*/

  67. }

  68. returntime;

  69. }

  70. #ifdef__cplusplus

  71. }

  72. #endif

  73. #endif/*__MEASURETIME_H*/


main.c文件

  1. /**

  2. ******************************************************************************

  3. *@filemain.c

  4. *@authorXinLi

  5. *@versionv1.0

  6. *@date24-October-2017

  7. *@briefMainprogrambody.

  8. ******************************************************************************

  9. *@attention

  10. *

  11. *

    Copyright©2017XinLi

  12. *

  13. *Thisprogramisfreesoftware:youcanredistributeitand/ormodify

  14. *itunderthetermsoftheGNUGeneralPublicLicenseaspublishedby

  15. *theFreeSoftwareFoundation,eitherversion3oftheLicense,or

  16. *(atyouroption)anylaterversion.

  17. *

  18. *Thisprogramisdistributedinthehopethatitwillbeuseful,

  19. *butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof

  20. *MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.Seethe

  21. *GNUGeneralPublicLicenseformoredetails.

  22. *

  23. *YoushouldhavereceivedacopyoftheGNUGeneralPublicLicense

  24. *alongwiththisprogram.Ifnot,see.

  25. *

  26. ******************************************************************************

  27. */

  28. /*Headerincludes-----------------------------------------------------------*/

  29. #include"main.h"

  30. #include"MeasureTime.h"

  31. /*Macrodefinitions---------------------------------------------------------*/

  32. /*Typedefinitions----------------------------------------------------------*/

  33. /*Variabledeclarations-----------------------------------------------------*/

  34. /*Variabledefinitions------------------------------------------------------*/

  35. static__IOdoublerunTime=0.0;

  36. /*Functiondeclarations-----------------------------------------------------*/

  37. __STATIC_INLINEvoiddelay_1us(void);

  38. /*Functiondefinitions------------------------------------------------------*/

  39. /**

  40. *@briefMainprogram.

  41. *@paramNone.

  42. *@returnNone.

  43. */

本站聲明: 本文章由作者或相關(guān)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉