完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我使用的是PIC32 MM000 32 GPL028和PIC32 MM00 64 GPL028。我的IDE是MPLAB X V3.40。我使用代码配置器生成Caletime2的代码,包括它的ISR。MCU正在运行8MHz,coretimer周期被设置为1ms。下面是生成的ISR代码:-首先,我发现它每次进入这个ISR时只添加“.”变量和0xFA0。当“比较”变量的值大于2 ^ 32时,会发生什么?换言之,溢出是否有问题?第二,我修改了下面的代码。唯一的区别是我使用了_CP0_GET_COUNT()函数来获得计数,而不是使用“.”变量的原始值。这会有什么问题吗?第三,当我使用代码配置器来生成其他计时器的代码时,而不是核心计时器,我发现ISR不需要为比较值设置新值。事实上,我认为这是正常的。为什么核心定时器的计数值在达到比较值后不重置为0?计时器1的ISR:谢谢
以上来自于百度翻译 以下为原文 I am using the PIC32MM0032GPL028 and PIC32MM0064GPL028. My IDE is MPLAB X v3.40. I used the Code Configurator to generated the code for the CoreTimer, including its ISR. The MCU is running 8MHz and the coretimer period is set to be 1ms. Below is the generated ISR code: void __attribute__ ((vector(_CORE_TIMER_VECTOR), interrupt(IPL7SOFT))) _CORE_TIMER_ISR(void) { uint32_t static compare = 0; // Update the compare value compare = compare + 0xFA0; _CP0_SET_COMPARE(compare); IFS0CLR= 1 << _IFS0_CTIF_POSITION; // Add your custom code here } - First, I find that it just add the "compare" variable with 0xFA0 each time it enter this ISR. What happen when the value of the "compare" variable get larger than 2^32? In the other words, does it has any problem if it overflow? - Second, I modified the code as below. The only difference is I used the _CP0_GET_COUNT()function to get the count in stead of using the original value of the "compare" variable. Will it get any problem? void __attribute__ ((vector(_CORE_TIMER_VECTOR), interrupt(IPL7SOFT))) _CORE_TIMER_ISR(void) { uint32_t static compare = 0; // Update the compare value compare = _CP0_GET_COUNT() + 0xFA0; _CP0_SET_COMPARE(compare); IFS0CLR= 1 << _IFS0_CTIF_POSITION; // Add your custom code here } - Third, when I use the Code Configurator to generate code of other timer, rather than the Core Timer, I found that the ISR does not need to set a new value to the compare value. In fact I think this is normal. Why the count value of Core Timer does not reset to 0 once it reach the compare value? ISR of timer 1: void __attribute__ ((vector(_TIMER_1_VECTOR), interrupt(IPL1SOFT))) TMR1_ISR() { /* Check if the Timer Interrupt/Status is set */ //***User Area Begin // ticker function call; // ticker is 1 -> Callback function gets called everytime this ISR executes TMR1_CallBack(); //***User Area End tmr1_obj.count++; tmr1_obj.timerElapsed = true; IFS0CLR= 1 << _IFS0_T1IF_POSITION; } Thank you |
|
相关推荐
1个回答
|
|
嗨,MIPS协处理器0Count寄存器是一个32位计数器,编译器认为它是一个无符号整数变量,所以Count寄存器将从429467295运行到0。使用来自Count或Compare寄存器的值进行运算,给出“太大”的结果,结果将从低端重新开始。在无符号32位计算中:4 294 967 295+100=99,没有问题或例外。您可以使用_CP0_GET_COUNT()的值来计算_CP0的新值。_SET_COMPARE(比较)在某些情况下,如第一设置,这可能是首选的。但是存在一个缺点,处理器使用从中断触发的多个时钟周期,直到到达ISR中计算新的比较值的点。f计时器增量为1毫秒,将得到中断延迟,又名AKA。除了计算周期之外,中断等待时间可能为1.01毫秒,带有示例值。使用MCC生成的代码,或者:一个中断与下一个中断之间的间隔,将精确地计算为1毫秒。直到发生导致中断过程的情况。如果发生这种情况,下一个计算的比较值将从当前Count值中取出,直到Count寄存器运行在32位左右时才会中断。在8MHz下运行是1073秒。这种延迟可能发生如果一个NVM闪存擦除或写操作被执行,就可以编写一个测试比较计数和比较寄存器值来避免这种情况,并且仍然得到精确的中断间隔。RAM内存以保持比较寄存器的值。O.CP0xGETSyBaseCube()将从系统协处理器获得值,比从内存中读取更快,并且通过使用CPU寄存器进行计算,以后将不需要写入内存,但差异会很小。同样,当从计数寄存器读取当前时间时,存在对于新的比较值,不需要使用静态变量。对于其他定时器(外围定时器),在PIC32设备中,它们都有一个周期寄存器PRX。不同于比较寄存器的周期寄存器函数,在那个周期寄存器将在硬件中复位定时器寄存器为零。在8位PIC设备中,有定时器甚至更原始,既没有周期也没有比较寄存器,这些定时器在从最大数滚动到零时只能中断。
以上来自于百度翻译 以下为原文 Hi, The MIPS Coprocessor 0 Count register is a 32 bit counter that is regarded as a unsigned integer variable by the compiler, so the Count register will run around from 429467295 to 0. Similar with the Compare register, when you use: unsigned int variables, or: unsigned long int variables, to do arithmetic with values from Count or Compare registers, giving a result that is 'too large', the result will start over from the low end. In unsigned 32 bit computation: 4 294 967 295 + 100 = 99 with no problem or exception. You may well use the value from _CP0_GET_COUNT() to calculate new value for _CP0_SET_COMPARE(compare) In some cases, like the first setting, this may be preferred. But there is a disadvantage, that the processor use a number of clock cycles from the interrupt is triggered, until it get to the point in ISR where new Compare value is calculated. If there is an accurate calculation of timer increment for 1 millisecond. You will get the interrupt delay, aka. interrupt latency in addition to the calculated period, maybe something like 1.01 millisecond with the example value. Using the code as generated by MCC, or : uint32_t register compare; // Update the compare value compare = _CP0_GET_COMPARE() + 0xFA0; _CP0_SET_COMPARE(compare); the interval between one interrupt and the next, will be exactly 1 millisecond as calculated. Until something happen that cause interrupt processing to be suspended or delayed more than 1 or 2 millisecond. If that happen, the next calculated Compare value will be in the past from the current Count value, and there will be no interrupt until Count register run around 32 bits. That is 1073 seconds when running at 8 MHz. Such a delay may happen amo. if a NVM Flash erase or write operation is performed. It is possible to write a test comparing Count and Compare register values to avoid such a situation, and still get exact interrupt interval. About the code generated by MCC, it is not really needed to keep a static variable 'compare' stored in RAM memory to keep the value of Compare register. _CP0_GET_COMPARE() will get the value from system coprocessor, faster than reading from memory, and by using a CPU register for calculation, there will be no need to write to memory afterwards, but the difference will be small. Similarly, when you read the current time from Count register, there is no need to use a static variable for the new compare value. For the other timers (peripheral timers), in PIC32 devices, they all have a Period Register PRx. Period Register function differently from Compare register, in that Period Register will Reset the Timer register to zero in hardware, when the Period value is reached. In 8 bit PIC devices, there are timers that are even more primitive with neither Period nor Compare register, these timers may only make interrupt when rolling over from max count to zero. Regards, Mysil |
|
|
|
只有小组成员才能发言,加入小组>>
5160 浏览 9 评论
1998 浏览 8 评论
1927 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3170 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2225 浏览 5 评论
729浏览 1评论
613浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
503浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
628浏览 0评论
526浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-22 13:40 , Processed in 1.225329 second(s), Total 79, Slave 62 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号