From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Count when integer changes?

Solved!
Go to solution

Hi,

 

Hope somone can help me with this. I have an analog gear position sensor, which outputs a voltage between 0 and 10V depending on which gear is selected. (I'm simulating this input voltage in the attached VI using a numeric control, and the levels aren't set correctly yet) Because the gear selector is powered by pneumatic cylinder supplied by an small tank, I'd like to count the number of gear changes.

 

How would I go about setting up a counter which increments whenever the gear selection changes up or down, and which can be reset while the VI is running using a button?

 

 

(PS: What I have at the moment to display gear position works, although I'm sure it could be done in a simpler manner. The entire code runs through for each iteration which isn't very efficient at all. Not sure what would be the best way to improve this as I'm relativley new to LabVIEW.)

 

Thanks for your help.

Kevin

Download All
0 Kudos
Message 1 of 6
(2,410 Views)

when you see a redundant amount of functions in your programming....think "array" , otherwise it's rube Smiley Wink

Spoiler
count.png
0 Kudos
Message 2 of 6
(2,383 Views)
Solution
Accepted by topic author kevinirving64

I recommend to use arrays instead of gigantic code with many duplications. Here's one possibility.

 

We keep the count of gear changes in a shift register and increment whenever the gear is different to the previous value using a feedback node. Modify as needed.

 

 

Download All
Message 3 of 6
(2,375 Views)

@apok wrote:

when you see a redundant amount of functions in your programming....think "array" , otherwise it's rube Smiley Wink


You did not answer the main question about counting the number of gear changes.

0 Kudos
Message 4 of 6
(2,374 Views)

i meant to,lunch time, wife called...

 

my suggestion, shift reg,comparison,add, select...

0 Kudos
Message 5 of 6
(2,365 Views)

Thanks guys, that's absolutely fantastic! I'm using feedback nodes and shift registers in other parts of my project, and played around with them in this VI after posting up but I couldn't get it to work how I wanted. Thanks for suggesting that I use an array - it really has tidied up the code.

 

I'll have a good look through the solution, and see what I can learn from it!

 

Regards,

 

Kevin

0 Kudos
Message 6 of 6
(2,344 Views)