Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 54313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:12:02+00:00 2026-05-10T17:12:02+00:00

Do you have a simple debounce routine handy to deal with a single switch

  • 0

Do you have a simple debounce routine handy to deal with a single switch input?

This is a simple bare metal system without any OS.

I would like to avoid a looping construct with a specific count, as the processor speed might fluctuate.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T17:12:02+00:00Added an answer on May 10, 2026 at 5:12 pm

    I think you could learn a lot about this here: http://www.ganssle.com/debouncing.pdf

    Your best bet is always to do this in hardware if possible, but there are some thoughts on software in there as well.

    Simple example code from TFA:

    #define CHECK_MSEC 5 // Read hardware every 5 msec #define PRESS_MSEC 10 // Stable time before registering pressed #define RELEASE_MSEC 100 // Stable time before registering released // This function reads the key state from the hardware. extern bool_t RawKeyPressed(); // This holds the debounced state of the key. bool_t DebouncedKeyPress = false; // Service routine called every CHECK_MSEC to // debounce both edges void DebounceSwitch1(bool_t *Key_changed, bool_t *Key_pressed) {     static uint8_t Count = RELEASE_MSEC / CHECK_MSEC;     bool_t RawState;     *Key_changed = false;     *Key_pressed = DebouncedKeyPress;     RawState = RawKeyPressed();     if (RawState == DebouncedKeyPress) {         // Set the timer which allows a change from current state.         if (DebouncedKeyPress) Count = RELEASE_MSEC / CHECK_MSEC;         else Count = PRESS_MSEC / CHECK_MSEC;     } else {         // Key has changed - wait for new state to become stable.         if (--Count == 0) {             // Timer expired - accept the change.             DebouncedKeyPress = RawState;             *Key_changed=true;             *Key_pressed=DebouncedKeyPress;             // And reset the timer.             if (DebouncedKeyPress) Count = RELEASE_MSEC / CHECK_MSEC;             else Count = PRESS_MSEC / CHECK_MSEC;         }     } 

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple webform that will allow unauthenticated users to input their information,
I have simple front controller plugin which contains this code: http://pastebin.com/m155c59b0 When session expire
I have simple application with single AppDomain which is periodicaly launched on a server.
I have simple remoting API that has method similar to this: bool FillMyList(List<string> ListToFill)
I have simple web application based on JSP. Root of application looks like this:
I have simple regex \.*\ for me its says select everything between and ,
Ok, i have simple scenario: have two pages: login and welcome pages. im using
In general, is it a best practice to have simple POJO Java classes implement
I develop tools in Autodesk Maya. Many of the tools I build have simple
Should simple JavaBeans that have only simple getters and setters be unit tested?? What

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.