Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

Question on DataTable Average function


MatthewBoyd Dec 31, 2013 10:38 PM

Hello,
Could someone please tell me precisely how the Average function works in a DataTable? For instance, if my Scan is every 1 sec and the DataInterval for the table is 1 min, will the value measured at 0min:59s be the last value included in the average at 1min:00s, or will the last included value be that measured at 1min:00s ?


For the below pseudocode, I'm finding that the analog measurements included in their averages are those measured between :00s and :59s (inclusive), but the serial measurements included in their respective averages are those measured between :01s and :00s (inclusive). Does anyone know why this may be?


DataTable(AnalogTable,True,-1)
DataInterval(0,0,sec,10)
Sample(1,Analog1,FP2)
...
EndTable

DataTable(SerialTable,True,-1)
DataInterval(0,0,sec,10)
Sample(1,Serial1,FP2)
...
EndTable

DataTable(OneMinTable,True,-1)
DataInterval(0,1,Min,10)
Average(1,Analog1,FP2,DisableAnalog)
...
Average(1,Serial1,FP2,DisableSerial)
...
EndTable
'****************************************

Scan(10,sec,0,0)
...
SubScan(1,sec,10)
AM25T(Analog1,...)
...
CallTable(AnalogTable)
DisableAnalog = False
DisableSerial = True
CallTable(OneMinTable)
NextSubScan
...
NextScan

SlowSequence
Scan(1,sec,0,0)
ModBusMaster(...,Serial1,...)
...
CallTable(SerialTable)
DisableAnalog = True
DisableSerial = False
CallTable(OneMinTable)
NextScan

* Last updated by: MatthewBoyd on 12/31/2013 @ 3:40 PM *


willB Jan 3, 2014 10:03 PM

Matthew,

I have forwarded this on to engineering for a solid answer for you. Thank you for being patient. Someone should respond soon with an answer.


willB Jan 3, 2014 11:39 PM

The last value should be the one measured at 1min:00s.

The user is calling the same table from two different sequences. This results in a time synchronization problem.

Internally each sequence keeps its own timestamp. This is the time used for data tables that output during a given interval. This time is advanced each time the scan runs.
Both the subscan and the slow sequence scan are programmed to run at 1 sec. Obviously, they cannot both run simultaneously.

As the program is written, the Slow Sequence is executing its calltable prior to the main scan. This is evident from the lag in the analog data.
When the slow scan runs at the 0min:59s boundary, it advances its time to 1min:00s, calls the table and detects that it is time to output. As each of the instructions between DataTable and EndTable execute, they also detect that it is time to store their data and so they do. Keep in mind that the main scan has not executed at this point so the data associated with it is still one scan behind. The EndTable instruction advances the next output time to the next 1min:00 boundary.

Immediately after the slow sequence completes its execution, the main scan will advance its time from 0min:59s to 1min:00s and call the table again. The table does not output because it is now programmed to output at the 2min:00s time slot.

Another problem with calling the table from multiple sequences is that the averages are updated each time the table is called so in this case the analog averages are updated when slow sequence calls the table and then again when the main scan calls it, vice versa for the serial when the main scan executes.

The key is that when crossing sequence boundaries, there must be care taken to avoid synchronization problems in time and in data access (i.e. accessing data from one sequence as it gets changed by the other).

The SemaphoreGet and SemaphoreRelease instructions are helpful to avoid synchronization problems.


MatthewBoyd Jan 6, 2014 01:47 PM

To review, the one-minute average table can only be called once within one sequence because the first time it executes at the :59sec/:00sec boundary, it changes the average period to the next :59sec/:00sec boundary. Furthermore, you cannot separate out the measurements from different sequences using DisableVar's because the table is only called once, and thus you lose the ability to change their True/False status for different calls (because there can only be one call).

Is there any way I can group the tables in the below updated pseudocode, preferably the one-minute average tables? We need to keep the number of tables to a minimum for our database software. Thanks.



DataTable(TempTable,True,-1)
DataInterval(0,0,sec,10)
Sample(1,Temp1,FP2)
...
EndTable

DataTable(AnalogTable,True,-1)
DataInterval(0,0,sec,10)
Sample(1,Analog1,FP2)
...
EndTable

DataTable(SerialTable,True,-1)
DataInterval(0,0,sec,10)
Sample(1,Serial1,FP2)
...
EndTable

DataTable(OneMinTempTable,True,-1)
DataInterval(0,1,Min,10)
Average(1,Temp1,FP2,False)
...
EndTable

DataTable(OneMinAnalogTable,True,-1)
DataInterval(0,1,Min,10)
Average(1,Analog1,FP2,False)
...
EndTable

DataTable(OneMinSerialTable,True,-1)
DataInterval(0,1,Min,10)
Average(1,Serial1,FP2,False)
...
EndTable
'****************************************

Scan(10,sec,0,0)
BrHalf4W(Temp1,...)
...
CallTable(TempTable)
CallTable(OneMinTempTable)

SubScan(1,sec,10)
AM25T(Analog1,...)
...
CallTable(AnalogTable)
CallTable(OneMinAnalogTable)
NextSubScan
...
NextScan

SlowSequence
Scan(1,sec,0,0)
ModBusMaster(...,Serial1,...)
...
CallTable(SerialTable)
CallTable(OneMinSerialTable)
NextScan

* Last updated by: MatthewBoyd on 1/6/2014 @ 6:51 AM *

Log in or register to post/reply in the forum.