chandu.kurapati
Full Member level 3
- Joined
- Oct 31, 2013
- Messages
- 186
- Helped
- 5
- Reputation
- 10
- Reaction score
- 5
- Trophy points
- 1,298
- Location
- Bengaluru, India
- Activity points
- 2,778
Hi,
Thanks for your patience, it's little bit long...
Here my intention to check stability of the digital inputs, if it they are depressed for 1000 counts.
if any one of the switch is released, time stamp and stability reset to 0.
Both are the different functionality and independent to each other, but to monitor stability logic is same.
Here i need to replace single logic for both digital inputs, thing is any input can depress and release at any time, should not impact on another input.
Can any one please guide me to replace single logic for the both inputs..
Code:
/* Global values */
u32 Switch1Stable = 0;
u32 Switch2Stable = 0;
/* Function to check for the switch stability*/
/* Switch1 & Switch2 values passed to this function as per switch status */
1---->depressed
0----->released
/* This function is called for every 1 ms */
static void voSwitchStability(bool Switch1, bool Switch2)
{
static u32 Switch1TimeStamp;
static u32 Switch2TimeStamp;
u32 Switch1Time = 1000;
u32 Switch2Time = 1000;
if(Switch1^Switch1Stable) /* if both are 0 or 1 no need to perform logic */
{
/* if switch 1 is pressed */
if(1 == Switch1)
{
if(( Switch1TimeStamp) >= Switch1Time)
{
/* switch1 is stable */
Switch1Stable = 1;
}
else if((Switch1TimeStamp) < Switch1Time)
{
/* Increment the switch1 time stamp */
Switch1TimeStamp++;
}
else
{
/* No Action */
}
}
else
{
/* Switch 1 reset */
Switch1Stable = 0;
}
}
else
{
/* reset time stamp */
Switch1TimeStamp = 0;
}
if(Switch2^Switch2Stable) /* if both are 0 or 1 no need to perform logic */
{
/* if switch 2 is pressed */
if(1 == Switch2)
{
if((Switch2TimeStamp) >= Switch2Time)
{
/* switch2 is stable */
Switch2Stable = 1;
}
else if((Switch2TimeStamp) < Switch2Time)
{
/* Increment switch2 time stamp*/
Switch2TimeStamp++;
}
else
{
/* No Action */
}
}
else
{ /* switch2 is released */
Switch2Stable = 0;
}
}
else
{
/* reset time stamp*/
Switch2TimeStamp = 0;
}
}
Thanks for your patience, it's little bit long...
Here my intention to check stability of the digital inputs, if it they are depressed for 1000 counts.
if any one of the switch is released, time stamp and stability reset to 0.
Both are the different functionality and independent to each other, but to monitor stability logic is same.
Here i need to replace single logic for both digital inputs, thing is any input can depress and release at any time, should not impact on another input.
Can any one please guide me to replace single logic for the both inputs..
Last edited: