This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

New debounce logic:

whether the following debouncing logic will work well:
the total cycle for code is 50ms and each function is executed only once during the cycle.

void main()
{
 signed int deb_Counter=0;
 while(1)
 {
   input();
   process();
   output();
 }
}
int debounce()
{

  if(key_pressed)
  {
     deb_Counter++;
  }
  else
  {
     deb_Counter--;
  }
  if(deb_Counter>10)
  {
   deb_Counter=0;
   return(1);
  }
  else
  {
  deb_Counter=0;
  return(0);
  }
}


this code is reffered from web
with thanks,
karthik

Parents
  • this debounce function will be called in input function sorry for not mentioning it.

    void main()
    {
     signed int deb_Counter=0;
     while(1)
     {
       input();
       process();
       output();
     }
    }
    void input()
    {
     int status=debounce();
    }
    int debounce()
    {
    
      if(key_pressed)
      {
         deb_Counter++;
      }
      else
      {
         deb_Counter--;
      }
      if(deb_Counter>10)
      {
       deb_Counter=0;
       return(1);
      }
      else
      {
      deb_Counter=0;
      return(0);
      }
    }
    
    


    with thanks,
    karthik

Reply
  • this debounce function will be called in input function sorry for not mentioning it.

    void main()
    {
     signed int deb_Counter=0;
     while(1)
     {
       input();
       process();
       output();
     }
    }
    void input()
    {
     int status=debounce();
    }
    int debounce()
    {
    
      if(key_pressed)
      {
         deb_Counter++;
      }
      else
      {
         deb_Counter--;
      }
      if(deb_Counter>10)
      {
       deb_Counter=0;
       return(1);
      }
      else
      {
      deb_Counter=0;
      return(0);
      }
    }
    
    


    with thanks,
    karthik

Children