完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好。我与PIC16F1947一起工作,在我的电路中有4个触摸按钮。我想一次触摸3或4次按钮,以减少噪音。我的代码是:MTOUCH_Service_Mainloop();if(MTOUCH_Button_isPressed(Button0){._ms(1000);if(MTOUCH_Button_isPressed(Button0)){._ms(1000);if(MTOUCH_Button_isPressed(Button0)){...。} } }我想,如果我的接触时间低于2秒,电路会拒绝它而不感兴趣。但是它不能正常工作!我该怎么办?
以上来自于百度翻译 以下为原文 hi everybody. i work with pic16f1947 and have 4 touch buttons in my circuit. i want to read every button 3 or 4 times in one touching to reduce the noise. my code is: MTOUCH_Service_Mainloop(); if(MTOUCH_Button_isPressed(Button0) { __delay_ms(1000); if(MTOUCH_Button_isPressed(Button0)) { __delay_ms(1000); if(MTOUCH_Button_isPressed(Button0)) { ... } } } i want to if my touching time is under 2 Sec, circuit reject it and not sense it. but it doesn't work properly!! how can i do this? |
|
相关推荐
12个回答
|
|
你好!我用来消除噪声的一个策略是:voidinter.high_.isr(void){if(INTCONbits.INT0F){u._ms(20);if(PORTBbits.RB0==0){PORTB=PORTB^0b00010;}}INTCONbits.INT0F=0;}在上面的代码中,我使用一个连接到RB0的按钮(上拉电阻被启用)我用一个很短的延时来实现一个很好的有效阅读。当一个用户按下按钮,状态将改变为低,但在过渡期间,由于接触按钮,输入将经历从低到高的变化。“if”语句将消除输入高(噪声)的情况。在这种情况下,我使用中断方法,但是很容易调整代码以使用轮询方法来读取输入。
以上来自于百度翻译 以下为原文 Hi! One strategic that I use to eliminate noise is the following: void interrupt high_priority isr(void){ if(INTCONbits.INT0F){ __delay_ms(20); if(PORTBbits.RB0 == 0){ PORTB = PORTB^0b00000010; } } INTCONbits.INT0F = 0; } In the code above, I use a button connected to RB0 (the pull-up resistor is enabled). I use a short delay to achieve a good effective read. When one user presses the button the state will change to low, but during the transition and because of contact button the input will experience changes from low to high. The “if” statement will eliminate the cases in which the input has high (noise). In this case I use interrupt method but is easy to adapt the code to use polling method to read the input. |
|
|
|
战略,但挂在一个ISR许多毫秒也写,以LATX,而不是PORTX。
以上来自于百度翻译 以下为原文 Strategic, but hanging in an ISR for many milliseconds also, write to LATx, not PORTx. |
|
|
|
谢谢!达里奥,去年我从你身上学到了使用LATX代替Poxx。有时候很容易忘记,我也向你学习。达里奥,你认为从ISR内部悬挂几毫秒是很重要的吗?这就是我用一个按钮从软件中消除噪音的方法。另一种方法是使用硬件(锁存器RS)
以上来自于百度翻译 以下为原文 Thanks! Dario. Last year I learned from you to use LATx instead of PORTx. Sometimes it's easy to forget. I am learning from you too. Dario, do you think it's critical to stay a few milliseconds hanging from the inside of an ISR? This is the way I found to eliminate noise trough software frome a button. Other way is to use hardware (Latch RS) |
|
|
|
当然,这通常是不好的做法,如果你的程序没有别的事可做,没有问题。否则,您应该在读取第一个按键之后设置另一个定时器,这样主代码就可以运行了。当新定时器到期时,你再次检查PIN的状态。
以上来自于百度翻译 以下为原文 Well, it is *usually* bad practice Of course, if your program has nothing else to do, no problems. Otherwise, you should set up another timer after the first keypress is read, so that main code can run... and when the new timer expires you go checking the pin's state again. |
|
|
|
嗨,Saye,这不是在固件中去掉mTouch按钮的正确方法。mTouch按钮仅在MTOUCH_Service_Mainloop()内扫描一次。使用MTOUCH_Button_isPressed() ifMTOUCH_Service_Mainloop()将无法获得任何新内容。如果此时系统中确实存在噪声,则始终建议回到硬件设计和mTouch配置。如果你不介意分享它。
以上来自于百度翻译 以下为原文 Hi Saye, This is not a proper way to debounce the mTouch button in firmware. The mTouch buttons only scan once inside MTOUCH_Service_Mainloop(). You will not be able to get anything new using MTOUCH_Button_isPressed() if MTOUCH_Service_Mainloop() is not called again. If you really have noise in your system at this point, it is always recommended to go back to your hardware design and mTouch configurations. I can take a look at your source code if you don't mind sharing it. |
|
|
|
我想看看主代码和中断代码(main.c和inter._manager.c)是如何处理触摸和其他任务的。使用ADC的触摸和其他任务的数据损坏。触摸中噪声的另一个可能原因是硬件布局。你核实过版面了吗?
以上来自于百度翻译 以下为原文 I would like to see how the main code and interrupt code(main.c and interrupt_manager.c) handle the touch and other tasks. Because the mTouch sensing is using an 8-bit timer to schedule the scan in the interrupt and use ADC to perform the scan, if other tasks use the interrupt or ADC, it might cause corrupted data for both touch and other tasks using ADC. The other possible cause for noise in touch is the hardware layout. Have you verified the layout? |
|
|
|
主代码:void main(void){SYSTEM_Initialize();WDTCON=0x25;//watch dog,在128秒后激活INTERRUPT_GlobalInter.Enable();//全局中断激活INTERRUPT_.pheralInter.Enable();//外围中断激活INTCONbits.INTE=1;IOCBPbits.IOCBP0=1;INTCONbits.INTF=0;TMR6=0;4=0;TMR0=0;TMR0=0;B=0;//门1C=0;//门1门1门1=0;门2=0;门2=0;门3=0;门4=0;而同时(1){MTOUCH_Service_Service_MaiMainloop(;如果(MTOUCH_按钮_按钮_按压(按钮0)按钮_按钮_按钮_被按压(按钮0)){led1=1=1=1;1=1=1=1;}自身_(MTOUCH_按钮_按钮_按钮_按钮_被按压(按钮_被按压(按钮(按钮1_按钮(按钮按钮1)按钮_被按压(按钮(按钮1)按钮{led2=1;}elseif(MTOUCH_Button_isPressed(Bu){led2=0;}_led2=0;}}}_}_}/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////R6_ISR();}if(INTCONbits.PEIE==1&&PIE3bits.TMR4IE == 1 && PIR3bits.TMR4IF == 1) { TMR4_ISR(); } if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1) { TMR0_ISR(); } if(INTCONbits.PEIE == 1 && PIE1bits.TMR2IE == 1 && PIR1bits.TMR2IF == 1) { TMR2_ISR(); } if(INTCONbits.PEIE == 1 && INTCONbits.INTE == 1 &&INTCONbits.INTF==1&&IOCBPbits.IOCBP0==1){ext_ISR();}.{//Unhandled Inter.}}
以上来自于百度翻译 以下为原文 main code: void main(void) { SYSTEM_Initialize(); WDTCON=0x25;///watch dog after 128 sec activate INTERRUPT_GlobalInterruptEnable();//global interrupt activate INTERRUPT_PeripheralInterruptEnable();//peripheral interrupts activate INTCONbits.INTE=1; IOCBPbits.IOCBP0 = 1; INTCONbits.INTF=0; TMR6=0; TMR4=0; TMR0=0; B=0;//door1 C=0;//door1 door1=0; door2=0; door3=0; door4=0; while (1) { MTOUCH_Service_Mainloop(); if(MTOUCH_Button_isPressed(Button0) ) { led1=1; } else if(MTOUCH_Button_isPressed(Button1) ) { led1=0; } else if(MTOUCH_Button_isPressed(Button2) ) { led2=1; } else if(MTOUCH_Button_isPressed(Button3) ) { led2=0; } } /////////////////////////////////interrupt manager code: void interrupt INTERRUPT_InterruptManager (void) { // interrupt handler if(INTCONbits.PEIE == 1 && PIE3bits.TMR6IE == 1 && PIR3bits.TMR6IF == 1) { TMR6_ISR(); } if(INTCONbits.PEIE == 1 && PIE3bits.TMR4IE == 1 && PIR3bits.TMR4IF == 1) { TMR4_ISR(); } if(INTCONbits.TMR0IE == 1 && INTCONbits.TMR0IF == 1) { TMR0_ISR(); } if(INTCONbits.PEIE == 1 && PIE1bits.TMR2IE == 1 && PIR1bits.TMR2IF == 1) { TMR2_ISR(); } if(INTCONbits.PEIE == 1 && INTCONbits.INTE == 1 && INTCONbits.INTF == 1 && IOCBPbits.IOCBP0 == 1) { ext_ISR(); } else { //Unhandled Interrupt } } |
|
|
|
对最初的问题没有把握,但是只需要对代码进行几条注释。在完成所有其他初始化之前,不要启用全局中断标志。启用它应该是最后一步。从中断服务中删除所有对PEIE的检查。这在以前已经讨论过,并且是MCC程序员读取数据表时犯的错误,即删除“INTCONbits.PEIE==1&&”的每个实例。为什么当你的代码不为它服务时,你设置了看门狗定时器?
以上来自于百度翻译 以下为原文 Not sure about your original question, but just a couple of comments on your code. Do not enable the global interrupt flag until you have finished ALL your other initialisation. Enabling it should be the LAST step. Remove all the checks of PEIE from the interrupt service. This ha ***een discussed before, and is an error some MCC programmer made reading the datasheet. i.e. remove every instance of "INTCONbits.PEIE == 1 &&". What is this test meant to be doing? if(INTCONbits.PEIE == 1 && INTCONbits.INTE == 1 && INTCONbits.INTF == 1 && IOCBPbits.IOCBP0 == 1) { ext_ISR(); } Why are you setting up the Watchdog timer, when your code is never servicing it? |
|
|
|
对不起的。这不是我的完整代码。在while循环看门狗正在重置,我忘了复制它。并且ExtIsIr()是用于IR远程的,我认为这里不必复制它。
以上来自于百度翻译 以下为原文 sorry. this is not my complete code. in while loop watch dog is resetting and I forgot to copy it. and ext_ISR() is for an IR remote and I think it is not necessary to copy it here. |
|
|
|
在一个中断服务功能中使用ADC吗?定时器2/4/6之一用于mTouch,它使用ADC进行mTouch扫描,如果在其他ISR中使用ADC,这会导致mTouch的数据损坏,而另一个任务使用ADC。K,并在主回路内进行实际ADC转换。
以上来自于百度翻译 以下为原文 Did you use the ADC in one of your interrupt service function? One of the timer2/4/6 is for mTouch, and it uses ADC for mTouch scan, if you use the ADC in other ISRs, this could cause data corruption for both mTouch and your other task uses ADC. If you do have this kind of situation, I would recommend to set a flag in the interrupt routine for the other ADC task, and do the actual ADC conversion inside main loop. |
|
|
|
嗨,如果这是你的代码…我建议你为按钮做一个切换-循环。如果你激活了外围中断,你也可能不需要全局中断。例如,对于ADC & GT,在睡眠模式下的ADCI中断,或者与其他的转换时序NESTEDRUTIN。
以上来自于百度翻译 以下为原文 Hi, if this is your code... I suggest you to make a switch - case loop for the buttons. If you activates the peripheral interrupt it is also possible that you not needs the Global interrupt. e.g. for the ADC -> ADC_interrupt in sleep mode, or with other in conversion timing nested routines. Gerald --- |
|
|
|
MMMM,切换/变量的情况?(除非他们解决宏……)
以上来自于百度翻译 以下为原文 Mmmm, switch/case with variables? (unless they resolve to macros...) |
|
|
|
只有小组成员才能发言,加入小组>>
5189 浏览 9 评论
2009 浏览 8 评论
1933 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3181 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2232 浏览 5 评论
743浏览 1评论
629浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
512浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
642浏览 0评论
538浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 09:29 , Processed in 1.950361 second(s), Total 97, Slave 83 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号