You have two options. One is to use the the counter on your DAQ board to detect signal change. The other option is to implement a software counter. If this is not a fast changing signal, then you can do everything in your while loop. Set up your while loop to run at a certain rate, which should be faster than your digital signal. Read the digital input on every iteration and set up a shift register in the while loop. This will make sure that the application stores the last state of the digital input for comparison. Set up another shift register for counting. Then, each time your read the digital input, compare the new state with the previous state. Each time, you detect a change on the digital input, increment the count in the second shift register. Hope this helps.