Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

Debouce Button Interrupt Routine

Posted by gcgasson on September 8, 2014

Hi,

I am new with FREERTOS and require some assistance please.

I have a 5 button system with a 2 character LCD display. I am updating the display queue in the ISR as the button are pressed. This works great but I am getting a lot of bouncings on the switches and I am looking for away in which I can debounce the buttons in the FREERTOS.

I have decreased the size of the queue to 1 and this has helped but not 100%

Is there away in doing this?

For example what if I disable the port interrupt for 10ms and then re-enable them after the interrupt occurred?

What is the correct way of doing this in the FREERTOS?

Best Regards,

Gary


Debouce Button Interrupt Routine

Posted by bowerymarc on September 8, 2014

I'd suggest to poll rather than use interrupts if those buttons are for human interaction only. Create a thread, poll them and use a delay (wait). Debounce by looking for two consecutive readings of the same value, and adjust the delay until they are bounce free (best is to look with a 'scope to the switch lines, but you could just try some values like 20, 50mS etc).

Unless your product is very dependent on precise timing of the buttons this will probably give you the smallest code size.

On Sep 8, 2014, at 5:25 AM, "Gary" gcgasson@users.sf.net wrote:

Hi,

I am new with FREERTOS and require some assistance please.

I have a 5 button system with a 2 character LCD display. I am updating the display queue in the ISR as the button are pressed. This works great but I am getting a lot of bouncings on the switches and I am looking for away in which I can debounce the buttons in the FREERTOS.

I have decreased the size of the queue to 1 and this has helped but not 100%

Is there away in doing this?

For example what if I disable the port interrupt for 10ms and then re-enable them after the interrupt occurred?

What is the correct way of doing this in the FREERTOS?

Best Regards,

Gary

Debouce Button Interrupt Routine

Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/freertos/discussion/382005/

To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/

Attachments

alternate (2116 bytes)

Debouce Button Interrupt Routine

Posted by jdurand on September 8, 2014

On 09/08/2014 07:18 AM, Marc Lindahl wrote: > > I'd suggest to poll rather than use interrupts if those buttons are > for human interaction only. > Create a thread, poll them and use a delay (wait). Debounce by looking > for two consecutive readings of the same value, and adjust the delay > until they are bounce free (best is to look with a 'scope to the > switch lines, but you could just try some values like 20, 50mS etc). > > Unless your product is very dependent on precise timing of the buttons > this will probably give you the smallest code size. > >

Even though this isn't a general programming list, I'll give a freebie

define mask (0b111) // make this any length you want for your debounce

uint i;

inside tick interrupt add:

i <<= 1; if(Button_Down) { i |= 1; if(!(~i & mask)) { set semaphore } }

Jerry Durand, Durand Interstellar, Inc. www.interstellar.com tel: +1 408 356-3886, USA toll free: 1 866 356-3886 Skype: jerrydurand


Debouce Button Interrupt Routine

Posted by heinbali01 on September 9, 2014

And if you like, here's a routine if you do not want to use an interrupt: you can call vCheckKey() from a regular task as often as you like.

Both key-press as key-release events are being filtered for dender, not for noise.

~~~~~

define DENDER_TIME 50 // Use 50 ticks anti dender time

TimeOutt xTimeOut; BaseTypet xWaitDender = pdFALSE; BaseTypet xLastKey = 0; BaseTypet xReportedKey = 0; TickType_t xDenderTime;

BaseType_t xReadKey( void ) // Reports the current key status { // Read some i/o pin return readPort(PORTA, 4); }

void vHandleKey( BaseType_t xKeyPressed ) // Handle the key status { printf ("Pressed %lun", xKeyPressed); }

void vCheckKey( void ) { BaseType_t xKeyPressed = xReadKey( );

if( xWaitDender == pdFALSE && xReportedKey != xKeyPressed )
{
    // We were not waiting for dender,
    // so report the new key status
    xReportedKey = xKeyPressed;
    vHandleKey( xKeyPressed );
}
// Has the key value changed?
if( xLastKey != xKeyPressed )
{
    xLastKey = xKeyPressed;
    xDenderTime = DENDER_TIME;
    vTaskSetTimeOutState( &xTimeOut );
    xWaitDender = pdTRUE;
}
// Were we waiting for the dender?
else if( xWaitDender == pdTRUE )
{
    // See if the timer has expired
    if( xTaskCheckForTimeOut( &xTimeOut, &xDenderTime ) )
    {
        xWaitDender = pdFALSE;
    }
}

} ~~~~~

Regards, Hein


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists