当前位置:网站首页>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
边栏推荐
- Go modules daily use
- HTTP cache - HTTP authoritative guide Chapter VII
- Client interns of a large factory share their experience face to face
- Openlayers 5.0 two centering methods
- Codeforces Round #783 (Div. 2) D题解
- Openharmony open source developer growth plan, looking for new open source forces that change the world!
- 什么是消息队列
- js获取本机ip地址
- 该买什么设备,Keysight 给你挑好了
- Audio signal processing and coding - 2.5.3 the discrete cosine transform
猜你喜欢
Zero base to build profit taking away CPS platform official account
Reflection on the performance of some OpenGL operations in the past
Client interns of a large factory share their experience face to face
8266 obtain 18b20 temperature
该买什么设备,Keysight 给你挑好了
Why is PostgreSQL about to surpass SQL Server?
Android Development: the client obtains the latest value in the database in real time and displays it on the interface
Wechat video extraction and receiving file path
Class loading mechanism
binlog2sql 工具安装使用及问题汇总
随机推荐
SQL of contention for system time plus time in ocrale database
An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
Openlayers 5.0 thermal diagram
Core concepts of rest
binlog2sql 工具安装使用及问题汇总
Machine learning catalog
JS controls the file type and size when uploading files
Customize the non slidable viewpage and how to use it
Gossip: on greed
Wechat video extraction and receiving file path
[报告] Microsoft :Application of deep learning methods in speech enhancement
Common processing of point cloud dataset
Some ideas about time-consuming needs assessment
HTTP cache - HTTP authoritative guide Chapter VII
Using 8266 as serial port debugging tool
SQL常用的命令
Modify the font size of hint in editext
Use of fluent custom fonts and pictures
Common SQL commands
Oracle配置st_geometry