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.
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.
04-29-2022 09:18 AM
Hi All,
In the images attached to this post, I have two main loops that run one after the other. I'd like to have one output window with a graph and data that updates with each iteration for both loops. The UpperandLower.png shows the two main loops. At the bottom of the image shows my attempt at selecting which data is written to the output window. THD data.PNG gives a better look at my data selection logic and the output window. I'm sure there's a much more straight-forward (and functional) way to do this, so I appreciate any feedback.
I was going to add the project to this post but at 24MB, it exceeds the 10MB limit. For whatever reason, 7-zip wasn't cooperating.
04-29-2022 09:48 AM
Use a 3rd update loop which is a queue that waits for data (check out the Producer/Consumer example), then you can easily queue up data each loop and the 3rd loop will update accordingly.
04-29-2022 10:54 AM - edited 04-29-2022 11:04 AM
Your code is a prime example to implement a state machine instead. Your two loops are never active at the same time and contain mostly identical code, so all you really need is one loop and switch state accordingly.
It is hard to fully gauge the code from a truncated picture (we can't even see the toplevel loop!), but I think there are serious architectural problem and the the entire thing could be done with much less than half the code.
There are also other fundamental flaws, such as poor choice of datatype ((using orange for obvious integers and even doing bitwise operations on them!!! 😮 )
The circled code in the left is pure madness! It does not take two selects, two comparison, and two case structures to turn two booleans into a numeric!!!!!
I'd consider starting from scratch with a proper state machine and all your problems will disappear. good luck!
We can probably give more targeted advice if you would attach the entire code and explain what it it supposed to do.
04-29-2022 11:23 AM
@altenbach wrote:
The circled code in the left is pure madness! It does not take two selects, two comparison, and two case structures to turn two booleans into a numeric!!!!!
.
To turn two booleans into a 0..3 numeric, here's all you need.
(see also)
04-29-2022 12:00 PM
Hi altenbach,
Thank you for the example of how I can simplify the logic. I had a feeling I was way off on the best way to do this. I'd definitely be interested in learning more about implementing a state machine in my code.
A little overview on what I'm trying to do: I'm trying to create a THD test for a power amplifier where the user enters the frequency spec range, say 1kHz to 10kHz as well as a middle frequency starting point. The program takes the middle frequency starting point and measures THD up to where the THD limit is reached. (Say 3%) Once the upper limit is reached, it moves to the lower frequency limit loop and does the same thing.
So I ideally need a single pop-up window that displays data as the upper frequency and lower frequency loops collect data one after the other.
Sound like something a state machine would be good for?
04-29-2022 12:30 PM
@JayWW wrote:
A little overview on what I'm trying to do: I'm trying to create a THD test for a power amplifier where the user enters the frequency spec range, say 1kHz to 10kHz as well as a middle frequency starting point. The program takes the middle frequency starting point and measures THD up to where the THD limit is reached. (Say 3%) Once the upper limit is reached, it moves to the lower frequency limit loop and does the same thing.
OK, that's not clear at all because you have two upper limits. (A) The one entered by the user (10kHz) and (B) the one where THD exceeds 3%. Is A always larger than B or can A be exceeded if the THD limit has not been reached?
Simple enough! that code should fit on a postcard! You have three main states:
04-29-2022 12:39 PM
Sorry for the confusion. The upper and lower frequency spec numbers are actually irrelevant when it comes to how the test logic works. The program itself will find the upper and lower limits.
To answer your question, typically the THD will pass beyond the given frequency range spec, unless there's something wrong with the unit.
04-29-2022 02:11 PM
Well, there still needs to be some upper limit. Seems unreasonable to ultimately go to THz just because the THD measurement is faulty. 😄
I guess a hard lower limit is 0Hz. 😄
If this is audio, maybe 44.1kHz is a good hard upper limit? Should the scanning be linear or logarithmic?
04-29-2022 02:27 PM
I would definitely have an "Abort" button or move to next step in the test button in case a loop gets stuck. But for the most part as soon as you move too far out from the frequency spec the output transformer begins to saturate and that causes a lot of noise.
The sweep would be linear. I'm trying model it after this extremely old test bench that's on it's last legs using all discreet test equipment. In his test routine, if the jump from one frequency to the next causes too much THD, the frequency gets dialed back and retested. These adjustments occur about five times before it's determined to indeed be in a high THD zone.
04-29-2022 03:35 PM
@JayWW wrote:
... the output transformer begins to saturate and that causes a lot of noise. .
Unless the connector fell off. 😄
To give you some pointers, here's a quick demo for a state machine. Easily fits on a postcard. 😄