Hello Guest it is October 31, 2024, 07:50:00 PM

Author Topic: Average stuff  (Read 4448 times)

0 Members and 1 Guest are viewing this topic.

Average stuff
« on: March 09, 2011, 02:11:30 AM »
Hi,

Im looking to take an average of an analogue input over a period of time, maybe also a couple of inputs averaged into one oem dro, im struggling to see how to do it with timers and things, any ides?

I need to do something like continuosly sample the inputs(s) and give an avergaed out put every 0.5s from the previous 0.5s.

Thanks

Matt
Re: Average stuff
« Reply #1 on: March 09, 2011, 04:54:52 AM »
Have been thinking, would this be easier to do in a macro??

Do macros have access to all the same variables as brains, oem dro numbers etc etc??

Matt

Offline poppabear

*
  • *
  •  2,235 2,235
  • Briceville, TN, USA
Re: Average stuff
« Reply #2 on: March 09, 2011, 09:44:07 AM »
Yes, something like that would be better to do in a VB macropump, or a cyclic VB script.

   If you want to do averaging over a 0.5 seconds intervals, that would be 500ms or 5 updates of Mach3.
So, you could use 8 UDROs, one of the UDROs would be your counter DRO, one would be where your
current Analogvalue would be, and one would be the UDRO you use on your screen to display the average.
so you would need to feed your "currentAnaIn" DRO via Brians if your pulling that value in over the modbus,
or what ever device. (I didn't use select case since it has move overhead time wise). UDRO 2007 will be your
screens display dro.

so in macropump it might look like this:

'macropump.m1s

MyCurrentAnaIN =    GetUserDRO( 2000 )   'feed from your analog in
ValueOne =           GetUserDRO( 2001 )
ValueTwo =          GetUserDRO( 2002 )
ValueThree =        GetUserDRO( 2003 )
ValueFour =            GetUserDRO( 2004 )
MyCounterDRO =    GetUserDRO( 2006 )

If MyCounterDRO = 0 Then         'scan 1
SetUserDRO( 2001, MyCurrentAnaIN )   'fill ValueOne
SetUserDRO( 2006, 1 )         'MyCounterDRO
End If

If MyCounterDRO = 1 Then         'scan 2
SetUserDRO( 2002, MyCurrentAnaIN )   'fill ValueTwo
SetUserDRO( 2006, 2 )         'MyCounterDRO
End If

If MyCounterDRO = 2 Then         'scan 3
SetUserDRO( 2003, MyCurrentAnaIN )   'fill ValueThree
SetUserDRO( 2006, 3 )         'MyCounterDRO
End If

If MyCounterDRO = 3 Then         'scan 4
SetUserDRO( 2004, MyCurrentAnaIN )   'fill ValueFour
SetUserDRO( 2006, 4 )         'MyCounterDRO
End If

If MyCounterDRO = 4 Then         'scan 5
   'Take the average of the last 5 values, including the current on during scan 5
   'and update your screen UDRO 2007 to show your average every 0.5s
SetUserDRO( 2007, ( ( ValueOne + ValueTwo + ValueThree + ValueFour + MyCurrentAnaIN )/5 ) )
SetUserDRO( 2006, 0 )          'MyCounterDRO reset counter for next 5 scans.
End If

'enjoy, Scott
fun times