
adccommunitymod (AutomationDirect) asked a question.
Created Date: August 01,2019
Created By: DavidH
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
Before I begin, I have uploaded a video here on YouTube that shows my problem and what I'm trying to do(I vary the signal to different voltages a couple of times): https://youtu.be/BJN3y4lsw_E I currently have a voltage simulator hooked up to the analog input of the Click PLC to simulate a sensor signal (0-1V) to represent a total scale of 0-4095(so this gives me a resolution of 1 in the PLC). I need to convert this value to a percent, which seems to be working. However, the signal seems to be a little jumpy. When I check with a digital multimeter it appears to be fine. I need the percent value to be stable at least to 1 decimal place and not jump all over the place. So I decided to try to implement a first order filter, and it doesn't seem to do much of anything. The formula I'm trying to follow is equation #6 found here: http://automationprimer.com/2016/03/12/ladder-logic-402-data-manipulation-and-filtering/ As you can see in the video, the Filtered Value and Filtered Percent are still not very stable. I even tried to play with the dampening factor to no success. Is there a different approach that I can take to this? I can't present a reading onto an HMI that is jumping all over the place like this. Thanks.
Created Date: August 01,2019
Created by: DavidH
Before I begin, I have uploaded a video here on YouTube that shows my problem and what I'm trying to do(I vary the signal to different voltages a couple of times):
https://youtu.be/BJN3y4lsw_E
I currently have a voltage simulator hooked up to the analog input of the Click PLC to simulate a sensor signal (0-1V) to represent a total scale of 0-4095(so this gives me a resolution of 1 in the PLC). I need to convert this value to a percent, which seems to be working. However, the signal seems to be a little jumpy. When I check with a digital multimeter it appears to be fine. I need the percent value to be stable at least to 1 decimal place and not jump all over the place.
So I decided to try to implement a first order filter, and it doesn't seem to do much of anything. The formula I'm trying to follow is equation #6 found here:
http://automationprimer.com/2016/03/12/ladder-logic-402-data-manipulation-and-filtering/
As you can see in the video, the Filtered Value and Filtered Percent are still not very stable. I even tried to play with the dampening factor to no success.
Is there a different approach that I can take to this? I can't present a reading onto an HMI that is jumping all over the place like this.
Thanks.
Created Date: August 01,2019
Created by: Adisharr
You can try using a rolling average. That should make things more stable. Try averaging 10 values, shift DS1 through DS9 one word down (DS2-DS10) then store live reading in DS1. Sum(DS1-10)/10 and store in another variable.
Created Date: August 01,2019
Created by: Garry
+1 Adisharr
Here is a quick ladder logic of the average.
{ "data-align ": "none ", "data-size ": "full ", "title ": "Average Analog Input Sample.png ", "data-attachmentid ":124388}
Regards,
Garry
Created Date: August 01,2019
Created by: Todd Dice
If someone at AD sees this thread, I think a "PLC code for analog filtering " would be a good adder to THIS PAGE .
Created Date: August 01,2019
Created by: Bolt
Here's how I filter my inputs in a Click PLC.
How do you do it?
Hi petevin,
I hope it helps you out.
Regards,
Garry
https://accautomation.ca/series/click-plc/
Average Analog Input Sample
Created Date: August 01,2019
Created by: Tinker
David, You might want to use an edge contact on that SC7 (like Garry did) SC7 is not a single scan pulse once a second, it is a 50% duty cycle square wave. Since your demo program is short the scan time could maybe be as low as a millisecond, (possibly 50 times faster that the ADC conversion time) so, once a second, for the first half a second you math is done perhaps 500 times (with perhaps only 10 separate input readings), then for the second half second you pause. Seem to me you'd want to do the math only once a second.
I assume this is a personal project. if someone else is paying you for your time I'd recommend a D0-More BRX which has built in filtering and a faster ADC allowing more aggressive noise filtering while still having reasonable response time (unless it is a high volume project where hardware cost would be more than development cost)
Created Date: August 01,2019
Created by: DavidH
You can try using a rolling average. That should make things more stable. Try averaging 10 values, shift DS1 through DS9 one word down (DS2-DS10) then store live reading in DS1. Sum(DS1-10)/10 and store in another variable.
+1 Adisharr
Here is a quick ladder logic of the average.
{ "alt ": "Click image for larger version Name:\tAverage Analog Input Sample.png Views:\t0 Size:\t21.6 KB ID:\t124388 ", "data-align ": "none ", "data-attachmentid ": "124388 ", "data-size ": "full ", "title ": "Average Analog Input Sample.png "}
Regards,
Garry
Thanks to both of you guys. I just got a chance to play with the code and the results look much better. I was looking at a moving average initially, but most people always seem to suggest a first order filter. I'm still new to the world of CLICK PLC programing, but I learned a lot from the example you posted.
Here's how I filter my inputs in a Click PLC.
Thanks for posting that. I'll definitely try your method also and see what the results are like.
David, You might want to use an edge contact on that SC7 (like Garry did) SC7 is not a single scan pulse once a second, it is a 50% duty cycle square wave. Since your demo program is short the scan time could maybe be as low as a millisecond, (possibly 50 times faster that the ADC conversion time) so, once a second, for the first half a second you math is done perhaps 500 times (with perhaps only 10 separate input readings), then for the second half second you pause. Seem to me you'd want to do the math only once a second.
I assume this is a personal project. if someone else is paying you for your time I'd recommend a D0-More BRX which has built in filtering and a faster ADC allowing more aggressive noise filtering while still having reasonable response time (unless it is a high volume project where hardware cost would be more than development cost)
Thanks for your suggestion there. Optimizing the code is definitely more critical as the program grows. With regards to what I'm trying to do right now, it's still in the proof of concept stage. I was initially looking at the Do-More BRX series(especially given its more robust features), but the CLICK seems to have everything I need right now and you can't go wrong with the price. If some of the more advanced instruction sets were available on the CLICK that would be the icing on the cake(hint hint to anybody from Automation Direct that is reading this). At any rate I will continue to play around and develop with CLICK and see where it goes.
Created Date: August 03,2019
Created by: Todd Dice
This post has very helpful in an application I'm doing right now. Thanks for asking it.