完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
电子发烧友论坛|
大家好,我试图打开一个LED(这是物理连接在RD0),当有一个上升沿RA0,我想这样做与中断。每当RA0上有前缘时,LED必须改变状态。我能够做到这一点而不中断,但我错过了一些前沿,这就是为什么我想使用中断。我在MPLAB V4.05和MCC3.55.1和XC8 1.45编译器与PIC18F45 K20。这是我的中断代码和我的PixMaulror感谢大家的帮助。
Pin管理器C(2.79 KB)-下载52次 以上来自于百度翻译 以下为原文 Hi everyone, I am trying to turn on a led (which is physically wired at RD0), when there is a rising edge on RA0 and i want to do this with interruption. the led has to change state everytime there is a front edge on RA0. i was able to do this without interruption but i was missing some front edge this is why i want to use interruptions. I am on Mplab V4.05 and mcc 3.55.1 and xc8 1.45 compiler with the pic18F45K20. Here is my interrupt code and my pin_manager Thanks everyone for your help. Attachment(s) interrupt_manager.c (2.60 KB) - downloaded 57 times pin_manager.c (2.79 KB) - downloaded 52 times |
|
相关推荐
18个回答
|
|
|
在这个PIC PORTA上没有中断更改能力,只有PORTB & lt;4:7& GT有这个特性。您的Pin管理器代码正在处理It0输入(这是在PoLTB & lt;0和gt;-r0),而不是PORTA。您的中断管理器代码与T0I/T0F一起工作,如果是Time0,而不是在A端口输入。陆上通信线。所以这是非常混乱的,它应该如何工作。也许张贴所有的代码将有助于使它更清晰。
以上来自于百度翻译 以下为原文 On this pic PORTA does not have interrupt on change capability, only PORTB <4:7> have this feature. Your pin_manager code is dealing with the INT0 input (this is on PORTB <0> - RB0) not PORTA. Your interrupt_manager code is working with T0IE/T0IF which is for timer0, not a port input at all. So this is very confusing as to how it is supposed to work. Maybe posting ALL the code would help make it clearer. |
|
|
|
|
|
即使在可用的情况下,也不建议对更改进行中断;如果可能的话,您应该使用INT PIN。你期望的脉冲宽度是多少?您可以在计时器中断中查询输入。
以上来自于百度翻译 以下为原文 Interrupt on change is not recommended for this purpose even if it was available; you should use the INT pin if possible. What sort of pulse widths are you expecting? You could poll the input in a timer interrupt. |
|
|
|
|
|
为什么????我经常在一个PIC上使用多个IOC引脚(和它们的中断)来读取来自电机编码器、速度传感器、快速过电流脱扣器和各种类型的脉冲。完全适用于电机/发动机速度控制、LCD控制面板、etc. Kdt……。尝试一个PORTB IOC引脚为您的触发输入边缘。P.S.为什么你使用“大规模”PIC18F45 K20这样一个简单的任务?特里沃
以上来自于百度翻译 以下为原文 Why ???? I very often use multiple IOC pins (and their interrupts) on one PIC to read pulses from motor encoders, speed sensors, fast over-current trips and all sorts. Works perfectly (so far, on hundreds of production PCB's) for motor / Engine speed controls, LCD control panels, etc. Kdt .... try one of the PortB IOC pins for your trigger input edges. P.S. why are you using the "MASSIVE" PIC18F45K20 for such a simple task ? Trevor |
|
|
|
|
|
因为它在OP的PIC上是不可靠的。这是在数据表中记录的。
以上来自于百度翻译 以下为原文 Because it's not reliable on the OP's PIC. This is documented in the data sheet. |
|
|
|
|
|
数据表表示,在ISR期间,如果将PORTB保存到一个RG“LaSTPORTB”,那么下一个ISRCAN检查一下,在一个RBIF(Interc&lt;0 & gt)中断之后,哪个IOC被改变了。
以上来自于百度翻译 以下为原文 The data sheet says The interrupt-on-change feature is recommended for wake-up on key depression operation and operations where PORTB is only used for the interrupt-on-change feature. Polling of PORTB is not recommended while using the interrupt-on-change feature During ISR, if you save PortB to a reg "LASTPORTB" , then next ISR can check to see which IOC bit changed, after an RBIF (INTCON<0>) interrupt. It works, believe me. |
|
|
|
|
|
|
|
|
|
|
|
是的,但是当一个IOccEnter发生变化时,这会导致一个RBIF中断。一旦在ISR中,进一步的改变将等待下一个ISR。选择是否使用它。它工作,相信我。我有许多速度控制系统与X3电机编码器一起使用OnEPIC,用X3IOC引脚。特里沃。
以上来自于百度翻译 以下为原文 Yes, but as change occurs on an IOC input, this causes an RBIF interrupt. Once in ISR, further changes will wait for next ISR. Choose to use it or not ....... It works, believe me. I have many speed control systems working with x3 motor encoders at once, using one PIC, with x3 IOC pins. Trevor |
|
|
|
|
|
回到主题…KDT…尝试一个PORTB IOC引脚为您的触发输入边缘。P.S.为什么你使用“大规模”PIC18F45 K20这样一个简单的任务?特里沃
以上来自于百度翻译 以下为原文 Back to the subject .... Kdt .... try one of the PortB IOC pins for your trigger input edges. P.S. why are you using the "MASSIVE" PIC18F45K20 for such a simple task ? Trevor |
|
|
|
|
|
不,它没有,正如数据表明确地说:RBIF中断标志可能不被设置。如果它在你的应用程序中工作,并且你不关心数据表所说的内容,那就太好了。但你会发现论坛上的其他人并不那么幸运。
以上来自于百度翻译 以下为原文 No, it doesn't, as the data sheet explicitly says: the RBIF interrupt flag may not get set. If it works in your application and you're not concerned about what the data sheet says, great. But you'll find other people on the forum who aren't quite so lucky. |
|
|
|
|
|
Himaybe原来的海报是使用PIC18F45 K20,因为它是在他手中的开发板上可用的设备。PIC18F45 K20在开发板上与PICkit 3一起在DV164131封装中使用,在好奇心板已经可用之后不再被提升。无论如何,如果感测到的信号来自按钮或其他机械开关,那么仍然可能有学习经验。在进行中,无论程序轮询端口寄存器RA0,中断对KBI引脚之一的更改,或外部中断的ITEX引脚之一。如消息1中所提到的,丢失一些前缘,也可能检测到2或4或…边缘快速排列。迈西尔
以上来自于百度翻译 以下为原文 Hi Maybe the original poster is using PIC18F45K20 because it is the device available on the development board he have at hand. PIC18F45K20 is used on development board distributed together with PICkit 3 in the package dv164131. It is no longer promoted much after Curiosity boards have become available. Anyway, if the signal beeing sensed is from a push-button or other mechanical switch, there may still be a learning experince in progress, regardless of the program polling Port register RA0, Interrupt on Change on one of the KBI pins, or one of the External Interrupt INTx pins. '... missing some front edge' as mentioned in message #1, might just as well have been detecting 2 or 4 or ... edges in rapid sequence. Mysil |
|
|
|
|
|
嗨,谢谢大家。“Kdt…尝试一个PORTB IOC引脚为您的触发输入边缘。P.S.为什么你使用“大规模”PIC18F45 K20这样一个简单的任务?我在波尔图尝试过,效果不错。我想通过使用PoTa来做同样的事情,但是在仔细阅读数据表之后,我想我不能。我使用PIC18F45 K20,因为我只是张贴了这部分代码,因为我遇到了中断问题,但是最后使用它有点复杂,这个PIC有广告。低功耗的优势!我的主要问题是我的所有条目都是物理连接到波尔塔和一个外部系统,我用一个方形信号驱动它们,它们可以从10秒到50ms不等。在我的原始代码(不中断)下,我检测到上升沿,并且执行我的条件。但是当采集系统是快或慢的时候,我错过了一些上升的边缘。这就是为什么我有使用中断的想法,所以只有当我检测到上升的边缘将不再做别的事情时,我才会执行我的条件。问题是,没有改变硬件的方法,有没有办法做到这一点?这里是我的代码,没有中断:空main(空隙){/*初始化模块,Mat Eyres和HordLoges *//HORLoges HalyStuleSyIn();//GPIO HalthGPIOION();/*变量Loals*/unChar char MeM1=0;而(1){MeM1= PoTa;S(5);//如果这个延迟太长或太短,我会错过上升沿…如果(波尔塔)!= MEM1){()PARABABIT.RA0&AMP;(MEM1和AM&0X01)PARABABIT.RA1&AMP;(MEM1和AM&0x02)PARABABIT.RA2&AMP;(MEM1和AM&0X04)PrababITS.RA3&AMP;(MEM1和AM&0x08)PrababITS.RA4&AMP;(MEM1和AM&0x10)Prababist.Ra&&;(MEM1和A&0x20)){PrdBoSt.RD0=1;//首脉冲重置端口;RC1=1;PrdBoSt.RD7=1;PrdBoSt.Rd3=1;PrtCbStudio。RC3=1;PrdButs.RD5=1;=0;//鳍脉冲重置端口;RC1=0;PrdBoTS。RD7=0;PrdBosits。RD3=0;PrtCbStudio。RC3=0;PrdBosits。RD5=0;γ-DelayyMS(10);} PtdBrd.Rd1=!PARABABIT.RA0&AMP;(MEM1和AM&0X01);/ /首次脉冲PORTCITS。RC0=!PARABABIT.RA1&AMP;(MEM1和AM&0x02);PARABABIT.RA2&AMP;(MEM1和AM&0X04);PARABABIT.RA3&AMP;(MEM1和AM&0x08);PARABABIT.RA4&AMP;(MEM1和AM&0x10);PARABABIT.RA5&AMP;(MEM1和AM&0X20);γ-DelayyMS(20);PORTD=0;/ /鳍去脉冲POTC=0;}
以上来自于百度翻译 以下为原文 Hi , thanks everyone. "Kdt .... try one of the PortB IOC pins for your trigger input edges. P.S. why are you using the "MASSIVE" PIC18F45K20 for such a simple task ?" I tried this on PortB and it is working fine. i wanted to do the same thing by using PortA, but after reading carefully the datasheet i think i can't. i am using the PIC18F45K20 because i posted just this part of the code because i am having problems with interruption but for the end using it is a little bit more complex and this PIC has the advantage to be low power! My main issue is that all my entries are physically connected to PortA and by an external system, i am driving them with a square signal which can vary from 10µs to 50ms. On my original code(without interruption) i detect a rising edge and i execute my conditions. but when the acquisition system is quick or slow i miss some rising edge. That's why i had the idea of using interruptions, so that i will execute my condition only when i detect the rising edge will do nothing else before. the problem is , is there a way to do this without changing my hardware? Here is my code without interruption : void main ( void) { /* Initialisations des modules matériels et des horloges */ // Horloges HAL_SYSTEM_Init(); // GPIO HAL_GPIO_Init(); /* Variables locales*/ unsigned char mem1 =0; while(1) { mem1 = PORTA; __delay_ms(5); //if this delay is too long or too short i miss rising edges.... if (PORTA!=mem1) { if ( (!PORTAbits.RA0 && (mem1 && 0x01))|| (!PORTAbits.RA1 && (mem1 && 0x02))|| (!PORTAbits.RA2 && (mem1 && 0x04))|| (!PORTAbits.RA3 && (mem1 && 0x08))|| (!PORTAbits.RA4 && (mem1 && 0x10))|| (!PORTAbits.RA5 && (mem1 && 0x20)) ) { PORTDbits.RD0=1;//debut pulse reset PORTCbits.RC1=1; PORTDbits.RD7=1; PORTDbits.RD3=1; PORTCbits.RC3=1; PORTDbits.RD5=1; __delay_ms(20); PORTDbits.RD0=0;// fin pulse reset PORTCbits.RC1=0; PORTDbits.RD7=0; PORTDbits.RD3=0; PORTCbits.RC3=0; PORTDbits.RD5=0; __delay_ms(10); } PORTDbits.RD1= !PORTAbits.RA0 && (mem1 && 0x01); // debut pulse PORTCbits.RC0= !PORTAbits.RA1 && (mem1 && 0x02); PORTDbits.RD2= !PORTAbits.RA2 && (mem1 && 0x04); PORTDbits.RD4= !PORTAbits.RA3 && (mem1 && 0x08); PORTCbits.RC2= !PORTAbits.RA4 && (mem1 && 0x10); PORTDbits.RD6= !PORTAbits.RA5 && (mem1 && 0x20); __delay_ms(20); PORTD=0; // fin de pulse PORTC=0; } |
|
|
|
|
|
不,如果你想在改变功能上使用中断,它在波尔塔上不存在。
以上来自于百度翻译 以下为原文 No, not if you are trying to use interrupt-on-change functionality, it does not exist on PORTA on this pic. |
|
|
|
|
|
你希望用5毫秒的延迟来捕获10个美国脉冲?而且你的代码是错误的;你使用的是你的意思。
以上来自于百度翻译 以下为原文 How do you expect to catch 10 us pulses with a 5 ms delay? And your code is wrong; you're using && where you meant &. |
|
|
|
|
|
“你希望如何捕捉5毫秒延迟的10个脉冲?你的代码是错误的;你使用的是& & &;你的意思是,“即使有50毫秒的脉冲,我还是会错过一些……我认为,对于第二个问题,你可能是对的!PARABABIT.RA1&AMP;(MEM1和0x01)),但不是第一个,因为我想要这2个条件(!Prababist.Ra1和(MEM1和AM&0x01)是正确的。我会尝试,但我不认为问题是从这里。“不,如果你试图使用中断的变化功能,它不存在于波尔塔上的这张照片。”你能告诉我在PIC参考与几个IOC引脚(超过6针具有此功能性)我搜索,但找不到。有,谢谢你的帮助。
以上来自于百度翻译 以下为原文 "How do you expect to catch 10 us pulses with a 5 ms delay? And your code is wrong; you're using && where you meant &." Even with 50ms pulses, i still misses some... and i think for the & thing you may be right for the second (!PORTAbits.RA1 && (mem1 & 0x01)) but not for the first because i want the 2 conditions (!PORTAbits.RA1 AND (mem1 && 0x01)) to be true. i will try that but i don't think the problem is from here. "No, not if you are trying to use interrupt-on-change functionality, it does not exist on PORTA on this pic." Can you advive me on a pic reference with several IOC pins (more than 6 pins with this functionnality) i searched but couldn't find any. Thanks for your help. |
|
|
|
|
|
Javple并没有说“& & &”的每一个标准都是错误的,但是“(MEM1和AM&0x01)”当然不应该是使用和&我假定您忘记在第二个例子中修复它。
以上来自于百度翻译 以下为原文 jtemples did not say EVERY instrance of "&&" is wrong, but "(mem1 && 0x01)" certainly should not be using &&. I assume you forgot to fix it in your second example. |
|
|
|
|
|
“我想你忘了在第二个例子中修正它。”是的,你说得对,我忘了。条件是:(!)PaababITI. RA1和AMP(MEM1和0x01)
以上来自于百度翻译 以下为原文 "I assume you forgot to fix it in your second example." Yes you are right, i forgot. the condition will be : (!PORTAbits.RA1 && (mem1 & 0x01)) |
|
|
|
|
|
18FXXK40系列在每个引脚上都有中断,它也没有上面提到的IOC错误。较新的PIC16F部件通常也有许多IOC引脚没有错误。
以上来自于百度翻译 以下为原文 The 18FxxK40 family has interrupt on change on every pin, and it also does not have the IOC bug I mentioned above. Newer PIC16F parts also typically have many IOC pins without the bug. |
|
|
|
|
|
18FXXK40系列在每个引脚上都有中断,它也没有上面提到的IOC错误。新的PIC16F部件通常也有很多IOC引脚,没有bug。谢谢,这非常有帮助。
以上来自于百度翻译 以下为原文 The 18FxxK40 family has interrupt on change on every pin, and it also does not have the IOC bug I mentioned above. Newer PIC16F parts also typically have many IOC pins without the bug. Thank you, this is very helpful. |
|
|
|
|
只有小组成员才能发言,加入小组>>
MPLAB X IDE V6.25版本怎么对bootloader和应用程序进行烧录
473 浏览 0 评论
5793 浏览 9 评论
2334 浏览 8 评论
2224 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3530 浏览 3 评论
1122浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
1095浏览 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 00:17 , Processed in 1.884650 second(s), Total 106, Slave 89 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
1807