catching switch closure, help needed
Franklin
Posts: 4,747
I am building a weather station using the propeller and need some input. The rain gauge and anemometer both have magnets that close a reed switch as they pass and I need a way to count these closures to update data. The rain gauge switches from once a second to once every two months and just needs to be accumulated for a 24 hour period. The anemometer can pulse up to 50 time a second and needs to be accumulated for 2.5 seconds. I've done this with ctra and hardware but was wondering if this could be done in software. Looking at the objects in the OBEX they seem to be more for querying a pin to see if it is pressed but with the other things the prop will be doing I'm not sure I would catch all the pulses that way. Does anyone have any insite on this problem?
Thanks,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Thanks,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Comments
Yes, you could do this all with software and not use the counters, but you'd need a cog anyway to handle it and that already comes with two counters.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Where P0 is your input and WindRaw is your [noparse][[/noparse]long] variable.
The software debouncing works on the theory that your input (bouncing) will last no longer than 1/4 of the 50Hz sample window.· When the input goes high the pulse count is updated, a short delay is inserted, and then the code checks to see if you've reached the end of the 2.5s accumulation window.· If that happens, the pulse count is written to your variable and the process starts over.
This is just an idea whipped up over coffee -- if you try it and it works (or doesn't), please let me know.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
I'll hook up the debounce and see what I get then.
Thanks for the help, any direction is better than random...
Very simple test program attached, there is no substance so don't bother running it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Note that I changed the delay-from-detected-high timing inside the anemometer object to 10ms (one half of your 50Hz max input).· I suggest you connect a 'scope to the circuit just to see what the actual duty-cycle from that switch is; you may need to adjust the code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA