LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Running Average from 5 Samples taken at 20mSec appart!

Solved!
Go to solution

Hi All ,

I need some help please ,(labVIEW beginner)

I have a CAN message that comes in every 20mSec I then take out the 8 bytes of data out this is all working fine howver I would like to add 5 values (5 x20mSEC ) and build a Running average of the values as indicated in the attached sketch ,A and B.

I know  that I can use the Mean pt to pt Vi and propably the compound artihmetic  ,I tried a for loop with a shift register however it seem in every 20mSec the for loop execute 6  times and add the same value 5 times,

it does not take the sample add it once and then in the next 20mSec it add the second value .

How can I solve my problem .

I appreciate all help and directions  

Regards 

QMESAR

1.jpg

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 1 of 29
(3,719 Views)
  • Do you know that "index array" is resizeable and gives you the elements in order if the index is not wired?
  • Did you search the forum for "running average"? "Mean ptbypt" in the palette. It will work if you don't constantly reset or e.g. use "continuous run" mode. If it doesn't, show us your actual VI. (What does this have to do with "compound arithmetic", "loops" and "shift registers"? If you drop "big words", be more specific. There is an infinite variety of possibilities to arrange them and many are wrong.)
  • small integers (e.g. U8) are difficult to average (division, summation, overflow wraparound, etc.), so you want to convert to a floating point representation.
  •  Your code has the measles with all these coercion dots. Pick a suitable representation and run with it!
  • There is almost never a good reason to use a stacked sequences.

 

Message 2 of 29
(3,714 Views)
Solution
Accepted by topic author QMESAR

You should just have to use the point by point Mean vi. It does not require a loop to work. Here is an example.

 

Avg Example.png

 

I would add the first call to make sure that when you start your program that the avg reinitialize. You could also add a button that you could press that would reset your running avg.

 

Tim
GHSP
Message 3 of 29
(3,703 Views)

Dear aeast.

Thank you for your kind reply this seams to do what am am trying to do.I apprecaire your small example .I just added to my code and it is working fine ,

 

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 4 of 29
(3,684 Views)

I'm glad I could help.

Tim
GHSP
Message 5 of 29
(3,678 Views)

Dear altenbach ,

Thank you for your reply !

As I can see from your signature you are very higly experienced with this which I am not ,This is my very first attempt at using labVIEW after doing a Basic 1 course,so yes I have very little knowledge and experience in this field .Secondly I am not trying to use big words ,I have found examples on this forum (and yes I did search the forum ) which shows how to do this by using a while loop with a shift register that puts the values in a Compound aritmetic vi and then divide it by the number of samples clearly mentioned an Average so this is where my big words come from.

Thank you for your comments I will look at all of it as I am trying to learn and are prepared to take a beating such as yours to learn .

The stacked sequencs is recomended by the machine manufacturer to read the CAN messages out as  the LV application needs to send the command to get the received ID(over USB) then wait 1mSec and then send the command to the unit to send the received data bytes back all over USB . I will enquire with them why the stack sequence is necessary.

 

Send Command for ID then select the correct ID in the case structure

1.jpg

2.jpg

Thank you once again for your comments it is appreciated 

Regards 

QMESAR

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 6 of 29
(3,676 Views)

Since there is a data dependency between the code in frame 1 and the case structure in frame 2, execution order is fully determined and the sequence is obsolete.

 

How often does the rxid change? If it is constant during the run, it only needs to be obtained once at the start of the program.

 

Please stop showing us pictures, attach the actual vi for better help!

0 Kudos
Message 7 of 29
(3,666 Views)

Dear  altenbach

Thank you for the reply, I have realized what you are saying about the data dependency and I corrected it in the RX loop and it is working fine (Thank you )

The Vi is attached I am still having probelms with the red dots I will look more closly,The RXID is constantly changing, it can be 1 of 5 different messages in the RX buffer .

 

Thank you for your advice 

 

PS I select the data however I can not get the VI attached to the post   how do I upload the files to the post

 

QMESAR

 

 

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 8 of 29
(3,649 Views)

@QMESAR wrote:

 

PS I select the data however I can not get the VI attached to the post   how do I upload the files to the post

 


It should just work using the [Choose File] Button below the edit window. Maybe try a different browser.

0 Kudos
Message 9 of 29
(3,630 Views)

I have tried all known Browers not possible to uploaf a .rar file

 it always report I should correct the errors however there is no marked errors to corrcet

Thank you all for your help so far 

1.jpg

---------------------------------------------------------------------------------------
Learning is an endless process but needs to start some where
0 Kudos
Message 10 of 29
(3,612 Views)