完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
您好,我读了几个以前的线程(已经链接),但无法计算出如何使用核心计时器计算我的程序的经过时间。我得到了一个秒的顺序,虽然它应该只有几毫秒我的代码如下:我的系统时钟是200兆赫,所以核心定时器时钟应该是100MHz -&10ns?当我读取时间使用的值,它是可笑的高,给我几秒钟,而不是像预期的MS。我做错什么了?
以上来自于百度翻译 以下为原文 Hello, I read several previous threads (already linked) but cannot figure out how to calculate the elapsed time of my program using the core timer. I get an order of seconds although it should be only few ms. My code below: static uint32_t StartTime, TimeUsed; (...) StartTime = _CP0_GET_COUNT(); // My code's elapsed time to be measured. TimeUsed = _CP0_GET_COUNT() - StartTime; My system clock is 200MHz, so the core timer clock should be 100MHz --> 10ns? When I read the TimeUsed value, it is ridiculously high, giving me few seconds instead of ms as expected. What am I doing wrong? |
|
相关推荐
8个回答
|
|
|
|
|
|
|
|
|
编译器是否将返回的值作为符号号来处理?如果是这样的话,那就可以解释了。当我使用了*CP0xGETSyCalt编程延迟时,我发现我必须使用带符号的数字,或者强制转换为无符号。
以上来自于百度翻译 以下为原文 Is the compiler treating the return value from _CP0_GET_COUNT as a signed number? If so, that could explain it. When I've programmed delays using _CP0_GET_COUNT, I've found that I have to either use signed numbers, or cast to unsigned. |
|
|
|
|
|
尝试:问题是翻滚开始时间现在可以更大。注意这只给了你31位。我认为有一种方法可以给你32位。
以上来自于百度翻译 以下为原文 try: static uint32_t StartTime;static int32_t TimeUsed;(...) StartTime = _CP0_GET_COUNT(); // My code's elapsed time to be measured. TimeUsed = (int32_t)( _CP0_GET_COUNT() - StartTime);the issue is roll over start time can be bigger that now. note this gives you only 31 bits. I think there is a method that gives you 32bits |
|
|
|
|
|
|
|
|
|
|
|
嗨,已经在很多PIC32 MX设备上使用了“核心定时器”,没有这样的问题,没有MZ的实际经验。使用XC32编译器的版本是什么?消息第1条中显示的代码对我来说似乎很好。如果消息在第4行中被应用,则在消息5、4中的建议与OP代码并不完全不同。在Myz中的几毫秒内可能会发生很多事情,确保StestTimes中的值没有被执行。另一个可能的错误是块内的一些代码,在系统协处理器CP0中删除“核心定时器”计数寄存器。在不需要这种动作的情况下,出现了坏的示例代码,清除了“核心定时器”寄存器。E代码,如果有任何''''.'''.''.''.''.'c',''.'''.''.''.'c'0',''.''.''',''.'''.''.'c'0',''.''.',''',''.''',''.'''.',''''.''',''.'c'0',''.''.''',''.''.',''.'c'0',''.''',''.
以上来自于百度翻译 以下为原文 Hi, Have used the 'core timer' a lot on several PIC32MX devices, with no such problem, no actual experience with MZ. What version of XC32 compiler is used? Code shown in message #1 seem good to me. Suggestions in message #5, #4 are not really different from OP code, if calculation inside the paranthesis is carried out first, before the cast is applied in #4. A lot may happen during a few milliseconds in a MZ, make sure that value in StartTime haven't been trashed in some way during the time elapsed. Another possible error would be some code inside the block, trashing the 'core timer' Count register, in system coprocessor CP0. There have been bad example code around, clearing the 'core timer' register, when such action is never needed. Search the source code if there is any occurrence of '_CP0_SET_COUNT' or 'mtc0(9' or similar. You may try with a cast on the macro _CP0_GET_COUNT() static uint32_t StartTime, TimeUsed; (...) StartTime = (uint32_t)_CP0_GET_COUNT(); // My code's elapsed time to be measured. TimeUsed = (uint32_t)_CP0_GET_COUNT() - StartTime; I would be surprised if it made any difference. Regards, Mysil |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475 浏览 0 评论
5794 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1124浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1098浏览 1评论
我是Microchip 的代理商,有PIC16F1829T-I/SS 技术问题可以咨询我,微信:A-chip-Ti
873浏览 1评论
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
475浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 13:19 , Processed in 0.891363 second(s), Total 88, Slave 70 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
950