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 Reply Children
  • Hmm, I can see a few problems with the above code.
    First, the debounce algorithm. If I understand correctly, you are going to take 3 samples of the input with 10-microsecond intervals, then make a majority decision. Normally, when you deal with mechanical contacts, you would want 10 milliseconds instead of 10 microseconds. And 3 samples doesn't sound like enough. More importantly, these two parameters (number of samples and time interval) must be chosen based on the typical behaviour of your system. That is, you should look at scope traces first.
    Second, the code looks sloppy. Variable naming is inconsistent. Types like 'uint16_t' and 'char' are intermixed. The array SHIFT_RESULT[] is not initialized properly. Indentation is extremely wobbly. And so on...