完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我正在使用控制器:PIC18F45K80,IDE:MPLABX IDE和编译器:XC8 pro。在目前的工作项目中,RB0引脚配置成上电时的上升沿外部中断。要求重新配置相同的引脚用于上升沿检测的下降沿。尝试改变配置在ISR例程中,如下所示。它对上升沿很有效,之后当它配置下降沿时它就不工作了。从上升沿到下降沿的重新配置中是否缺少任何东西。我不能使用“RB端口更改中断”,因为RB0没有提供。有任何建议。n?提前感谢…!!!
以上来自于百度翻译 以下为原文 Hello Everyone, I am using controller: PIC18F45K80, IDE: MPLABX IDE and Compiler: XC8 pro. In currently working project, RB0 pin is configured as rising edge external interrupt at power up. Requirement is to reconfigure the same pin for falling edge on rising edge detection. Trying to change the configuration with in ISR routine as follows. if((INTCONbits.INT0IF && INTCONbits.INT0IF)) { // Clear the interrupt flag INTCONbits.INT0IF = 0; if(INTCON2bits.INTEDG0 == 1) //interrupt is triggered on falling edge. INTCON2bits.INTEDG0=0; else //interrupt is triggered on faising edge. INTCON2bits.INTEDG0=1; //Enable INT1 External Interrupt INTCONbits.INT0IE=1; } It is working good for raising edge and after that it when it configured falling edge its not working. Is there anything missing in reconfiguring from rising edge to falling edge. I can't use "RB Port Change Interrupt" as RB0 doesn't have provision. Any suggestion? Thanks in Advance...!!! |
|
相关推荐
10个回答
|
|
为项目做一些特定的逻辑:逻辑有多少?脉搏有多宽?这是你的开关吗?如果(IntNo.In0&I&Ap&OncTun.Itn0IE)/ /您不需要IncNIT.It0IE,如果它从来没有禁用{//清除中断旗语。In0IF=0;如果(ItNCO2BITS,ITEDG0==1)/ /中断在下降沿触发。Time.InCON2BIT.IndigG0=1;//在时间关键性的东西之后执行此操作,并且为项目& GT做一些特定的逻辑;/ /如果需要很长的时间,则不要在中断中执行。//启用Int1外部中断/ /内插。如果没有启用,你就不会在这里。}
以上来自于百度翻译 以下为原文 How Much Logic? How Wide is the Pulse? Is it do befor you switch? if((INTCONbits.INT0IF && INTCONbits.INT0IE)) //you do not need INTCONbits.INT0IE if it is never disabled { // Clear the interrupt flag INTCONbits.INT0IF = 0; if(INTCON2bits.INTEDG0 == 1) //interrupt is triggered on falling edge. INTCON2bits.INTEDG0=0; else //interrupt is triggered on faising edge. INTCON2bits.INTEDG0=1; // do this after the time critical stuff, // If it takes a long time, then do not do in in the interrupt. //Enable INT1 External Interrupt //INTCONbits.INT0IE=1; // why are you enabling this? if it was not enabled you would not be here. } |
|
|
|
在你试图做的事情中有一个竞赛条件:如果在PIC到达ISR代码之前边缘再次切换,ISR将ItIdg设置为错误的值。您可以通过使用中断优先级来缩小窗口,而不是测试ItnIF,在ISR结束时清除ItnIF,并执行ItnC2BIT.IndigG0=!ItnC2BIT.IntIG0而不是“IF”语句(或任何变体给您一个BTG指令)。
以上来自于百度翻译 以下为原文 There's a race condition in what you're trying to do: if the edge toggles again before the PIC gets to your ISR code, the ISR sets INTEDG to the wrong value. You can narrow the window by using interrupt priorities, not testing INT0IF, clearing INT0IF at the end of the ISR, and do INTCON2bits.INTEDG0 = !INTCON2bits.INTEDG0 instead of the "if" statement (or whatever variant gives you a BTG instruction). |
|
|
|
非常感谢你的回应,我将使用3个标志。非常小的指令。I ActNoBix.It00IE=1在上电并在功能结束时再次启用(IncNord.Itn0IE=1),因为配置从上升到下降。不管这个声明和逻辑对我的项目是什么,我也有同样的问题。
以上来自于百度翻译 以下为原文 Thank you very much for your response. The logic i am going to use setting 3 flags. very minimal instructions. I am INTCONbits.INT0IE=1 at power up and enabling again (INTCONbits.INT0IE=1 ) at the end of function as the configuration changed from rising to falling. irrespective of this statement and logic specific to my project also I have the same problem. |
|
|
|
除非你禁用它,否则你不需要重新启用密码。脉宽有多大?按你的时钟速率有多少个指令?
以上来自于百度翻译 以下为原文 You do not need to re-enable INTCONbits.INT0IE unless you disable it. How Wide is the Pulse? How many instructions is that at your Clock rate? |
|
|
|
那不是必要的。永远不会改变自己的价值。你缺少的一件事是改变Itdig0可以设置In0f,因此你应该在改变ItIdG0之后清除It0f。
以上来自于百度翻译 以下为原文 That isn't necessary. INT0IE will never change value on its own. One thing you are missing is that changing INTEDG0 may set INT0IF, so you should clear INT0IF after changing INTEDG0. |
|
|
|
非常感谢你不生脉。具体的设备功率信号是连接RB0。其他设备的功率损耗和上电应该很快被检测。我的时钟配置为32mhz。在这些事件上递增现有变量并设置标志。在启动时,外部中断被初始化为TRISBbit.TRISB0=1;INTCON2bits.INTEDG0=1;INTCONbits.INT0IF=0;INTCONbits.INT0IE=1;ANCON1bits.ANSEL10=0;ISR代码类似于//如果设置了Timer标志并且启用了中断DIF((InCONTITS.IT0IF){ItNCO2BIT.ITCDG0=!INTCON2bits.INTEDG0Flag=1;//清除中断标志INTCONbits.INT0IF=0;}检测上升沿但不检测下降沿。尝试给出建议但仍面临相同问题。
以上来自于百度翻译 以下为原文 Thank you very much for your not generating pulse. To be specific power signal of device is connected RB0. Power loss and power up of another device should be detected very quickly. My clock is configured for 32mhz. On these events increment existing variable and setting flag will be done. At power up external interrupt is initialized as TRISBbits.TRISB0=1; INTCON2bits.INTEDG0=1; INTCONbits.INT0IF=0; INTCONbits.INT0IE=1; ANCON1bits.ANSEL10=0; The ISR code is similar to // If Timer flag is set & Interrupt is enabled if((INTCONbits.INT0IF ) { INTCON2bits.INTEDG0 =!INTCON2bits.INTEDG0 Flag =1; // Clear the interrupt flag INTCONbits.INT0IF = 0; } Detecting the rising edge but not falling edge. Tried with given suggestions but still facing same problem. |
|
|
|
我认为您想要的是二进制补码,而不是逻辑非运算符“!”你是使用模拟器还是实际硬件?可能在过渡波形上有噪声。
以上来自于百度翻译 以下为原文 I think you want ~INTCON2bits.INTEDG0 for the bitwise complement, rather than the logical NOT operator "!". Are you using the simulator, or actual hardware? Perhaps there is noise on the transition waveform. |
|
|
|
|
|
|
|
|
|
|
|
是的,这通常会生成更小的代码。但是没有功能上的差异。
以上来自于百度翻译 以下为原文 Yes, that typically generates smaller code. But there's no functional difference. |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
733浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
505浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 08:35 , Processed in 1.265283 second(s), Total 66, Slave 59 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号