Il 23/09/2013 23:42, pozz ha scritto:
Ok, this is the full story. I want to interface a microswitch-based sensor
When the shutter moves vertically, the thin rope attached to it creates the circular movement of the cam inside the sensor. I have seen sensors with 6 cams per rotation, but there are so many low- and high-quality sensors on the market that I expect some differences among them.
The final goal of the project is to detect movement of the shutter caused by humans (i.e., not caused by wind). This can be achieved if I'm able to count the debounced pulses of the microswitch. For example, I can raise the alarm when I see 10 pulses in a second (low sensitivity) or just 2 pulses in 5 seconds (high sensitivity). Depending on the sensor used, I can change the sensitivity of the alarm detector by changing the number of the pulses and the period of counting.
So I connected the two wires at the output of the sensor (connected internally to the microswitch) at a microcontroller-based circuit: one pole is connected to 0V and the other to a pulled-up input of the microcontroller. Normally the switch is closed so the level is 0V when the shutter isn't moving (it's impossible to stop the shutter when the microswitch is open).
I made some tests pulling/releasing manually the rope of the sensor and the pulses frequency, width and bouncing changes dramatically. Here two pictures with a high rotation speed:
As I wrote in my previous email, the best solution I found that minimize the not-detected and false pulses is to sample the switch line at 1ms rate and count the pulse when I see the 0-1 sequence. After this sequence, I wait for 1-0-0 sequence to consider the pulse finished and start waiting for the next pulse (sequence 0-1).
Of course there's no problem with low rotation speed: the pulse is sufficiently long to detect it correctly. The problems come with short pulses that have a very small stable interval (where the signal is stable high, so the switch is open without bouncing).
I know I should sample at a higher frequency (maybe 100us) to increase reliability, but I prefer to avoid stressing the microcontroller too much, because it has other tasks (consider I have 8 similar inputs) to run.
I know the pulses are very noisy and an optical/magnetic sensor could solve many problems, but I can't change the sensor. Moreover for this application I could tolerate a few errors in the counting process.