LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I create a software up/down/resettable counter?

I would like to have a counter that initializes at zero and counts up to 1 in increments of .01 and when 1 is reached, the counter would then decrement back down to 0 in .01 increments. The counter would run continuously for comparison to a analog input. The output from the compare would be sent to a digital output producing a simple PWM signal. The increment/decrement rate needs to be 50 times per second. That is increment or decrement by .01 every 1/50th of a second.
Thanks for any replies.
Chris
0 Kudos
Message 1 of 4
(3,253 Views)
Looks like a rare time for Sequence structures in a continuous while loop (count up, count down, & repeat. 1/50 of a second is 20 msec, so I added that time delay for each count - its accuracy will be dependent on your computer clock, but should be within a usec. See if the attached helps, good luck with it, Doug
0 Kudos
Message 2 of 4
(3,253 Views)
Thanks Doug. I have not yet figured out how to affect the count down speed or the increment. I found another solution using a for loop in a continuous while loop. Inside the for loop is an array holding the numbers 0-100 and 99-1. cycling through does what I need also. See the attached VI.
0 Kudos
Message 3 of 4
(3,253 Views)
Not exactly sure what you mean on 'affecting the count down/up speed', but if that value needs to be variable, change the ms constant to a control on your front panel - so you can change it easier. If it needs to programmically vary, then wire that value (from its source) in place of the constant. ??
0 Kudos
Message 4 of 4
(3,253 Views)