LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA Wizard Quadrature Encoder Questions

I recently had an opportunity to review the FPGA wizard code and had a few questions regarding the implementation of the QuadratureCtr_X4.vi

 

This VI is located at:

C:\Program Files\National Instruments\LabVIEW x.x\FPGAWizard\PlugIns\Function\niRIOQuadCtr\Templates\FPGA\QuadratureCtr_X4.vi

 

The following items caught my attention:

  1. Local variables are used instead of shift registers
  2. The "First Call?" funtion is replaced by the "First Run?" boolean control

 

 

  1. Local variables are used instead of shift registers
    • Why aren't shift registers used?
    • Is there any resource/performance benefit of this approach vs a shift register

 

 

  1. The "First Call?" funtion is replaced by the "First Run?" boolean control
    • Why not just use the "First Call?" function in the SubVI?
      • It seems like this leaves room for error as the user must wire this value.  Thus, it would leave me to believe there would be a good reason for providing this input.

 

 

I have attached an image of the block diagram for reference.

QuadratureCtr_X4.png

CLA, CTA
0 Kudos
Message 1 of 3
(3,092 Views)

Hi LVB,

 

You seem to have great grasp best practice FPGA programming. Honestly, I don't know the exact reason the wizard is designed this way. That said, let me put in my two cents about why I think it is built this way.

 

1. While shift registers are best practice for accessing variables like this, as long as we aren't truly accessing the data in parallel, this code will work just fine. The real issue with local variables comes with race conditions or unpredictable behavior with data access and manipulation in parallel conditions. Since the implementation isn't important to the function in this instance, I guess the developer went with readability over best practice.

 

2. For this one, I believe that the develpers took this route so that it didn't actually have to be the "first call" you can reset the functionality at any time during execution by toggling this boolean.

 

I hope this satisfies some of your curiosity.

Cheers!

TJ G
0 Kudos
Message 2 of 3
(3,076 Views)

@LVB wrote:

I recently had an opportunity to review the FPGA wizard code and had a few questions regarding the implementation of the QuadratureCtr_X4.vi

 

This VI is located at:

C:\Program Files\National Instruments\LabVIEW x.x\FPGAWizard\PlugIns\Function\niRIOQuadCtr\Templates\FPGA\QuadratureCtr_X4.vi

 

The following items caught my attention:

  1. Local variables are used instead of shift registers
  2. The "First Call?" funtion is replaced by the "First Run?" boolean control

 

 

  1. Local variables are used instead of shift registers
    • Why aren't shift registers used?
    • Is there any resource/performance benefit of this approach vs a shift register

 

 

  1. The "First Call?" funtion is replaced by the "First Run?" boolean control
    • Why not just use the "First Call?" function in the SubVI?
      • It seems like this leaves room for error as the user must wire this value.  Thus, it would leave me to believe there would be a good reason for providing this input.

 

 

 


1 this wizard was created before free feedback nodes were available.  shift registers were not used because you could not put while loops inside single cycle timed loops.  this is the only implementation at the time that would allow you to encapsulate the functionality within a sub-vi.
if you were implementing this today (2010) , free feedback nodes would be used.

2. this issue is less clear.  first call could have been used since a separate reset was provided. 

Stu
0 Kudos
Message 3 of 3
(3,069 Views)