LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA - host and target timing

Hello to everyone.

I am doing some project on NI sbRIO-9636  and I have created Target and Host VI. Project is about speed regulation of two DC motors.

 

In Target VI I get data from encoders and send the number of pulses in host VI (using FIFO). 

In Target VI loop timing is 25us. This means 10ms/25us = 400 elements every 10ms I need to get from buffer

 

 

In Host VI I do the calculations in order to get the velocity of the motors and plot the speed on the XY graph. I extract one element from array (with Index Array) and plot every 10ms. 

 

Here is the problem: 

When I change the speed manually I see changes on the XY graph about 4 or 5 secons after I changed the speed, which means that data arrived late to the Host.

 

Can anyone tell me what is the problem, because I think I did the calculations in timing well?

 

Thanks in advance.

0 Kudos
Message 1 of 12
(4,244 Views)

Hey,

Please mention the host side and target side buffer sizes, also attaching the both VIs would be great . 

0 Kudos
Message 2 of 12
(4,220 Views)

Hello Charanasai,

 

Here are my VIs for one motor. Where can I read buffer sizes?

 

Thanks in advance.

 

Download All
0 Kudos
Message 3 of 12
(4,173 Views)

Hey there,

You are using delay of 10msec for every loop in host vi  instead of using a timed loop!

 In Fifo.Configure, requested depth is the Host buffer size and when you create FIFO on Target side the number given for requested number of elements is Host buffer size ( for more info ).

As you are using 25us loop time, to collect 400 samples on Target side will take 0.1 sec. And if your target buffer size is 1024 or sth,to fill it will take some more time,this along with 10msec delay on Host side is may be causing the problem .

 

 

With my little experience, I suggest you to use timeout as 0 everywhere to avoid overflows or underflows.(for more info  refer this.)

I personally find this below code is most successful. TRy to use sth like this .

sample code.png

All the best 🙂

Message 4 of 12
(4,133 Views)

Hello Charanasai.

 

 

Thank you for your help.

 

I want to ask you one more question. What actually happens here in my LV project (Host and Target) when I put delay? (I wanted to  know this in order to understand the problem better.) If you could explain to me it would be very helpful.

 

Thank you once again.

 

 

0 Kudos
Message 5 of 12
(4,041 Views)

Hey,

Glad I could be of some help 🙂

As you are putting delay, it will delay the loop execution by 10msec for each iteration of the loop, instead you have to use a timed loop where your loop time should be 10msec or the time required for acquisition of 400 samples, whatever is your requirement.

 

Message 6 of 12
(4,020 Views)

I don't recommend using a timed loop in your host VI, unless there's some particularly good reason to do so. Rather, you should simply eliminate the Wait (ms) function from your original loop, and instead let the FIFO Read dictate your loop timing. You probably want your timeout slightly longer than 10ms, in case there's some delay; even with a long timeout, the loop will still proceed each time there are 400 data points available.

 

The size of the buffers is mostly irrelevant to the delay; you don't need to fill the buffers before you start receiving data. However your code has some problems. The most serious one is that you have an array that grows on every loop cycle, stored in a shift register. That array will need to be copied into new, larger locations in memory, and the larger that array grows, the longer it will take to do that copy. Eventually that array will become so large that there won't be an available block of memory large enough to fit it, even if you have plenty of RAM.

Message 7 of 12
(3,982 Views)

My bad.. sorry!  I agree, buffer size is irrelevent to the delay. 🙂

Message 8 of 12
(3,970 Views)

Hello Nathand.

 

Thank you for your help. So, can you tell me how to avoid that problem with growing array? What I need is only first element from this array. I can't read elements one by one, so in any case I will get some array, right? Can you please tell me more about solving this?

 

Thanks in advance

0 Kudos
Message 9 of 12
(3,941 Views)

This code is a problem:

Insert Into Array problem.png

Each time you insert a new element into the array, the array grows. As a style note, there's no need for the insert into array at all, just expand the Build Array down to add an additional input - although that change will have no effect on the problem of constantly-growing memory use.

 

Consider using a chart instead of a graph, so that you aren't maintaining the entire history of the graph yourself. A chart stores only its designated history length, removing older data as necessary. Otherwise, you should remove the data yourself when your array gets "too large" to prevent the arrays from growing out of control.

Message 10 of 12
(3,920 Views)