# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to implement a TDD system which is time sensitive to the switching operation (in other other words, time synchronisation error in microseconds)

I am using two USRPs and I am implementing a TDD link between them. Let's name them USRP1 and USRP2

I am using two boolean flags to switch between transmission from one USRP to another. This is as shown here:

Fig. 1

Every 10msecs, I execute the loop to make changes to the boolean flags. When USRP1 Tx flag is True and rest of the flags are False then USRP1 performs transmission and USRP2 performs reception. After 10msecs, USRP2 performs transmission and USRP1 performs reception. When Change Freq flag is True, both USRPs do nothing.

The transmission is performed as shown in the block diagram:

Fig. 2

During transmission, I generate a sine wave of certain frequency and time duration and send it over USRP. I do not add any other information to the frame. I perform transmission only when the appropriate flag is True. There is one other flag here, which is USRP1 Tx Complete which is more related to logic I have built and not related to the problem I am facing right now.

During reception, I receive sine wave on the USRPs. This is as shown here:

Fig 3

If the appropriate flags are set true, the USRP should start receiving. Both the USRPs have their individual flags which are labelled as USRP1 Tx and USRP2 Tx. The problem I am facing is that with this logic, I notice that when I run the VIs in highlight mode, there is difference in the status of the boolean flags USRP1 Tx within the infinite while loop timed at 10msecs (Fig. 1) and the boolean Flag in Fig. 2 and 3. For e.g., if the value of the flag in Fig. 1, at some time instance t0 is True, it doesn't get updated immediately in Fig. 2 and 3. Basically, it takes time before the value in Fig., 1 gets updated in Fig. 2 and 3. Hence there is this synchronisation error between flags in Fig 1 and the while loop operation in Fig 2 and 3.

My question is: Is there a better way of doing this TDD operation? I need the while loop in Fig., 2 to be entered as soon as flag in Fig. 1 is set to True and exit the while loop in Fig 2 as soon as flag in Fig 1 is False.

Message 1 of 4
(245 Views)

## Re: How to implement a TDD system which is time sensitive to the switching operation (in other other words, time synchronisation error in microseconds

• Please attach actual LabVIEW code, preferably in LabVIEW 2021 or earlier (many experienced LabVIEW users don't upgrade every year).  A closer examination of the code by us is probably advisable.
• If possible, include the entire LabVIEW Project (easiest done by compressing the Project folder, yielding a ZIP file you can attach).
• You do realize, I hope, that when you run in "Highlight Execution" mode, all timing is slowed way down.
• I'm concerned by how you are using three Global Variables to manage this song-and-dance.  Makes little logical sense to me (but then I'm seeing only a tiny piece of code, I'm guessing ...)
• Once you get into the While loop, you never get out until the Stop button is pushed.  Suppose when called, USRP1 Tx is true, everything else is False.  At some point in time (having nothing to do with the 10 ms Timer, but probably happening within a few nanoseconds on entering this loop), USRP2 TX will be set True and USRP1 TX will be set false.  10 ms later, the While will run again, and at some unknown time (probably measured in ns), Change Freq will be set True and USRP2 TX will be set False.  Repeat the last sentence, but now Change Freq is set False (again at unknown time).  After this, nothing changes until Stop goes true and the loop stops.

Is that the intended behavior?  If so, although it makes no logical sense to me, then you coded it correctly.

If this is not what you intend, then you really do need to show us the entire code, and explain what you want to do, not how you want to do it!

Do you understand the ideas of Data Flow?  Do you realize that you cannot predict the order of operations inside a While Loop such as yours that has elements (like the setting of three Globals) not directly connected to each other by wires?  Have you had sufficient experience with LabVIEW and Data Flow to understand why Global Variables are often a Bad Idea (particularly for programmers familiar with other text-based languages who are encountering LabVIEW for the first time)?

Bob Schor

Message 2 of 4
(178 Views)

## Re: How to implement a TDD system which is time sensitive to the switching operation (in other other words, time synchronisation error in microseconds

Hi @Bob_Schor,

first of all, thank you very much for replying. I appreciate the help.

I have attached the compressed file along with this thread. The main files (or main VI) are USRP_singlecarrierTDMUSRP1 and USRP_singlecarrierTDMUSRP2. The others are just subVI needed to run the main program. Please note that I do not have that good experience with LabView to understand the advantages and disadvantages of global variables. As you mentioned, I only have text based programming language experience till now. So I sometimes program in obviously stupid way in LabView. But I am here to learn.....

1. I am using three global variable exactly as  you described. But I need the change to happen exactly every 10msecs. If I group the boolean flags as (USRP1 Tx, USRP2 Tx, Change Freq) and start the VI, I begin with (1,0,0) at t0, then at t0+10msec, the flags should become (0,1,0), at t0+20msec, I should get (0,0,1) and at t0+30msec, the flags should become (1,0,0) and so on.... These flags are the control flags and they guide how the rest of the program works.

2. Each of the while loop are stopped by the global variable stop which is present in VI system stop. I tried using local variable to stop but I kept on getting error saying latch function is not possible.

3. When USRP1 Tx is true, USRP1 transmits a sine wave containing 4000 samples over the air and USRP2 receives the samples. When USRP2 Tx is set to true, USRP2 transmits sine wave containing 4000 samples over the air and USRP1 receives the samples. After the samples are received, the receiver performs DFT and extracts frequency, amplitude and phase values.

4. When Change Freq is True, I reset all the other flags, save the amplitude, frequency and phase values and repeat the process again.

What I want to do is for e.g., if the flag transits from (1,0,0) to (0,1,0), the USRP1 should immediately stop the transmission and start receiving and USRP2 should immediately stop receiving and start transmitting. That means, I should exit the while loop responsible for transmission and switch to while loop responsible for reception. Right now that is not the case. When I run the VIs in highlight mode, I notice that for some duration of time, USRP1 is still transmitting even after the flags are (0,1,0) and then it switches to reception. It could be that this problem might exist only in highlight mode. But how do I verify that the problem does not exist when I run the VI in normal mode? In other words, how do I make sure that the transition is sharp when the flags change.

Second question is, is there a more optimal way of programming the VI here? Are the global variable causing any problem?

Message 3 of 4
(148 Views)
Solution
Accepted by topic author labview_wannabe

## Re: How to implement a TDD system which is time sensitive to the switching operation (in other other words, time synchronisation error in microseconds

Well, the attached code (thank you!) is something of a mess.  When I first started learning LabVIEW (I was an experienced Macro, Fortran, and Pascal programmer, so knew about "Structured Programming"), I read "The LabVIEW Style Book" cover-to-cover about 3 times.  Now (almost) all of my wires are straight and short, there are sub-VIs with icons to "hide the messy details", and every VI (including the Top Level VI) fits on a Laptop screen.  And I can "walk" a non-programmer through the logic of the program.

But never mind.  I couldn't find where in your code that you attached the "Strange Loop" (please forgive me, Douglas Hofstadter) that cycled through the three "States" of your program.  Here is a loop that spends one second in each of three states (the output is the name of the State), with a single Stop button that stops the whole system when the State running when Stop is pressed finishes.  I'm writing it as a LabVIEW 2019 SP1 snippet.  It uses an Enum that I call "State" that takes on the values "State 1", "State 2", and "State 3" (which makes for a convenient "output" for this VI).  I call this a "State Cycler" ...

Bob Schor

Message 4 of 4
(112 Views)