完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。我正在使用PIC24F。我想禁用嵌套中断(ItCON1=0x8000;),但问题是当我们禁用嵌套中断时,我们不能改变CPU的优先级(SrBase.IPL),并且我想把CPU的优先级更改为最高(SrBITS.IPL=7),以防止OC中断。固化,在我的代码的某些部分。有人能提出一个合适的方法来解决这个问题吗?当做
以上来自于百度翻译 以下为原文 Hello guys. I am using PIC24F. I want to disable the nested interrupts (INTCON1 = 0x8000;), but the problem is when we disable the nested interrupts, we cannot change the priority of CPU (SRbits.IPL), and I want to change the priority of CPU to highest (SRbits.IPL = 7) in order to prevent the interrupts from occuring, in some parts of my code. Can anyone mention a suitable approach to achive this? Regards |
|
相关推荐
13个回答
|
|
不要禁用嵌套中断。简单地使所有的中断相同的优先级(因为它们已经默认为4)。这样他们就不会筑巢了。
以上来自于百度翻译 以下为原文 Don't disable nested interrupt. Simply make all interrupts the same priority (as they already are by default at 4). This way they won't nest. |
|
|
|
您好,根据中断族参考手册,您仍然应该能够使用DISI汇编指令(第2.3节)。我没有检查XC16编译器手册,但甚至可能有一个宏来支持这一点,否则使用内联汇编。
以上来自于百度翻译 以下为原文 Hi, According to the Interrupt Family Reference Manual you should still be able to use the DISI assembly instruction (section 2.3). I did not check the XC16 compiler manual but there might even be a macro to support this, otherwise use inline assembly. Regards |
|
|
|
这是否与您的其他线程有关(http://www. McCys.com /william hill官网
/ M1048020.ASPX)?如果是的话,你试过这些建议吗?苏珊
以上来自于百度翻译 以下为原文 Is this related to your other thread (http://www.microchip.com/forums/m1048020.aspx)? If so, did you try those suggestions? Susan |
|
|
|
苏珊:是的,部分与另一个线程有关。实际上,这次我把结果显示在16×2 LCD上,并且禁用嵌套中断比留下那些中断启用了更精确的结果(由DEFULTE)。是的,我尝试了所有这些建议。
以上来自于百度翻译 以下为原文 @susan: Yes is partially related to the other thread. Actually this time, I was displaying the result on 16*2 lcd, and disabling nested interrupts give me more accurate results than leaving those enabled (by deafult). And yes I tried all those suggestions. |
|
|
|
好的,就像我们已经切换到这个线程一样,也许你最好描述一下你真正想要做的事情。在我的经验中,玩中断优先级是很少见的,并且禁用中断更是罕见。因此,你可能使用错误的技术来解决任何真正的问题。苏珊
以上来自于百度翻译 以下为原文 OK, as we seem to have swapped on to this thread, perhaps you had better describe what you are actually trying to do. In my experience, playing with interrupt priorities is rare and disabling interrupts is rarer still. Therefore you are probably using the wrong technique to solve whatever the real problem is. Susan |
|
|
|
我用一种简单的方式描述。我用两个中断,输入捕获测量频率,UART(RS485)发送频率作为从属设备。所以我想澄清关于优先顺序的歧义。这里之所以要问的原因是RRASILLY:无论如何,中断优先级可能是罕见的,但是禁用中断来读取/访问ISR中修改的变量是正常的做法。在XC16编译器用户指南中也提到了这一点。我们设置CPU优先级最高,禁用所有中断,读取变量,启用中断。但我也禁用了嵌套中断,这是不应该做的。现在我不这样做,加上优先权默认,它与稳定工作(礼貌的诺斯盖尔)。
以上来自于百度翻译 以下为原文 I described in a simple way. I am using two interrupts, input capture to measure the frequency, UART (RS485) to send the frequency as a slave device. So I wanted to clear the ambiguity regarding the priorities. The reason to ask here is because its rareSmile: Anyway, interrupt priorities may be rare, but disabling the interrupts to read/access the variable that is modified in ISR is a normal practice. This is also mentioned in XC16 Compiler UserGuide. We set the CPU priority highest to disable all interrupts, read the variable, enable the interrupts. But I also disabled the nested interrupts which should not be done. Now I donot do this, plus leave the priorities to default and it works with stability (Courtesy of NorthGuy). |
|
|
|
下一个问题:输入捕获频率ISR的频率和发送计算频率值的频率是多少?UART的波特率是多少?为什么在UART TX侧使用中断?我猜想,处理是沿着线:-输入捕获测量2(或更多)输入样本的时间,并计算瞬时频率(我假设这是在其ISR中完成的)-它可能设置一个标志来表示已经计算了新的频率,或者可能跳过这一步。在线检查标志和/或UART TX缓冲器是免费的,然后新的值传递给UART将被发送-冲洗和重复,所以只需要1中断,所以没有问题。然而,我最初的问题的答案可能表明我的方法是不够的。苏珊
以上来自于百度翻译 以下为原文 Next question(s): How often is the input capture frequency ISR called and how often are you sending the calculated frequency value? What BAUD rate is the UART? Also why are you using interrupts on the UART Tx side? I'm guessing the processing is along the lines of: - Input capture measures the time of 2 (or more) input samples and calculates the instantaneous frequency (I assume this is done in its ISR) - It probably sets a flag to say that a new frequency has been calculated, or perhaps skips this step - The main line checks for the flag and/or that the UART Tx buffer is free and then the new value is passed to the UART to be sent - rinse and repeat If so then there needs to only be 1 interrupt and so no problem. However the answers to my initial questions may show where my approach is not sufficient. Susan |
|
|
|
我不知道输入捕获ISR的频率有多高。我怎样检查这个?我发送频率每2毫秒,波特率9600。我在上一篇文章中提到它是一个从设备,意味着它使用接收中断来回复主设备。因此,有两个中断是必要的。我只将两个样本的值存储在输入捕获ISR中,计算主函数中的频率。ValueAy属性((中断,NoAutoAsPSV))IIC1中断(空隙){CAP1= IC1BUF;CAP2=IC1BUF;IFS0BITS IC1IF=0;}
以上来自于百度翻译 以下为原文 I donot know how often the input capture ISR called. How can I check this? I send the frequency every 2 ms, with 9600 baud rate. And I mentioned in my last post that it is a slave device, means it replies to master device using receive interrupt. Therefore two interrupts are necessary. And I only store the values of two samples in input capture ISR, calculate the frequency in the main function. void __attribute__((interrupt,no_auto_psv)) _IC1Interrupt(void) { cap1 = IC1BUF; cap2 = IC1BUF; IFS0bits.IC1IF = 0; } |
|
|
|
因此,“主”向UART发送一个值,该值触发RX ISR将一个值(在主回路中计算)写入UART TX缓冲器。首先,如果将CAP1和CAP2值转换为频率的计算非常小(例如,从另一个减去),则有两件事出现在脑海中:在UART的RX ISR中做到这一点。如果ISR都具有相同的优先级,那么它们将永远不会中断,因此没有问题。另一方面,如果计算更耗时,那么:在输入捕获ISR中,添加另一个标志,称“我已经更新了捕获值”——UART RX ISR设置了标志。写“UART”的主循环查看第一个标志并在需要时执行计算,然后将结果复制到变量中。然后,检查是否设置了第二个标志,如果是,将变量的值写入UART。如果输入捕获以比UART高得多的频率操作,那么您将简单地将计算的频率值重写几次。如果它运行得慢得多,那么您将多次发送相同的值。至于输入捕获ISR触发的频率,那么您可以查看它是如何初始化的,以查看在触发ISR之前需要捕获多少个ISR。至于它捕获的频率,那么这肯定是你设计的一部分。苏珊
以上来自于百度翻译 以下为原文 So the 'master' send a value to the UART which triggers the Rx ISR that writes a value (calculated in the main loop) into the UART Tx buffer. Two things come to mind Firstly, if the calculation to convert the 'cap1' and 'cap2' values to frequency is very small (e.g. subtract one from the other) then do that in the UART's Rx ISR. If the ISRs both have the same priority then they will never interrupt each other so there is no problem. On the other hand, if the calculation is more time consuming, then: - in the Input Capture ISR, add in another flag that says 'I've updated' the captured values' - have the UART Rx ISR set a flag that says 'write to the UART' The main loop looks at the first flag and performs the calculation if required then copies the result into a variable. It then checks to see if the 2nd flag is set and, if so, writes the value from the variable to the UART. If the Input Capture is operating at a much higher frequency than the UART then you will simply have the calculated frequency value overwritten several times. If it is operating much slower, then you will send the same value multiple times. As for how often the input capture ISR is being triggered, then you can look at how it is initialised to see how many captures it requires before it triggers the ISR. As for how often it captures, then surely that is part of your design. Susan |
|
|
|
输入捕获在每第十六个上升沿被初始化,意味着它捕获频率的每第十六个上升沿,并且ISR在每秒钟捕获时被触发。硬件给出频率为约100~150 kHz的连续方波。因此,它以更高的频率运行,但我不计算每个回路的频率,而是计算主回路,当它匹配一定的计数(粗略估计)时,然后计算频率,并重置计数变量。
以上来自于百度翻译 以下为原文 The input capture is been initailized at every 16th rising edge, means it captures every 16th rising edge of the frequency, and the ISR is being triggered at every second capture. And the hardware gives frequency as a continuous square wave of approx. 100 ~ 150khz. Therefore, it is operating at much higher frequency, but I donot calculate the frequency at every loop, instead I am counting my main loop and when it matches a certain count (roughly estimated), then I calculate the frequency, and reset the count variable. |
|
|
|
如已经提出的,改变中断优先级不是禁用中断的方法。在临界段之前使用值为0的DISI指令,然后在临界段之后使用DISI=0来禁用中断。如果你还没有弄懂didii指令,那就读一读。
以上来自于百度翻译 以下为原文 As has already been mantioned, changing the interrupt priority is NOT the way to disable interrupts. Use the DISI instruction with a value >0 before the critical section, then use DISI = 0 after the critical section to disable interrupts. If you haven't worked out what the DIDI instruction does then Read The Fine Manual. |
|
|
|
有人忽视了艾伦的SIG消息,并试图引用他的帖子。这是一个虚构的信息,让这个话题从“未读主题”列表中掉下来。
以上来自于百度翻译 以下为原文 Someone disregarded Alan's sig message, and tried to quote his post. This is a dummy message to allow this topic to fall off the "unread topics" list. |
|
|
|
我不确定你是怎么做的。假设你正在使用系统时钟或一个定时器,这意味着你知道计数器在递增的频率,你捕获计数器读取每16个输入脉冲。这意味着“CAP1”(使用你的变量名)将捕获计数器在第一个脉冲和“CAP2”计数器在第十六。因此,每个脉冲的瞬时频率(在16个脉冲上的平均值)是为什么需要在主回路中计数,当它们触发时,ISR会被扰乱。它也应该给你一些想法。你可能还需要把频率值从8增加到更多位,也改变将值发送到PC的方式,但是使用适当大小的缓冲器是相当直接的——底层技术是相同的。苏珊
以上来自于百度翻译 以下为原文 I'm not sure I follow how you are doing this. Assuming that you are using the system clock or one of the timers which means you know the frequency the counter is incrementing at, you capture the counter reading every 16 input pulses. That means 'cap1' (to use your variable names) will capture the counter at the first pulse and 'cap2' the counter at the 16th. Therefore the instantaneous 'frequency' of each pulse (averaged over the 16 pulses) is clock_freq * 16 / (cap2-cap1) Why is there any need to count in the main loop which is going to be upset by the ISRs when they trigger. I would write something like: volatile int cap1, cap2; volatile int ic_flag; uint8 tx_freq; void _ISR_ _IC1Interrupt(void) { _IC1IF = 0; cap1 = IC1BUF; // Get the first time capture cap2 = IC1BUF; // Get the time capture 16 pulses later ic_flag = 1; // Tell the main loop to calculate the frequency } void _ISR_ _U1RXInterrupt(void) { _U1RXIF = 0; UTRXREG = tx_freq; // Send the last calculated frequency } main() { uint32 calc_freq; tx_freq = 0; // Dummy initial value ic_flag = 0; // Initialise the oscillator, PPS, UART and Input Capture using the Fosc while(1) { if(ic_flag) { // We have new timing values calc_freq = fosc * 16 / (cap2 - cap1); // Perform the calculation // Scale the value to fit into a byte __builtin_disi(20); // Ensure the following move is done atomically tx_freq = calc_freq; __bultin_disi(0); // Let the interrupts happen ic_flag = 0; // Show that we have done our bit } } } There is a whole lot wrong with the above code (e.g. no error handling etc.) but it should give you some idea of what to do. You may also need to expand the frequency value from 8 to more bits and also alter the way that send the value to the PC but that is fairly straight forward using an appropriately sized buffer - the underlying technique is the same. Susan |
|
|
|
只有小组成员才能发言,加入小组>>
5275 浏览 9 评论
2048 浏览 8 评论
1962 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3225 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2272 浏览 5 评论
806浏览 1评论
701浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
635浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
695浏览 0评论
592浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-1-6 06:56 , Processed in 1.479793 second(s), Total 72, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (威廉希尔官方网站 图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号