完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我正在尝试制作一个PID控制器,我需要两个中断,一个用于检测AC电流交叉为零(第一个图像),另一个用于使用time0计数时间,以便能够应用我的PID算法(第二个图像)。问题是,我只能执行一个或另一个,而不是。同时,这取决于我如何选择优先权。基本代码是下一个:如何执行这两个中断?帮助
以上来自于百度翻译 以下为原文 I am trying to make a PID controller, I need two interrupts, one for detecting the AC current crossing for zero (First image), and the other for counting the time using the Timer0 in order to able to apply my PID algorithm (Second image). The problem is that I can only execute one or the other, not both at the same time, and that depends of how I choose the priority. The basic code is the next: #include #include #include ////////////////////////////////////////////////////////////////////////////////////// /// CONFIGURATION BITS. Search for the PIC18F4550 in the help documentation (F1) ///// /// to understand how to configure the MCU ///// ////////////////////////////////////////////////////////////////////////////////////// #pragma config PLLDIV = 5, CPUDIV = OSC1_PLL2, USBDIV = 2 #pragma config FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF #pragma config PWRT = OFF, BOR = OFF, VREGEN = OFF #pragma config WDT = OFF, WDTPS = 32768 #pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF #pragma config STVREN = ON, LVP = OFF, ICPRT = OFF, XINST = OFF #define _XTAL_FREQ 48000000 ///////////////////////////////////////////////////////////////////////////////////// /// INTERRUPTS PROGRAMMING ////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// int i = 0; //void SetupClock(void); bit flag; //Declare the Flag bit int time = 150; // Time it takes to send the trigger voltage (Time*0.01 ms) unsigned char Timer0Config; int main() { PORTB = 0x00; LATB = 0x00; TRISB = 0xD9; // RB7-1 RB6-1 RB5-0 RB4-1 RB3-1 RB2-0 RB1-0 RB0-1 ( 1 = Input, 0 = Output) ////// OPTOTRIAC INTERRUPT INITIATION //////////////////////////////////////////// //TRISBbits.RB0 = 0; //set RB4 as output INTCONbits.INT0E = 1; //enable Interrupt 0 (RB0 as interrupt) INTCON2bits.INTEDG0 = 1; //cause interrupt at falling edge INTCONbits.INT0F = 0; //reset interrupt flag ei(); // This is like fliping the master switch to enable interrupt flag = 0; // Flag Variable initialization ////// TIMER INTERRUPTS INITIATION /////////////////////////////////////////////// TRISAbits.RA4 = 0; //set RB4 as output LATA4 = 0; //Make RB4 high when the program starts Timer0Config = TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_1 ; // Timer0 configuration OpenTimer0(Timer0Config); WriteTimer0(0x1); //Please use HEX. Decimal don't work //WriteTimer0(0xE17B); INTCONbits.TMR0IF = 0; //reset Interrupt Flag ei(); // This is like fliping the master switch to enable interrupt while(1) { } } void interrupt high_priority CheckButtonPressed() { if(INTCONbits.INT0F == 1) //Checks Receive Interrupt Flag bit { for (int count=0; count LATBbits.LATB5 = 1; __delay_ms(0.1); //Generate 300ms delay LATBbits.LATB5 = 0; INTCONbits.INT0F = 0; // Clear Interrupt Flag } } void interrupt low_priority TimerOverflow() { if(INTCONbits.TMR0IF == 1) { LATA4 = ~LATA4; INTCONbits.TMR0IF = 0; } } How can I execute both interrupts? Help |
|
相关推荐
10个回答
|
|
|
|
|
|
对于两个中断,不需要两个中断处理程序。只需在优先级高的中断中测试两个IF标志,看看它是哪一个中断。这两个中断处理程序用于中断优先级,而这些中断优先级是不需要的,并且它们不工作的原因是您没有启用中断优先级。
以上来自于百度翻译 以下为原文 You don't need two interrupt handlers for two interrupts. Just test the two *IF flags in your high priority interrupt to see which interrupt it is. The two interrupt handlers are for interrupt priorities, which you don't need, and the reason they aren't working is that you haven't enabled interrupt priorities. |
|
|
|
您的PIC只有一个核心,它不能同时运行两位代码。关键是要使一个需要最低延迟的“高优先级”一个(即您的过零点),并使两个中断服务例程尽快退出。所有的慢/阻塞代码都必须在中断服务之外运行。
以上来自于百度翻译 以下为原文 Your PIC only has one core, it can't run two bits of code at the same time. The key is to make the one that requires the lowest latency the "high priority" one (i.e. your zero-crossing), and make both interrupt service routines exit as soon as possible. Do the bare minimum required inside the ISR, then get out of there. All slow/blocking code has to be run outside the interrupt service. |
|
|
|
你启用优先权了吗?伊本在RCON?然后,需要设置优先级来分配每个中断优先级。
以上来自于百度翻译 以下为原文 Did you enable Priority? IPEN in RCON? Then you need to set the Priority to assign each interrupt a Priority. |
|
|
|
我不知道怎么做。我是微控制器领域的新手。另外,我认为我在中断功能中需要最低限度的最低限度。
以上来自于百度翻译 以下为原文 I don't how to enable it . I am new in the microcontrollers world. Also I think I am making the bare minimum required in my interrupt functions |
|
|
|
所有这些神秘信息都隐藏在PIC数据表中。
以上来自于百度翻译 以下为原文 All this arcane information is hidden in the PIC datasheet. |
|
|
|
最小方法:执行需要多长时间。你不应该在中断处理程序中延迟,特别是高优先级中断!重新思考如何在没有这些延迟的情况下做到这一点。
以上来自于百度翻译 以下为原文 Minimum means: how long it takes to execute. You should not put a delay in the interrupt handler. Especially the high priority interrupt! Rethink how you can do this without those delays. |
|
|
|
而且,AHEM:
以上来自于百度翻译 以下为原文 And, ahem: WriteTimer0(0x1); //Please use HEX. Decimal don't work really? [:)] |
|
|
|
U不需要两个不同的ISR功能,首先U分配优先级为UR中断,并且在高优先级中断功能中写入另一个低优先级中断功能,U只需要一个ISR功能。
以上来自于百度翻译 以下为原文 u dont need two different ISR function,first u assigned priority to u r interrupts ,and write another low priority interrupt function in high priority interrupt fiunction, u need only one ISR function and if(INTCONbits.TMR0IF == 1) instead of this try following syntax for both interrupt if(INTCONbits.TMR0IF) |
|
|
|
我告诉你在RCON寄存器中的iPin位。下载你的芯片的数据表并查找它。有一段中断。或者你质疑什么是适当的语法来实现它?
以上来自于百度翻译 以下为原文 I told you the IPEN bit in the RCON register. Download the data sheet for your chip and look it up. There is a whole section on interrupts. Or is you question what is the proper syntax to enable it? |
|
|
|
只有小组成员才能发言,加入小组>>
5253 浏览 9 评论
2038 浏览 8 评论
1958 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3219 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2267 浏览 5 评论
792浏览 1评论
686浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
617浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
686浏览 0评论
586浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-30 09:54 , Processed in 1.708269 second(s), Total 101, Slave 82 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号