Input from a reed switch?
rapscaLLion
Posts: 75
Hi,
I need to collect input from a rotating source which has a reed switch built into it. The reed switch switches on/off twice per revolution.
I have connected the reed switch to the 3v source on one end and input 2 on the other end. I have been using the "count" function from
the BS2 library, but I'm not entirely sure the results are accurate and also not entirely sure that this is the best way to do it. Theoretically
the fastest the rotation could be is about 30 rotations per second, or 1800 rpm. The slowest is 0. I imagine the average will be about 300-600.
Any ideas? I need to sample this twice per second.
I need to collect input from a rotating source which has a reed switch built into it. The reed switch switches on/off twice per revolution.
I have connected the reed switch to the 3v source on one end and input 2 on the other end. I have been using the "count" function from
the BS2 library, but I'm not entirely sure the results are accurate and also not entirely sure that this is the best way to do it. Theoretically
the fastest the rotation could be is about 30 rotations per second, or 1800 rpm. The slowest is 0. I imagine the average will be about 300-600.
Any ideas? I need to sample this twice per second.
Comments
You could poll for the input in Spin or assembly but the easiest way would be to use the cog counters and just read their current value whenever needed.
I'm writing this from memory please consult description of CTRA in manual and also the counter app note if it doesn't work.
One problem may be bounce, the counter will detect any positive edge whats so ever at a very high clock rate.
Graham
Take care about the rebound, or bounce. you have to debounce the mechanical contact. You need to do that with a small delay after each state changing.
dro
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
in medio virtus