View Single Post
  #4   Spotlight this post!  
Unread 15-02-2015, 12:16
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Counting up and down with a switch

Quote:
Originally Posted by shindigo View Post
Hi We are using counters with switches on digital inputs to check for rapid changes in the switch. We would like the counter to count up when the switch goes from unpressed to pressed and count down (to negative numbers) when it goes
from pressed to unpressed. So far the counter appears to only count up on either state change.

Any thoughts about how to get it to count down when the switch is released?

mp
You need to construct the counter in Up/Down mode.

Code:
myCounter.setUpDownCounterMode();
Then set the up source to the channel with a rising edge and the down source to the channel with a falling edge.

Code:
myCounter.setUpSource(myDigitalIn);
myCounter.setUpSourceEdge(true, false);
myCounter.setDownSource(myDigitalIn);
myCounter.setDownSourceEdge(false, true);
Reply With Quote