Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. lqplee
  2. PLCnext Engineer
  3. Thursday, 10 June 2021
How to sample the process values with an adjustable sample rate?
Currently I use a timer with a 1000ms PT and assign the timer in a 1s task. It takes the timer 2-4 seconds to output TRUE. See the picture attached.
I use the output of the timer to start the sample of the instant process value.
I think if the timer is assigned to a 500ms task, it will probably take 1-2 seconds to output TRUE but there is still some inconsistent. What is the best way to solve the accurate sampling rate?

Thanks
Jason
Attachments (1)
Frank PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo
Hi Jason,

I've used your code in a 1s cyclic task and it worked as expected, means ET==PT.
But it might be that I did not fully understood your setting.

I would also recommend to use raise the execution time of your task, maybe a good guess would be twice as fast as your application demands.
So, if you're using a 1s timer, a cycle of at least 500ms would be appropiative...

Another alternative sampling process data (IO Data - Localbus) would be to synchronize the bus cycle with the cycle time of your task.

Example:

  • Create a cycle task with the highest needed sampling rate (maybe 100ms)
  • Open the Localbus Configuration --> Settings --> Trigger Task and choose the created task --> The PD update is now synchronized with this task
  • You could now simply count the execution cycles to adjust the sampling rate. E.g. if you only want to sample the IO values every second, than only copy the values only after every tenth cycle


Br,
Frank
Phoenix Contact Electronics Headquarter - PLCnext Runtime Product Management and Support
  1. one week ago
  2. PLCnext Engineer
  3. # 1
lqplee Accepted Answer Pending Moderation
0
Votes
Undo
I use a counter to count the output of the timer. The timer is in 1s task and the PT for timer is 1000ms. I got about 17 count in one minute. When the timer is put into 500ms task, I got about 28 count in one minute. While the timer is in a 100ms task, I can get 49 timer switching on output. See the attached picture.
Should it be 60 switching on for a PT=1s timer in 60 secs?
The process values are from the Modbus Poll and the poll rate is between 500ms to 1s (Poll rate varies depending on if a write command is sent). With your reminding, I could use a "add" block to count the number of 100ms cycle. The only thing I have to do is to divide the sample rate (sample rate is a HMI parameter) by 100ms, then compare the result to the number of cycle to do sampling. Am I doing right here?
However, it raises the concern that the timer does not work accurate in PLC program.

Thanks
Jason
Attachments (1)
  1. one week ago
  2. PLCnext Engineer
  3. # 2
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo
The timer works accurately, and your results are as expected.
You should draw up a timing chart or table, showing the value of every variable in your picture at the start and end of every task cycle. Then you will see why you are getting these results.
In short, the logic in your picture is executed once every task cycle, from left to right. This includes the timer, which only adds a delta to the ET value once each task cycle, and only sets Q on the task cycles that ET >= PT and IN = TRUE.
Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. one week ago
  2. PLCnext Engineer
  3. # 3
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.