# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Tunnels vs Shift Registers

Hi!

Let us say we have a loop with controls outside the loop to be initialized before loop run-time. I have seen applications using shift registers to connect the loop content with outside controls. Are there any advantages of using Shift Registers this way over Tunnels?

Message 1 of 12
(3,570 Views)
Solution
Accepted by sskr33

## Re: Tunnels vs Shift Registers

@sskr33 wrote:

Are there any advantages of using Shift Registers this way over Tunnels?

Yes, the values in the shift registers can be set inside the loop. So iteration 0 sets the values for iteration 1. That is in fact the hole point of a shift register. Usually (there are corner cases*) if you don't want that a tunnel is better.

All this stuff is probably in the (free) online courses (although I never did them).

* A 'corner case' (pretty common, but for this context) is when an output of the loop needs to make sense even if the loop iterates 0 times. This is important for instance when references are used. Two tunnels (in and out) would change the output to a 0 reference if the loop runs 0 times. A shift register would output it's input.

Message 2 of 12
(3,556 Views)

## Re: Tunnels vs Shift Registers

wiebe@CARYA wrote:

@sskr33

Yes, the values in the shift registers can be set inside the loop. So iteration 0 sets the values for iteration 1. That is in fact the hole point of a shift register. Usually (there are corner cases*) if you don't want that a tunnel is better.

Having to set the starting value inside the loop sounds like a corner case to me. I can't say I have ever used a feedback node since it inception as I have yet to run into a case where a shift register would not suffice. You know you can "preset" a shift register so iteration 0 starts at any value you want.

========================
=== Engineer Ambiguously ===
========================
Message 3 of 12
(3,504 Views)

## Re: Using Matlab in Labview

Feedback nodes are handy especially in larger state machines where you have one case that needs a value from a previous iteration. Rather than having to wire the value to a shift register and wire it through all of your case you can simply put a feedback node in that one case and all is good.

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
Message 4 of 12
(3,474 Views)

## Re: Tunnels vs Shift Registers

@RTSLVU wrote:

Having to set the starting value inside the loop sounds like a corner case to me.

I think wiebe was referring to updating the value for the next iteration, not the starting value

@RTSLVU wrote:

I can't say I have ever used a feedback node since it inception as I have yet to run into a case where a shift register would not suffice.

A Shift Register and a Feedback Node as essentially the same thing.  But I do find Feedback Nodes quite useful for things like comparing a value to its previous iteration.  It saves wiring.

There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 12
(3,469 Views)

## Re: Tunnels vs Shift Registers

@crossrulz wrote:

@RTSLVU wrote:

Having to set the starting value inside the loop sounds like a corner case to me.

I think wiebe was referring to updating the value for the next iteration, not the starting value

Yes, I was.

@crossrulz

@RTSLVU wrote:

I can't say I have ever used a feedback node since it inception as I have yet to run into a case where a shift register would not suffice.

A Shift Register and a Feedback Node as essentially the same thing.  But I do find Feedback Nodes quite useful for things like comparing a value to its previous iteration.  It saves wiring.

A thing about the feedback loop attached to loops is that you can put it inside a structure (even a loop), while still having the initializer on the loop. The rest of the loop diagram doesn't need to have all the wires that a shift register would need. That sounds like a great feature, but I found the use cases very limited. You often want to use the output of the feedback node as well. So you still end up with a shift register...

For me feedback nodes attached to a loop are mostly obscure and mostly useless. That could be biased by a decade of using the shift register.

Standalone feedback nodes are a different story altogether.

Message 6 of 12
(3,351 Views)

## Re: Tunnels vs Shift Registers

Another question:

Do Shift Registers have any advantages over Tunnels in perspective of speed of the execution of the loop or resources consumed when used on FPGA? In case you only use them for initiation, that is (the value doesn't change during the loop run-time).

Message 7 of 12
(3,341 Views)

## Re: Tunnels vs Shift Registers

@sskr33 wrote:

Do Shift Registers have any advantages over Tunnels in perspective of speed of the execution of the loop or resources consumed when used on FPGA? In case you only use them for initiation, that is (the value doesn't change during the loop run-time).

I'd put my bet on a tunnel.

With a SR, LV would likely be smart enough to avoid data copies if the value doesn't change in the loop. But it might (I really don't know for sure) add logic for writing values on the right side even if it never changes. So (IMHO) best case it will be as good as a tunnel, worse case it will be less efficient.

Of course if you want execution speed, you'd use a single cycled timed loop. Then you'd know the execution speed, and LV will make it fit or it will fail to compile. I'd say a SR will require more slices though.

So in execution speed (not really applicable on an FPGA), resources and also compilation time, I'd go for the tunnel. In this situation.

Message 8 of 12
(3,338 Views)

## Re: Tunnels vs Shift Registers

I would bet that the compiler could do a better job of optimizations when it is a tunnel since it is explicit that it will not change inside the loop. A shift register would indicate that the value might change and therefore some optimizations may not be allowed.

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
Message 9 of 12
(3,292 Views)

## Re: Tunnels vs Shift Registers

@Mark_Yedinak wrote:

I would bet that the compiler could do a better job of optimizations when it is a tunnel since it is explicit that it will not change inside the loop. A shift register would indicate that the value might change and therefore some optimizations may not be allowed.

From what I understand anytime you have a tunnel entering a loop it pretty much negates any optimizations so SR or FN makes no difference in that aspect.

========================
=== Engineer Ambiguously ===
========================
Message 10 of 12
(3,289 Views)