الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

سؤال عن كيفية عمل debounce لكل اطراف المنفذ

مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

اريد عمل low pass filter لكل اطراف المنفذ (PORTx) مرة واحدة في مايكرو AVR ATMEGA16 لتلافي مشكلة الــ bouncing

في الحقيقة يوجد امثلة كثيرة في النت هذه بعضهاولكن كلها تتعامل مع رجل واحدة أو اثنين على الأكثر

هل يوجد مثال أو هل تعامل أحدكم مع حالة فلترة لجميع اطراف البورت بصورة غير معقدة بحيث يمكن تغيير الثابت الزمني لهذا الفلتر

وجزاكم الله خيراً

#2

rc circuit بسيطة

لكن سؤال لمذا تريد عمل debounce لها وهى خرج كمبيوتر من الأساس انا لا اجد مشكلة فى ان يتعامل معها ميكرو ATMEGA16

ارجو منك ان تعظينى نبذة عن التطبيق

موقع البرنامج

مبارك لشعب تونس photo-thumb-42837.png

#3

السلام عليكم ورحمة الله

جزاك الله خيراً علي الرد وتحريك الموضوع (:

المشروع هو عبارة عن digital input module بسيط لمراقبة حالة مفاتيح (متصل مع PC بـ serial port)

والفكرة مستوحاة من هذا الموديول (شركة ABB) الذي يستخدم digital filter ويمكن تغيير اعدادات الفلتر حسب الحاجة:

The binary input board 23BE40 can execute the following processing functions for the different types of signals:
• Digital filtering to suppress contact bounce
• Suppression of technologically caused chattering signals
• Intermediate position suppression and monitoring for double indications
• Consistency check for all binary input channels allocated to digital measured values.....

اظن ان استخدام الـ digital filter سيكون استغلال جيد لموارد المايكرو

#4

اعذنى اخى مرة اخرى فلم افهم الكثير

هل لك ان تقوم برسم block diagram يوضح المشروع لانك لا تحتاج لعمل debounce للمنافذ لنقل اشارات للميكرو كنترولر

بالإضافة كيف ستتحكم فى اعدادات الفلتر

موقع البرنامج

مبارك لشعب تونس photo-thumb-42837.png

#5

السلام عليكم

الموضوع (حتي الآن ) بسيط جدا" عبارة عن مفاتيح موصلة بالمايكرو ويقوم المايكرو بالتحقق من حالة هذه المفاتيح وفق شروط معينة واذا تحققت هذه الشروط يقوم بارسال الحالة الجديدة للحاسب

من ضمن الشروط هو التخلص من bounce بواسطة digital filter كما في الصورة التالية:

488402781.jpg

نعم يمكن استخدام دائرة RC circuit كما ذكرت اخي في مشاركة سابقة ولكن سيكون الـ cutt-off ثابت

لاحظ في الصورة انه يمكن عمل هذه الاعدادات لكل مدخل علي حدة وبصورة مستقلة عن بقية المداخل.

في الروابط بالمشاركة السابقة اظن انه بالامكان الاستفادة والتعديل في هذا الكود

/****************************************************************************
 Title:    Debouncing 8 Keys
 Author:   Peter Fleury <pfleury@gmx.ch> http://jump.to/fleury,
           based on algorithm of Peter Dannegger <danni@specs.de>
 Date:     December 2003
 Software: AVR-GCC 3.3 
 Hardware: AT90S8515 at 4 Mhz, STK200 compatible starter kit

 Description:
 Demonstrates debouncing 8 keys. The state of the eight keys is sampled
 four times using a timer interrupt. If a key is pressed longer than
 four seconds, the corresponding bit in the key_press global variable is set.
 The main loop checks if a bit is set in this global variable and resets 
 the bit.

 Pressing the key connected to PIND2 increments a counter, while pressing 
 the key connected to PIND3 decrements the counter. 
 The value of this counter is displayed using LEDs on PORTB.

*****************************************************************************/

#include <inttypes.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>


#ifndef CTC1
#define CTC1 WGM12              // for compatibility with ATmega
#endif


#define XTAL		4000000L    // Crystal frequency in Hz
#define DEBOUNCE	200L		// debounce clock 200Hz = 5msec


/*
 * Module global variable, informs the main programm when a key is pressed.
 * This variable must be declared 'volatile, since it is accessed from
 * both interrupt und main loop.
 */
static volatile uint8_t key_press;	   


ISR (SIG_OUTPUT_COMPARE1A)
{
  static uint8_t key_state;		// debounced and inverted key state:
  static uint8_t ct0, ct1;      // holds two bit counter for each key
  uint8_t i;


  /*
   * read current state of keys (active-low),
   * clear corresponding bit in i when key has changed
   */
  i = key_state ^ ~PIND;   // key changed ?

  /* 
   * ct0 and ct1 form a two bit counter for each key,  
   * where ct0 holds LSB and ct1 holds MSB
   * After a key is pressed longer than four times the
   * sampling period, the corresponding bit in key_state is set
   */
  ct0 = ~( ct0 & i );			// reset or count ct0
  ct1 = (ct0 ^ ct1) & i;	    // reset or count ct1  
  i &= ct0 & ct1;			    // count until roll over ?
  key_state ^= i;			    // then toggle debounced state

  /*
   * To notify main program of pressed key, the correspondig bit
   * in global variable key_press is set.
   * The main loop needs to clear this bit
   */
  key_press |= key_state & i;	// 0->1: key press detect

}


int main( void )
{
  uint8_t count = 0;


  TCCR1B = _BV(CTC1) + _BV(CS10);  // clear timer on compare match, no prescaler
  OCR1A  =  XTAL/DEBOUNCE;		   // timer = 5 msec
  TIMSK  = _BV(OCIE1A);            // enable Output Compare 1 overflow interrupt

  DDRB  = 0x00;                    // use all pins on PortD for input
  PORTD = 0xff;                    // with pull-up enabled

  DDRB  = 0xff;                    // use all pins on PortB for output 
  PORTB = 0xff;                    // turn all LED off

  sei();                           // enable interrupt

  for(;;)
  {
    if (key_press & _BV(2) )
    {
        // key 2 pressed, increment counter
        count++;
        PORTB = ~count;

        key_press = 0;
    }
    else if ( key_press & _BV(3) )  
    {
        // key 3 pressed, decrement counter
        count--;
        PORTB = ~count;

        key_press = 0;
    }
  }

}
#6

اذا بكل بساطة ال debounce ليس على أطراف ال TxD و RxD للمنفذ لكن على المفاتيح الميكانيكية وهذا هو الكلام الصحيح

المنفذ فقط ينقل اعدادات هذا الفلتر

اذا كان هذا ما فهمته

يكون ال debouncing عبارة عن delay معين ( تأخذه من الحاسب كما ذكرت انت )

يمكنك ان تراقب المنفذ دوريا واذا حدث أى تغير عليه تقوم بتحميل احدى ال timers فى المتحكم بقيمة ال delay وعندما يقوم بعمل overflow سينفذ routine ليقرأ الحالة النهائية للمفتاح وهى القيمة بعد الإستقرار

موقع البرنامج

مبارك لشعب تونس photo-thumb-42837.png

#7
حريف برمجة كتب:

يكون ال debouncing عبارة عن delay معين ( تأخذه من الحاسب كما ذكرت انت )

يمكنك ان تراقب المنفذ دوريا واذا حدث أى تغير عليه تقوم بتحميل احدى ال timers فى المتحكم بقيمة ال delay وعندما يقوم بعمل overflow سينفذ routine ليقرأ الحالة النهائية للمفتاح وهى القيمة بعد الإستقرار

نعم هذا هو المقصود بالضبط

مبدئياً أنا استخدمت هذه الطريقة بقيمة delay واحدة تطبق علي جميع اطراف البورت (وليس لكل مدخل علي حدة كما في المنتج الجاهز)

ولنا عودة بإذن الله

وجزاكم الله خيراً علي اهتمامكم و جعله الله في ميزان حسناتكم

مواضيع مشابهة