Automation Studio: Store sensor values for 5 seconds and extract minimum value

afm

Member
Join Date
Aug 2023
Location
Tennessee
Posts
88
Hi all,

I am working with an IO link sensor (measuring current across motor)and need to read in and store the sensor values for 5 seconds, then extract the minimum value from the data set. I am a beginner in ladder programming and automation studio and have only used the MOVE block for array storage, but not for a sensor with constantly changing values. I know there is probably a very straightforward solution, but any help is appreciated. Thanks!
 
How many readings in the 5 seconds do you need ? is it every scan? if so then at a scan time of 20ms that would be 250 registers or tags or array of 250.
It certainly is going to take some processor time to extract the lowest because you will have to itterate through the array to find it, then for that instance it will increase you scan time, The other way is to do it on a change, so you store the value then compare the current value with the last if it is lower then store that, just keep doing this for 5 seconds before resetting it.
so in the 5 seconds it will have the lowest value in that 5 seconds but check every scan without any hungry processing.
However, you will almost certainly need to put a delay timer on the logic when the motor is first energised as the PLC will scan faster than the contactor will pull in so initially you would have 0 as your lowest number so there can be no lower number.
I suggest on start of the motor you do a oneshot to load perhaps what would be the highest reading into the lowest store variable, run a timer off the output for the motor to start a timer & use the timer up bit to enable the comparison. run a reciprocating timer for the 5 seconds i.e. it gives a one scan pulse every 5 seconds.
 
Last edited:
Is there some reason you need to store data for five seconds, or do you just need to find the lowest value within a five second period?

If the latter is sufficient, just initialize the result with the present value at the beginning of the time period and while the timer is running, if the value is lower than the result, move it to the result.
 
Hi,

Thank you for your response. I have a delay timer so that my program doesn't start until the motor has been running for 3 seconds. Once those 3 seconds are done, I want to do the 5 second scan to determine the minimum sensor value.

I just need to establish the minimum during the first few seconds bc the linkage system my motor is driving will repeat the values every cycle. My program is used to determine when a user is putting in work/effort into the system because you will see a live drop in the sensor value. So I want to use the minimum sensor value I found at the beginning to compare to the live sensor value (if LiveValue < MinValue then work was done to the system).

I tried out one method I had seen someone use in a similar application to extract mins and maxes from analog sensors. The sensor values range from 4-20 mA, so I initialized the Max to be 4 and Min to be 20, then compare the live value to it to update for the first 5 seconds. After the 5 s is complete, I want to use the establish minimum to compare against the live reading. However, my Live sensor value overrides the Min value and ignores the logic. I can add videos if needed for clarification. Thank you!
 
Last edited:

The questions are,

  • Does OP want the displayed minimum value
    • to represent the previous 5s.
    • and to be updated on every scan
    • i.e. available at every scan once an initial 5s have expired?
  • OR is it enough to collect the data for 5s, and
    • only update the displayed minimum once every 5s
    • i.e. at the end of that 5s of data collection?
The former requires an entire array of N stored data samples to be checked every scan cycle, with N comparisons every scan cycle;

The latter does not require an array of stored data samples and instead requires but a single value storing the minimum value since the start of each 5s period, and executes only one comparison per scan cycle.
 
is there some reason you need to store data for five seconds, or do you just need to find the lowest value within a five second period?

If the latter is sufficient, just initialize the result with the present value at the beginning of the time period and while the timer is running, if the value is lower than the result, move it to the result.




+1
 
Hi all,

After I start my motor (after a short delay for it to ramp up), I want to determine the minimum value my sensor displays in the first few seconds because the system naturally has some fluctuation. I only need to to this once at the beginning of my motor startup. I will use this same value the entire time to compare my live readings to it.

I will only need to update this value once the motor has been turned off and then turned back on.
 
This is one (of many) ways to implement what @OkiePC is suggesting.

Caveats

  • Automation Studio (A-S) will have different syntax for the operands and the instructions, of course.
  • if A-S does not allow access to the TON accumulator then this approach will need two timers
    • 3s TON cascading to a 5s TON
Untitled.png
 
If A-S does not let the program access the accumulating time, cascading two timers can be used to accomplish the same result:
Untitled.png
 
Thank you for this. I have 2 questions before I try this out.

1) do I need to intialize the minimum sensor value before starting this?

2) I am currently not storing any values in an array, do I need to do that? Is that is what is causing my Live sensor value to override my other variables that are trying to store the minimum?

Thanks.
 
Thank you for this. I have 2 questions before I try this out.

1) do I need to intialize the minimum sensor value before starting this?

2) I am currently not storing any values in an array, do I need to do that? Is that is what is causing my Live sensor value to override my other variables that are trying to store the minimum?

Thanks.


The examples in posts 8 and 9 have the value initialized with the MOV instruction that takes the analog input (I:0.4) and puts it into a holding register (N7:0) while the motor is starting. Once the delay period ends, it only stores the analog input if it is less than the stored value. Basically, N7:0 will be initialized with whatever the input is at the end of the delay time (or, actually, to be pedantic, one PLC scan before the delay time ends).


If you only care about the minimum value, I wouldn't bother with saving values in an array.
 
[Update: @joseph_e2 said it better]


Thank you for this. I have 2 questions before I try this out.

1) do I need to intialize the minimum sensor value before starting this?

2.i) I am currently not storing any values in an array, do I need to do that?

2.ii) Is that is what is causing my Live sensor value to override my other variables that are trying to store the minimum?

Thanks.

1) No, this logic initializes the minimum value at* the start of the 5s sampling period.

2.i) No.

2.ii) I don't know what your existing code is doing as you have not posted it.

* actually 1ms or 1 scan cycle before, but that should not matter as I suspect the 3s and 5s are "soft" numbers.
 
Thank you. These are the images for how the sensor is read in, another engineer recommended I use this method to bit shift. (RealSensorValue is our live current value)

https://ibb.co/X4t3kZf
https://ibb.co/S3dNN8V

This is the current logic I was using. Even when the LT condition was not true, my RealSensorValue was overriding the MinSensorValue. (RunEffortProgram is my 3 s delay on motor earlier in logic)
https://ibb.co/5K0KRN0
 
Thank you. These are the images for how the sensor is read in, another engineer recommended I use this method to bit shift. (RealSensorValue is our live current value)

https://ibb.co/X4t3kZf
https://ibb.co/S3dNN8V

This is the current logic I was using. Even when the LT condition was not true, my RealSensorValue was overriding the MinSensorValue. (RunEffortProgram is my 3 s delay on motor earlier in logic)
https://ibb.co/5K0KRN0

Yes, because the input rung to the MOVE instruction on rung 0014 is true, so whether the LT instruction evaluates to True is completely irrelevant.

Solution: look at @joseph_e2's comment about my code, and look at my code, to see how I ensure that the MinSensorValue is not unconditionally overwritten once the while the 5s MinTimer is timing i.e. while RunEffortProgrm is 1 and MinTimer.Q is 0.

Quickest solution, starting from what you have:

  • Rung 0014, top branch: insert a one-shot (pulse) just after the branch point and before the MOVE.
Better solution:

  • Rung 0014: remove the bottom branch of Rung 0014
  • Rung 0014: change the [NOcontact MinTimer.IN] to [NCcontact MinTimer.IN]
  • Rung 0015: change the [NOcontact MinSensorValueSearch] to [NCcontact MinTimer.Q]
  • Rung 0013: move this entire rung to after current rung 0015
    • PLC programming is primarily about time, and the scan cycle is the primary clock; the secondary clock comprises rules for the order of execution of rungs and instructions.
      • Thinking about and being aware of when something happens is more important than what is happening.
I strongly suggest you try both solutions, and try to understand why they work.

Also consider that the reason your code did not work, and you did not know why, was that you had two MOVE instructions that could be writing the value of RealSensorValue into MinSensorValue, and you had no idea which one was doing the writing; note that my code has only one such MOVe instruction, so I am able to control, with an iron fist ;), when it does and does not overwrite MinSensorValue.
 
Last edited:

Similar Topics

Hi, I have been trying to run drive via Sysmac studio. I can ping the drive. I can see the logic bits going on/off as per command. But, drive is...
Replies
21
Views
571
Hello Experts, I recently stumbled with an issue about ABB VFD ACS800 connected with B&R PLC X20CP1484-1. This ABB VFD ACS800 somehow got...
Replies
0
Views
325
Hi, I would like to prepare a project for the operator panel and I do it like this: New project -> I choose the appropriate panel -> add object ->...
Replies
0
Views
428
Hi, I would like to prepare a project for the operator panel and I do it like this: New project -> I choose the appropriate panel, it seems to me...
Replies
3
Views
640
Hi all, I am working on a ladder program in AS and I was to trigger a reading on my IO link sensor every .5 s, and use that value to run a...
Replies
1
Views
542
Back
Top Bottom