mark.duyvesteyn
Member
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.
thanks for any insights anyone can give me!
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.