LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can i make circular buffer using while loop ?

I need to make circular buffer to read value each 100 count by using 2 while the first put the value into array the second read from it.

 

thanks

0 Kudos
Message 1 of 16
(4,107 Views)

Can you explain what you mean? (not clear are e.g. the terms: "100 count", "2 while", "first" , "second"??)

 

What is the size of the circular buffer? (100?) Do you just want to read the oldest before replacing it with a new value? Where does the data come from? What is the purpose?

0 Kudos
Message 2 of 16
(4,102 Views)

Yes sir first thanks for your answer, i will explain what i want.

I have array with 100 element it's the size of it, the first while loop will count from 1 to inf and the counter value will be add to the array but when it's reach to 100 the data will over flow, so i need the second while loop takes the value from array.

Note the first while loop let's say it's work under 1000 Hz and the second 100 Hz so how can i make it work.

0 Kudos
Message 3 of 16
(4,095 Views)

Still not clear at all. Can you show us some simplified code?

0 Kudos
Message 4 of 16
(4,068 Views)

Buffer_loop.png

As you can see i have two while loop the first one with delay 1 ms the second loop with 100 ms.

i need to make buffer. but the delay time is different so what should i do.

the array size is 100.

first loop counter will count from 1 to Inf.

the second loop will read the values from array.

 

hope it's clear this time and thanks

0 Kudos
Message 5 of 16
(4,064 Views)

@Mohammed_Kandeel wrote:

I have array with 100 element it's the size of it, the first while loop will count from 1 to inf and the counter value will be add to the array but when it's reach to 100 the data will over flow, so i need the second while loop takes the value from array.

Note the first while loop let's say it's work under 1000 Hz and the second 100 Hz so how can i make it work.


This sounding a lot like a Producer/Consumer.


GCentral
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
0 Kudos
Message 6 of 16
(4,063 Views)

@Mohammed_Kandeel wrote:

 

As you can see i have two while loop the first one with delay 1 ms the second loop with 100 ms.

 


OK, there are two while loops running in parallel (no first or second).

 


@Mohammed_Kandeel wrote:

 

 

first loop counter will count from 1 to Inf.

 


Integers don't have "Inf".

 


@Mohammed_Kandeel wrote:

i need to make buffer. but the delay time is different so what should i do.

the array size is 100.

 


Since the loop on the left runs 100x faster, a 100 element buffer will only be sufficient during the first 100ms, then it will start dropping data.

 


@Mohammed_Kandeel wrote:

 

the second loop will read the values from array.

 


What array? Why do you think that "delete from array" is the right way to read an element? Should the second loop read all 100 elements? There still needs to be some synchronization.

 

Can you step back for a few seconds and instead tell us what you are trying to achieve? Where does the data come from? What should the second loop do with the data? Why do you even have two loops?

Message 7 of 16
(4,055 Views)

If you are describing a Producer/Consumer setup, as crossrulz guesses, then you might want to take a look at Channel Wires. These might simplify your understanding of the pattern - alternatively, stick with the Queue as detailed in the already linked White Paper regarding P/C, since these have many more examples available on the forums in questions like this.

 

A circular buffer usually describes an array of the most recent N points, with the insertion point rotating around the array (or the array rotating around - probably altenbach can tell us which is the fastest but I'd guess the former).

 

You could use this, but it sounds like what you really want is to stream data from one place to another. For that, the Queue and the Channel Wire are better choices.


GCentral
0 Kudos
Message 8 of 16
(4,043 Views)

Is this what you're meaning?

Queue rotating array.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 9 of 16
(4,022 Views)

Hi all,

sorry if i my explanation didn't get for you.

 

we have queue and queue is just an array but i know it's size and it's FIFO.

so i ask my self if i need to replace the queue by array what will change. and the data it will be just the value of iteration of while loop.

0 Kudos
Message 10 of 16
(4,008 Views)