Jump to content

Recommended Posts

Good Morning Guys / Gals

I am trying to find a solution for a piece of test equipment that i have built for a client, i am using a SM43 with Analog inputs and outputs and when we built the equipment the client wanted a peak reading, he is now asking for an average reading.

The test being carried out is about 15 seconds long and the first 2 seconds are ignored so in essence i need to average a reading from a 0-10v input for 13 seconds and display it on the screen at the end of the test, i am hitting a total blank of how to do this my thoughts were to take a sample every 1/2 second and add together and divide the end result but the amount of code seems huge, is there a simpler way to do it or even a block i am missing, or can i create a block with all this code in.

Thanks  

Link to post
Share on other sites

+1 on what Aus says on the Filter limitation. 

I've had jumpy analog inputs I've had to filter up to 100 values.  I wrote a routine that stuffed a small data table that added the incoming value to a total and then stuffed it into the top of a data table after pushing all the other ones down and incrementing a pointer.  The pointer was the divisor of the total until it reached the total number of samples that I wanted, and then I used it to point to the row of the data table that had the oldest value and subtract it from the total before dividing it.

Overkill?  Yes.  But very precise overkill with the ability to change the number of samples on the fly.

Joe T.

Link to post
Share on other sites

I assumed @muckingfuddle wanted an actual average, not a moving average.

For a 100 point moving average you could use MIs and indirect addressing. For 1000 points, you probably need to use a Data Table, as Joe suggests above, but for 10,000 points or more you're probably out of luck.

At one time I came up with a routine for an approximation of a moving average for any number of points that I've never used, because I don't trust it, but I'm interested in finding out if it might be useful. Simply subtract the average from the sum and add the most recent data point then divide by the number of points to obtain the new average, and repeat. Only 4 registers needed - the most recent data point, the sum, the number of points total, and the average. I've simulated it in an Excel spreadsheet and it appears to follow an actual moving average very closely, but I'm worried that there is a flaw that I'm not seeing that might crop up under unusual circumstances. I think I need a mathematician.

Link to post
Share on other sites

Hi All, i have tried the solution provided by @Flex727 and the solution works pretty well, i did have to change the MI inputs to ML inputs as the number was overrunning and becoming negative, not really sure if that is the correct way but it did seem to work, one issue i seem to get is that sometimes my analog input seems to go negative and that really screws up my average, is there a way to stop my analog input going negative, i do have a calibration adjustment which i would like to stop at 0 but can potentially go negative.

 

 476517297_BRDATESTER.PNG.e6588795efdfde2e005f4dc0e02bbf3a.PNG

Link to post
Share on other sites
13 hours ago, muckingfuddle said:

one issue i seem to get is that sometimes my analog input seems to go negative and that really screws up my average, is there a way to stop my analog input going negative

Yes, insert this just above ladder rung 36:

image.png.02f4e9e61f0cc9498f7cab8a007c65c6.png

Link to post
Share on other sites

Hi,

I recommend STORE DIRECT "Value" to "Variable" with condition (value>=0). And use "Variable" for calculate AVERAGE.

If "Value"<0 then RESET "Variable".

In this case it is possible to generate error if "Value" is not correct ("Value"<<0) with no signal on input.   

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...