04-14-2008 03:45 PM
04-15-2008 12:11 PM
Hello Alex D,
There isn't a "good" solution for this unless the edges you're counting are very slow. Basically what you would need to do is use a digital input task and monitor your digital signal and then save a reference to the counter value when it changes values and manually subtract or add the change to your "real" counter value (By “real” counter value I mean a software variable that you use to hold the current value after you manually add or subtract counts from the hardware counter to account for counting in two directions—the hardware counter will always be counting up) I.e. If you put a DAQmx read for both the digital line and counter in a loop you would read both, take the difference between the current counter value and subtract it from the value from the previous iteration and then add or subtract that from a numeric value that would represent your "real" counter value.
Pseudo code:
1. Initialize "real" counter value to 0.
2. Read counter and digital line.
3. If digital line is high add the counter value change to the "real" counter value; if the digital line is low then subtract.
4. Repeat starting at step 2—make sure you add the change in the counter value and not the actual counter value (subtract from previous iteration).
This will have error due to the software timing--if the digital line changes in between reads then all of the counts between the two reads will be counted in one direction. If you're reading signals slow enough this may be a satisfactory solution, otherwise, as you've suggested, you will likely need to get a different DAQ card.
I hope this helps. Have a great day!
Cheers,