当前位置:网站首页>LPC1768 关于延时Delay时间与不同等级的优化对比
LPC1768 关于延时Delay时间与不同等级的优化对比
2022-04-23 19:23:00 【ToneChip】
因为我在驱动编写IIC的时候,使用了一个软件模拟IIC 的方法来驱动加密芯片,因此需要写一个delay函数来控制时序,但是当我把做好的无代码优化的code变成最高等级(速度最快,代码最优)的优化后,发现IIC验证居然不通过,初步怀疑是不是软件时序的时间没有对上,于是使用IO翻转的方式配合逻辑分析仪测试了一下不同延时函数的时间对比.
//=2022.04.21 为了测试delayms函数延时的具体时间,使用IO翻转来测量
void TestDelay(void)
{
LEDInitOnCS0804();
// __enable_irq();
while(1)
{
LED_ON;
atca_delay_us2(1);
LED_OFF;
atca_delay_us2(1);
}
}
/************************************************
优化等级 none low Med High (ms)
delayms(1); 0.29 0.27
delayms(4); 0.59 0.57
delayms(10); 1.19 1.17
delayms(1000); 100.1 100.1 100.1
atca_delay_us2(1); 2.75us 1.5us
atca_delay_us3(1); 5us 4.75us
************************************************/
排版不是很对齐哈,只测试最高等级和none
每个函数的定义如下
//#pragma optimize=none
void delayms(int ms)
{
//2019.01.01在这里填坑
//在高等级的优化选中时,在无任何动作的循环体内要用volatile来定义变量
volatile int i;
volatile int j;
// int i;
// int j;
// for( i = 0; i<16666; i++) //约 1ms
// for( j = 0; j<ms; j++);
for( i = 0; i < 1000; i++) //=1000 OK
for( j = 0; j < ms; j++);
// asm( " nop " );
// asm( " nop " );
// asm( " nop " );
}
void atca_delay_us2(uint32_t nus)
{
int i;
int j;
for( i = 0; i < 17; i++) //约 1us = 16.6666
for( j = 0; j < nus; j++);
}
void atca_delay_us3(uint32_t nus)
{
volatile int i;
volatile int j;
for( i = 0; i < 17; i++) //约 1us = 16.6666
for( j = 0; j < nus; j++);
}
通过对比发现atca_delay_us2和atca_delay_us3唯一区别就在于变量使用了volatile
总结: 使用volatile修饰的变量在工程中使用代码优化无影响
最后配上IAR6.3的代码优化打开选择界面
版权声明
本文为[ToneChip]所创,转载请带上原文链接,感谢
https://tonechip.blog.csdn.net/article/details/124345186
边栏推荐
- The usage of slice and the difference between slice and array
- Matlab 2019 installation of deep learning toolbox model for googlenet network
- White screen processing method of fulter startup page
- Common processing of point cloud dataset
- SSDB foundation 2
- MySQL syntax collation (4)
- Openlayers 5.0 discrete aggregation points
- SQL Server database in clause and exists clause conversion
- Speculation on the way to realize the smooth drag preview of video editing software
- Common SQL commands
猜你喜欢
[报告] Microsoft :Application of deep learning methods in speech enhancement
FTP, SSH Remote Access and control
Wechat video extraction and receiving file path
Installation, use and problem summary of binlog2sql tool
深度学习——特征工程小总结
I just want to leave a note for myself
Network protocol: SCTP flow control transmission protocol
Switching power supply design sharing and power supply design skills diagram
MySQL syntax collation (5) -- functions, stored procedures and triggers
Matlab 2019 installation of deep learning toolbox model for googlenet network
随机推荐
The difference between underline and dot of golang import package
White screen processing method of fulter startup page
The platinum library cannot search the debug process records of some projection devices
The most detailed network counting experiment in history (2) -- rip experiment of layer 3 switch
MySQL syntax collation (2)
openlayers 5.0 加载arcgis server 切片服务
Build intelligent garbage classification applet based on Zero
Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es
static类变量快速入门
[transfer] summary of new features of js-es6 (one picture)
Oracle configuration st_ geometry
The flyer realizes page Jump through routing routes
Common SQL commands
HTTP cache - HTTP authoritative guide Chapter VII
Oracle配置st_geometry
[报告] Microsoft :Application of deep learning methods in speech enhancement
openlayers 5.0 两种居中方式
Decompile and get the source code of any wechat applet - just read this (latest)
高层次人才一站式服务平台开发 人才综合服务平台系统
Translation of audio signal processing and coding: Preface