完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我正在制作一个应用程序,它通过Modbus通信到一个设备上,我想检测它们之间是否存在通信丢失,以便激活一个警报。好的,我已经实现了一个带有TMR2的计时器,如果没有20个以上的APROX,就可以激活警报。它可以正常工作,闹钟被激活,但是经过一段时间后,计数器复位,警报被解除,直到另一个20秒的通信丢失。我把代码的碎片留给了我,因为任何人都能告诉我问题是什么,因为我不能用FI。任何感觉…TMR2Y-中断复位到0 TMR2Y计数器,如果我收到任何数据,只有在RXI中断。当计数器复位时,没有RXI中断,我已经证明了。报警管理如果您需要更多信息,不要犹豫问我。希望有人能给我一些启示,因为我疯了…多谢
以上来自于百度翻译 以下为原文 Hi everyone, I am making an application that communicates by MODBUS to a device and I want to detect if there is a loss of communication between them so as to activate an alARM. Ok, i have implemented a timer with TMR2 so as to activate the alarm if there are more than 20 seconds aprox without communication. It works all right, the alarm is activated but after a period of time the counter resets itself and the alarm is desactivated untill another 20s of loss of communication. I left you the fragment of code where I implement this so as anyone could show me what the problem is because i can´t find any sense.... TMR2_Interrupt //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //+INTERRUPT SERVICE ROUTINE //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //----------------------------------------------------------------------------- //- HIGH INTERRUPT Addressing - //----------------------------------------------------------------------------- #pragma code HighInterruptVector = 0x0008 void HighInterruptVector (void) { _asm goto HighInterruptRoutine _endasm } //----------------------------------------------------------------------------- //- HIGH INTERRUPT Function - //----------------------------------------------------------------------------- #pragma interrupt HighInterruptRoutine void HighInterruptRoutine (void) { if (PIR1bits.TMR2IF) { if (TMR2_Counter <= 1250) //20 seconds { TMR2_Counter ++; } PIR1bits.TMR2IF = 0; //CLEAR TMR2 flag } } I reset to 0 the TMR2_Counter if I receive any data, only in the Rx_Interrupt. When the counter resets there is not Rx_Interrupt, I have already proved that. Alarm managing if(Alarm1 != 0 | Alarm2 !=0) { if (Alarm1 == 0x0003 & Alarm2 == 0x0000) //Loss of synchronism with the motor Alarm { alarmCounter = 0; //Reset Alarm counter syncAlarmCounter_Aux ++; if (syncAlarmCounter_Aux > 32000) //1 second { syncAlarmCounter_Aux = 0; syncAlarmCounter ++; if (syncAlarmCounter > 15) //Seconds of Time Out for loss of synchronism alarm { PORTCbits.RC0 = 0; //Activate Relay if loss of synchronism alarm detected while x period of time (Negative Logic) PORTCbits.RC1 = 0; } } } else //For any other alarm activate Relay { alarmCounter_Aux ++; syncAlarmCounter = 0; //Reset the loss of synchronism Alarm counter if (alarmCounter_Aux > alarmTimeOut_Aux) { alarmCounter_Aux = 0; alarmCounter ++; if (alarmCounter > alarmTimeOut) { PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic) PORTCbits.RC1 = 0; } } } if (TMR2_Counter > 1250) //20s without RS485 communication { PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic) PORTCbits.RC1 = 0; } } else { alarmCounter = 0; syncAlarmCounter = 0; //Reset the loss of synchronism Alarm counter if (TMR2_Counter > 1250 ) //20s without RS485 communication { PORTCbits.RC0 = 0; //Activate Relay if alarm detected (Negative Logic) PORTCbits.RC1 = 0; } else { PORTCbits.RC0 = 1; //Desactivate Relay if no alarm detected PORTCbits.RC1 = 1; } } If you need more info don´t hesitate to ask me. Hope anyone could bring some light to this, because I´m getting mad... Many thanks |
|
相关推荐
3个回答
|
|
你有没有向自己证明你没有得到意外的重置(WDT,堆栈过/下溢,…)?我在这一系列处理器中所做的第一件事是分析重置,如果它不是预期的(例如,堆栈溢出是从来没有预料到的),我冻结和闪烁一个“莫尔斯电码”模式,显示意外复位类型的LED。至少有一个NOP,你可以放置断点看看是否有意外的重置。你应该命名确切的处理器,并且至少显示来自“Real'”专家的帮助配置。我只是一个低级汇编程序CODER。GPEDIT 1:“重置”-gt;“意外重置”编辑2:(语法):被证明&被证明。
以上来自于百度翻译 以下为原文 Have you proven to yourself that you're not getting an unexpected reset (WDT, Stack Over/Underflow, ...)? One of the first things I do in this family of processors is to analyze the reset and if it's not one expected (for instance, stack overflow is never expected), I freeze and blink an LED with a "Morse-Code" - like pattern that shows the type of unexpected reset. At least have a nop where you can put a breakpoint to see if you're getting an unexpected reset. You should name the exact processor and at least show the configuration for help from 'real' experts. I'm just a lowly assembler coder. GP Edit 1: "a reset" -> "an unexpected reset" Edit 2: (Grammar): proved -> proven. |
|
|
|
非常感谢GlennP,一旦你说了,我想起了看门狗,这就是问题所在。微控制器由于WDT溢出而复位,所以计数器和所有的变量都被重置。现在它正在工作,正如我所预期的,非常感谢。
以上来自于百度翻译 以下为原文 Many thanks GlennP, once you said it I remembered the watchdog, that was the problem. The microcontroller was reseting itself due to the WDT overflow so the counter and all of the variables were being reset. Now it is working so as I expected, many thanks |
|
|
|
很高兴它的工作。我注意到一件事在你的中断代码。它可能是好的(如果TMR2IE总是真的),但是我通常测试XxxIR和XXXY的逻辑。[我是批量的——ANDing PIEx和Pixx,在测试之前保存结果,但这是效率的细节,因为我通常有很多中断服务,并且我的处理器没有多级中断能力。]
以上来自于百度翻译 以下为原文 Glad it's working. I noticed one thing in your interrupt code. It may be fine (if TMR2IE is always true), but I usually test the logical AND of XxxIR and XxxIE. [I do it in bulk - ANDing PIEx and PIRx and saving the result before testing, but that's a detail for efficiency as I usually have a lot of interrupts being serviced and my processors don't have multi-level interrupt capabilities.] GP |
|
|
|
只有小组成员才能发言,加入小组>>
5166 浏览 9 评论
2000 浏览 8 评论
1928 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3174 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2226 浏览 5 评论
734浏览 1评论
615浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
506浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
631浏览 0评论
528浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-24 22:00 , Processed in 1.169606 second(s), Total 53, Slave 46 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号