LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Counting up and then count down, over and over

Solved!
Go to solution

Hi,

 

I am trying to make a function that counts up to a specific number and then counts down and does that over and over again. I wrote the logic in C++ but I am having such a hard time converting this into LabView logic. Attached is my code I want it to do in C and then also the VI that I am trying to make work, I also threw in a screen shot of it just for quick reference. Hopefully my code is easy enough to follow. Basically end game I want to feed the rpm output to a frequency port on an fpga sinewave generator. I just want the rpm to wave around the chosen rpm based on how much percentage it should hunt. Right now all it does is stay at whatever the first rpm it saw was. Also I don't have a way to really test what if the C++ code works, but it's fairly simple I think it should work.

 

Thanks,

Download All
0 Kudos
Message 1 of 11
(1,245 Views)

Something like this?

 

Hunter.png

 

It gets tricky if you need to use floating point numbers as 10.000000001 <> 10 

 

Also if you can't open the snippet the True Case just passes Y straight through.

========================
=== Engineer Ambiguously ===
========================
Message 2 of 11
(1,236 Views)
Solution
Accepted by topic author MGardner5

Hi MGardner,

 

learn about LabVIEW basics like shift registers:

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
Message 3 of 11
(1,231 Views)

I did a lot of labview training while it was free last year, just haven't kept refreshed with it lately. You guys replied really quickly, so thank you. Kinda felt like it was quite a simple issue. I am quite more familiar with C, less with visual coding forms like labview.

 

Thanks!

0 Kudos
Message 4 of 11
(1,203 Views)

Hmmm, I was almost sure that would work, but I had to make a few adjustments to the code to make it do as I wished but I still now only outputs a value of 1 continuously. I thought maybe the comparison signs were flipped around but that is not it either. Even tried changing the loop to continue if true. Briefly got it it work and output 1800, but then it failed again without me doing much I don't think

0 Kudos
Message 5 of 11
(1,191 Views)
Solution
Accepted by topic author MGardner5

Hi MGardner,

 

please do the LabVIEW basics (again): learn about THINK DATAFLOW!

 

It does not make any sense to place that "Hunting" button outside the inner while loop!

It also does not make any sense to place that outer while loop, which only iterates once! (That's just Rube-Goldberg!)

 

See this (again):

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO
Message 6 of 11
(1,149 Views)

Ahhhh I see what the issue was, I had my output connected to the rpm output shift register rather than just a node though the while loop. Then I kept overthinking the issue thinking the logic was wrong. Thanks, I am good to go now.👍

0 Kudos
Message 7 of 11
(1,117 Views)
Solution
Accepted by topic author MGardner5

I got some time to sit down and work out the bugs I've been seeing. This is now my accepted version. This now does exactly what I've been wanting it to do. FYI I am running continuously on the project I am going to incorporate this into so that's why I went this route.

MGardner5_0-1628267501282.png

 

0 Kudos
Message 8 of 11
(643 Views)

Do you mean you are using the "Run Continuously" button to execute your VI? If so, don't. This is basically the same as starting the VI an infinite number of times. Essentially it runs the VI and when it finishes it starts it over again. You have no control over the sate of things. If you need your program to run continuously, write the code to do that. I have been programming in LabVIEW for over 25 years and The last time I used "Run Continuously" was probably 25 years ago. 



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 11
(626 Views)

How is that any different than putting everything inside an infinite while loop? My main program is an exe program that logs into a cRIO. The program is active whenever it's connected. I am not sure if that is continuous or not.

0 Kudos
Message 10 of 11
(623 Views)