FieldPoint Family

cancel
Showing results for 
Search instead for 
Did you mean: 

Need help with voltage counter

I have a system that passes current through a resistor when ever a button is pushed.  The voltage across the resistor (about 100mV) is read by a cFP-AI-102 Analog Input voltage module.  I'm trying to figure out a way to count the number of times this happens.  In other words, I need to count how many times the button is pushed.

I've tried using a While Loop, but since it counts with every iteration I end up with way too many counts for each button push.  Is there a way I only count once?

Thanks,
Eric
0 Kudos
Message 1 of 4
(6,872 Views)
Hi!
   If I understand, you want to measure how many times button is pushed, i.e. how many transition 0 -> 100 mV, right?  I'd do that with a shift register and a while loop.... just save the past state of the analog in, if the comparison between the past state and curtrent state is > 50 mV, you have a push.... (actually it depends on how terminals are connected...)

 Post your code, perhaps I can understand better the starting point. 

   remember: this way you're going to measure too many transitions, because usually, when a button is pressed or released you have some oscillating voltage (I don't know if you ever tried to handle a switch button with a microcontroller, there you can see this).  But maybe, AI module sample at "low frequencies" respect to this phenomenon.

graziano


0 Kudos
Message 2 of 4
(6,867 Views)
Thanks Graziano!  That was just the help I needed.  I did just what you said, and it works like a dream.  It only counts once, so I guess the button isn't bouncing too badly.

Take care,
Eric
0 Kudos
Message 3 of 4
(6,857 Views)
Hi!
   Actually, almost each electonic-mechanical switch bounces when swithed, what I suppose is that it bounches too fast to be seen by the AI module, which should have a quite low sampling rate.... consider this if your is a prototype for a system to be implemented in different technologies! 

   Anyway, I'm glad it works now! Smiley Happy

   Have a nice week-end!

graziano


Message Edited by Graziano on 01-18-2008 03:30 AM
0 Kudos
Message 4 of 4
(6,848 Views)