当前位置:网站首页>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
边栏推荐
- Pdf reference learning notes
- An idea of rendering pipeline based on FBO
- ArcGIS JS API dojoconfig configuration
- All table queries and comment description queries of SQL Server
- [transfer] summary of new features of js-es6 (one picture)
- Core concepts of rest
- Client interns of a large factory share their experience face to face
- [报告] Microsoft :Application of deep learning methods in speech enhancement
- PostgreSQL
- Application of DCT transform
猜你喜欢
MySQL syntax collation
网络协议之:sctp流控制传输协议
Common SQL commands
Matlab 2019 installation of deep learning toolbox model for googlenet network
MySQL syntax collation (4)
MySQL syntax collation (5) -- functions, stored procedures and triggers
White screen processing method of fulter startup page
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)
An idea of rendering pipeline based on FBO
随机推荐
Redis optimization series (III) solve common problems after master-slave configuration
2021-2022-2 ACM training team weekly Programming Competition (8) problem solution
MySQL practical skills
The platinum library cannot search the debug process records of some projection devices
机器学习目录
Audio signal processing and coding - 2.5.3 the discrete cosine transform
数据分析学习目录
arcMap 发布切片服务
C1000k TCP connection upper limit test
Prefer composition to inheritance
Convert string to JSON
Web Security
Installation, use and problem summary of binlog2sql tool
Strange passion
Decompile and get the source code of any wechat applet - just read this (latest)
On the forced conversion of C language pointer
ArcMap publishing slicing service
Some records used by VS2010
Core concepts of rest
SQL server requires to query the information of all employees with surname 'Wang'