debouncing an annonmeter

I have made a small wind meter that tweets out the wind speed and direction, using an old cell phone and a X2. It has been going great.... until today. It has started tweeting higher than expected wind speeds and gusts which are lower than the average - which should be impossible according to the code below.

I think what is happening is the reed switch is bouncing, causing an overflow somewhere. It is strange, it has been running for weeks fine, then just today (which was quite a hot day) it started playing up - would the temperature have anything to do with it? The sun has gone down now and it is still all over the place.

Is there away to use a count command with a debounce? of a simple way to count pulses in a time frame with a debounce? Im thinking about a background timer, (im already using the settimer command)

below is the code part which is causing the issues.

Code:
windspeed_and_gust:  '1.29651 knots = one pulse in D.1 per second  

W1=0  			' set variables to zero
W2=0
W3=0
W4=0
W5=0
W6=0
W7=0
W8=0
W9=0
W20=0


for W1=1 to 38               'loop , 38 =  10 minute updates.

count D.1,30000, W6      'counts anomenter rotations in 15 seconds and puts them into w6 - clock speed is 2x.

if W6 > W3 then let W3 = W6   'Keeps the highest number of rotations in W3 - for gusts

endif

W4 = W4 + W6             'accumulates the values to get the average windspeed in the 10 minute block.

next W1

symbol average_windspeed = W7
symbol gust_windspeed = W8

average_windspeed = W4 / 439       'calculation for windspeed. Calibrated at 439.  
gust_windspeed = W3 * 10/156	' calculation for the gusts.  Calibrated at  x 10 / 156.
thanks for any insights anyone can give me!
 

PaulRB

Senior Member
Hi Mark,

Your theory does sound like the most plausible one. Options I can think of are: debounce the reed switch with an R/C circuit; debounce in software (replacing the count command with a short loop of code with short pauses, may need to increase the clock frequency); replace reed switch with optical sensor (perhaps reed switch starting to wear out).

PaulRB
 
Last edited:

AllyCat

Senior Member
gusts which are lower than the average - which should be impossible according to the code below.
Hi Mark,

Perhaps not particularly surprising because the average appears to be calculated from summing 38 samples but the divisor for the average is only about 28 times larger than for the gust (439 / 15.6). :confused:

Unless the reed it totally failing/broken then a simple R/C filter would be the simpest hardware fix. Otherwise a Hall sensor probably would be easier to incorporate than optics (or just replace the reed which should work for many millions/billions of operations).

Alternatively, a software fix should be fairly easy, a polling loop would probably test about once per ms so you might actually want a slight pause/delay and test for two consecutive "closures". You would need to find an alternative 15 second timer; for M2s there's time = 0 : do : (poll, debounce and count) : loop until time => 15 (or 30 with a doubled clock) but I'm not sure of the equivalent for X2s.

Cheers, Alan.
 

jedynakiewicz

Senior Member
With due respect but for the sake of clarity and accuracy, your device is an ANEMOMETER. Now that I have used the correct spelling for the first time in this thread, if anyone in the future should search on Anemometer they will find this thread.
 
Perhaps not particularly surprising because the average appears to be calculated from summing 38 samples but the divisor for the average is only about 28 times larger than for the gust (439 / 15.6).
thanks so much AllyCat. Not sure how i missed that - think it was a typo when i was multiplying by 10, and dividing by 15.6, when it should of been multiple by 10 and then divide by 115.6. That should sort that out.

Strange that it only showed up after two weeks of testing, theory is that for the last two weeks it has been blowing easterly, which is a quite gusty. The gusts would have been routinely 25% higher than the average, therefore would have always come out on top. Yesterday the wind swung to a sea breeze westerly which was very smooth, and hence the gusts always being about the same as average, but because of the calculation were 25% lower!

just got to figure out the debounce not and it will be sorted! what size capacitor would i need? I am using a 22uf across the reed at the moment, and a 10k resistor to ground.

and thanks jedynakiewicz, ANEMOMETER, must try and commit that one to memory.
 

rossko57

Senior Member
22uF is a bit big if you are trying to get a nice square pulse stream. I wonder if it is big enough to cause arcing and erode the reed switch contacts?
You're more likely to get long term consistent results using an opto device, now you've proven the principles.
 

AllyCat

Senior Member
Hi Mark,

IMHO 22uF is much too large, particularly directly across the reed. The current pulse when the reed closes might be damaging the reed contact surfaces. AFAIK, a reed's contact bounce shouldn't be more than a ms or two so a time constant of about 2 - 5 ms should be OK, say 100nF + 22k ohms (pull-up or pull-down as appropriate) and preferably about 1k in series with the capacitor. Certainly not more than 10k + 1uF which might start to limit the maximum detected speed.

Cheers, Alan.
 
Top