It is currently Wed Aug 27, 2014 7:09 am




Post new topic Reply to topic  [ 2 posts ] 
 Data Logging at Precise Sampling Frequency wrt Timestamp 
Author Message
Sergeant
Sergeant

Joined: Tue Nov 03, 2009 8:32 pm
Posts: 46
Post Data Logging at Precise Sampling Frequency wrt Timestamp
I have a required of logging data at a frequcny of 500 millisec. I have tried various options but i cannot seem to allign the timestamp. e.g the timestamp should be
hh:mm:ss.000
hh:mm:ss.500
hh:mm:ss.000
hh:mm:ss.500

............. or always separated by the same interval.
I have tried Triggers from PLC as well as scheduled group but to no avail. What could eb the best method to do this.

One method is to buffer in PLC and read from that, but with the PLC and just using FactorySQL, i want to do this.


Wed Nov 11, 2009 1:00 am
Profile
Moderator
Moderator

Joined: Sun Apr 02, 2006 3:43 pm
Posts: 2493
Post Re: Data Logging at Precise Sampling Frequency wrt Timestamp
Hi,

First off, it's important to note that in terms of actual sampling precision, you're not going to be able to get down to the millisecond. There are too many variations along the chain from the PLC to the OPC server, FSQL and the database. I usually tell people not to expect more than about 100ms of precision, and even that can occasionally shift.

I know you're logging at 500ms, so that's fine- but I just want to make sure you don't expect the sample to be taken at a given millisecond. If that's what you want, you definitely need to buffer in the PLC. I believe there are a few threads on the forum here about how to then read those buffers from FSQL.

However, if you want this just so that your data lines up for table/correlation purposes, and the "000"/"500" millisecond values are more just IDs than actual timestamps, there are a few things you could do. First, instead of relying on the timestamp for the correlation, you could use a separate column for the "sample_id", which would be 0 if it were the 000 sample, or 1 if it were the second sample for the time. You could do this with an action item:
Code:
if(ToInt(DateFormat(now(),"fff"))>500,1,0)

(Note: the expression looks a bit strange because it seems that DateExtract doesn't support milliseconds (or I couldn't find the right keyword), so I used ToInt & DateFormat to get the milliseconds)

Basically what this is saying is that you know there will be two samples per second. You don't know exactly at what time they'll occur- that depends on when the group is started, and when it runs (which can be imprecise on the order of milliseconds, ignoring the effects of system load), but that you want to identify the executions as either the first or second one.

That's easy, but of course it can make your queries more difficult. You have to group based on an expression of the timestamp, and then on this column as well if you're trying to execute aggregate functions, among other things. Instead, it really would be best for the data to be only in the timestamp. Therefore, what you could do would be to create your own timestamp instead of using the built-in FSQL option.
1) Uncheck "Store Timestamp" on the Action panel
2) Create a new action item
3) Use an expression like:
Code:
ToDate(Concat(DateFormat(now(),"yyyy-MM-dd HH:mm:ss."), if(ToInt(DateFormat(now(),"fff"))>500,"500","000")))

4) Store results as date datatype to "t_stamp", or appropriate date column.

In this way all of your timestamps will be either 000 or 500 in the milliseconds field.

Hope this helps,

_________________
Colby Clegg
Inductive Automation
Software Development


Wed Nov 11, 2009 9:39 am
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: