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

Debounce Logic

I have done software debounce logic with 2/3 voter logic
and kindly verify the coding i don't no whether it is correct or not. Please help me

Coding:

void inputRoutine()
{
 uint16_t temp;
 InputP1_Temp=P1&0x00;
 for(Index1=0;Index1<MAXINPUTS;Index1++)
 {
    temp=debounce(Index1);
        if(temp==1)
        {
        Input_TableP1[Index1]=1;
        }
        else if(temp==0)
        {
                 Input_TableP1[Index1]=0;
        }
  }
}

/*****************
-- Debounce Port P1 --
*****************/

bit debounce(uint16_t IN_INDEX)
{
 uint16_t INDEX2,ONE=0,ZERO=0;
 char  TEMP,SHIFT_RESULT[3]=0x00;
  for(INDEX2=0;INDEX2<3;INDEX2++)
   {
                 TEMP= P1;
         SHIFT_RESULT[INDEX2]=(TEMP>>IN_INDEX)& 0x01;
                 delay_10micro_sec();
   }

   /* Comparision of 3 values retreived from same pin*/

   for(INDEX2=0;INDEX2<3;INDEX2++)
   {
        if(SHIFT_RESULT[INDEX2]==1)
                   ONE++;
        else if(SHIFT_RESULT[INDEX2]==0)
                   ZERO++;
   }
   return (ONE>ZERO);
}

With Thanks,
G.Karthik Ragunath

Parents
  • what about this debounce logic for 3 inputs.

    #include<stdio.h>
    #include <REGX52.H>
    
    /* This code is for button debouncing.Here 3 buttons are considered and each button have individual buffer
       and each buffer is compared for 2/3 logic and stored in input table.
    */
    
    void inputRoutine();
    void debounceLogic();
    
    unsigned int compareBuffer(unsigned int[]);
    unsigned int inputBuffer1[3],inputBuffer2[3],inputBuffer3[3],debounceStatus;
    unsigned int bufSize,bufIndex,shiftIndex,inputTable[3],inputIndex;
    
    void main()
    {
    bufSize=3;
    bufIndex=0;
    shiftIndex=0;
    count=0;
    
     while(1)
     {
      inputRoutine();
     }
    
    }
    
    void inputRoutine()
    {
     debounceLogic();
     if(bufSize==bufIndex)
     {
    
       bufIndex=0;
    
     }
     else
     {
      bufIndex++;
     }
    }
    
    
    /*Here Port P0 is used and Pins P0.0 ,P0.1 and P0.2 is used*/
    
    /*Each Pinvalues are stored in inputBuffer. And compared for 2/3 logic*/
    
    void debounceLogic()
    {
     inputBuffer1[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer1);
     shiftIndex++;
     inputBuffer2[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer2);
     shiftIndex++;
     inputBuffer3[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer3);
     shiftIndex++;
     shiftIndex=0;
     inputIndex=0;
    }
    
    unsigned int compareBuffer(unsigned int tempBuffer[])
    {
     unsigned int one=0,zero=0,i;
    
    
      for(i=0;i<3;i++)
      {
       if(tempBuffer[i]==1)
       {
        one++;
       }
       else
       {
        zero++;
       }
    
      }
      if(one>zero)
      {
        return(1);
      }
      else
      {
       return(0);
      }
    
    
    }
    
    

    thanks,

Reply
  • what about this debounce logic for 3 inputs.

    #include<stdio.h>
    #include <REGX52.H>
    
    /* This code is for button debouncing.Here 3 buttons are considered and each button have individual buffer
       and each buffer is compared for 2/3 logic and stored in input table.
    */
    
    void inputRoutine();
    void debounceLogic();
    
    unsigned int compareBuffer(unsigned int[]);
    unsigned int inputBuffer1[3],inputBuffer2[3],inputBuffer3[3],debounceStatus;
    unsigned int bufSize,bufIndex,shiftIndex,inputTable[3],inputIndex;
    
    void main()
    {
    bufSize=3;
    bufIndex=0;
    shiftIndex=0;
    count=0;
    
     while(1)
     {
      inputRoutine();
     }
    
    }
    
    void inputRoutine()
    {
     debounceLogic();
     if(bufSize==bufIndex)
     {
    
       bufIndex=0;
    
     }
     else
     {
      bufIndex++;
     }
    }
    
    
    /*Here Port P0 is used and Pins P0.0 ,P0.1 and P0.2 is used*/
    
    /*Each Pinvalues are stored in inputBuffer. And compared for 2/3 logic*/
    
    void debounceLogic()
    {
     inputBuffer1[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer1);
     shiftIndex++;
     inputBuffer2[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer2);
     shiftIndex++;
     inputBuffer3[bufIndex]=(P0>>shiftIndex)&0x01;
     inputTable[shiftIndex]=compareBuffer(inputBuffer3);
     shiftIndex++;
     shiftIndex=0;
     inputIndex=0;
    }
    
    unsigned int compareBuffer(unsigned int tempBuffer[])
    {
     unsigned int one=0,zero=0,i;
    
    
      for(i=0;i<3;i++)
      {
       if(tempBuffer[i]==1)
       {
        one++;
       }
       else
       {
        zero++;
       }
    
      }
      if(one>zero)
      {
        return(1);
      }
      else
      {
       return(0);
      }
    
    
    }
    
    

    thanks,

Children
  • Debounce? I see no such thing (unless the switch has a bounce time in nano or microseconds.

    the surefire way to debounce is

    timer reloading at bounce time set flag47

    in the main

    if flag47 read the switches to newswitches

    compare newswitches to oldswitches
    if identical
    --compare oldswitch to sentswitch
    --if different
    ----set newswitch flag (to be reset in switch processor)
    -------- switch processor reads sentswitch
    ----set sentswitch to oldswitch
    if different
    set oldswitch to newswitch

    Erik