• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoEliminate shake filter method for pcDuino/Arduino ...
Previous Next

Eliminate shake filter method for pcDuino/Arduino (9)

Posted by: admin , April 22, 2014

A. method: setting a filter counter which can compare the sample value with the current valid values: If the sample value = current valid value, the counter is cleared to zero if the sampled value <> current judging effectively counter is >= limit n (overflow) when the counter overflows, then this value replaces the value currently in effect, and clear counter.

B. advantages: better for slow changes of measured parameters of the filter effect can be avoided near the threshold controller on/off beat or numeric on the monitor repeatedly.

C. disadvantages: for rapidly changing parameters because it was difficult to counter that sampling for the value of the overflow happened to be jamming, the interference will be deemed valid values into the system.

D. test code

int Filter_Value;
int Value;

void setup () {
Serial.begin (9600); / / initialize the serial communication
randomSeed (analogRead (0)); / / random seed
Value = 300;
}

void loop () {
Filter_Value = Filter (); / / get the filter output value
Serial.println (Filter_Value); / / serial output
delay (50);
}

/ / Used to randomly generate a current value of around 300
int Get_AD () {
return random (295, 305);
}

/ / Debounce filtering
# define FILTER_N 12
int i = 0;
int Filter () {
int new_value;
new_value = Get_AD ();
if (Value! = new_value) {
i + +;
if (i> FILTER_N) {
i = 0;
Value = new_value;
}
}
else
i = 0;
return Value;
}

Tags: pcDuino

Share!
Tweet

admin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors