完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
你好。
我想知道例如while循环需要多少个时钟。 你对这件事有什么想法或文章吗? 以上来自于谷歌翻译 以下为原文 Hi. I wanted to know that for example how many clocks a while loop takes. Do you have any ideas or any articles on this matter? |
|
相关推荐
21个回答
|
|
|
1.有一个自由运行的时钟;
2.延迟执行时间戳。 这样的事情会起作用: //得到时间戳 &amp; sharpdefine tick_get()(TIM2-> CNT)// TIM2初始化为自由运行时钟 //延迟多个周期 void delay(uint16_t cnt){ uint16_t start_time = tick_get(); //时间戳记例程的开始 while(tick_get() - start_time&lt; cnt)继续; //等到所需的周期数已经过去 } 当你想延迟一定数量的我们或ms时,只需用正确的周期数来喂它。 上面的代码是阻塞的。非阻塞版本将是这样的: //测试是否已经过了多个周期 char isdelay(uint16_t cnt){ static uint16_t start_time = 0; //为例程的上一个开始添加时间戳 if(tick_get() - start_time&lt; cnt)返回0; //未指定周期数 start_time + = cnt; //增加start_time 返回1; //表示已经过了设定的周期数 } 以上来自于谷歌翻译 以下为原文 1. have a free-running clock; 2. time stamp your execution for delays. something like this would work: //get time stamp &sharpdefine tick_get() (TIM2->CNT) //TIM2 initialized as a free running clock //delay a number of cycles void delay(uint16_t cnt) { uint16_t start_time = tick_get(); //time stamp the start of the routine while (tick_get() - start_time < cnt) continue; //wait until the desired number of cycles has passed } when you want to delay a certain amount of us, or ms, just feed it with the right number of cycles. the code above is blocking. a non-blocking version would be something like this: //test if a number of cycles has passed char isdelay(uint16_t cnt) { static uint16_t start_time = 0; //time stamp the previous start of the routine if (tick_get() - start_time < cnt) return 0; //the number of cycles specified has not passed start_time += cnt; //increment start_time return 1; //indicating that the set number of cycles has passed } |
|
|
|
|
|
谢谢。它是否适用于8位MCU,最大时钟为16 MHZ?
我用过的东西是这样的: void delay_us(unsigned int d) { TIM5-&GT; CNT = 0; 而(TIM5-&GT; CNT&LT; d); 并且TIM5-> CNT每1us计数一次(TIM5时钟为1MHz)。 这在CPU时钟为120 MHz(当我使用我的stm32f217 MCU时)时有效。 但是当我使用16MHz CPU时钟的相同设置时,这不起作用(我在stm32f217和stm8s中尝试过这个)。 注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 Thanks. Does it work with 8-bit MCUs that the maximum clock is 16 MHZ? Something that I used was this: void delay_us(unsigned int d) { TIM5->CNT=0; while(TIM5->CNT This works when the CPU clock is 120 MHz(When I'm using my stm32f217 MCU). But when I use the same settings with 16MHz CPU clock this does not work(i tried this in both stm32f217 and stm8s that I have). Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
|
只有小组成员才能发言,加入小组>>
stm32mp157的异核通信的rpmsg_sdb的m4固件和a7驱动该如何编写?
1453 浏览 0 评论
stm32f103用freertos对一个采样率为1kHz的传感器,进行采样,数据出差
1502 浏览 0 评论
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
3649 浏览 1 评论
3842 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
2461 浏览 1 评论
STM32H7打开DCache后,出现了串口接收信息为空的现象,是哪里出了问题?
727浏览 5评论
用NANO STM32F103RBT6的开发板烧录不了是哪里出了问题?
661浏览 5评论
710浏览 5评论
外部中断触发类型为双边沿触发,进入中断回调后有什么办法判断该边沿是上升沿还是下降沿?
941浏览 5评论
STM32L071CBT6低温环境下无法正常工作是什么原因引起的?
745浏览 5评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 06:27 , Processed in 0.641084 second(s), Total 41, Slave 34 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
5330