Announcement

Collapse
No announcement yet.

How To Smooth Analog Input Signal Via Filtering

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts


  • How To Smooth Analog Input Signal Via Filtering

    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/...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.

    Attached Files


  • #2
    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.

    Comment



    • #3
      +1 Adisharr
      Here is a quick ladder logic of the average.
      Click image for larger version

Name:	Average Analog Input Sample.png
Views:	120
Size:	21.6 KB
ID:	124388

      Regards,
      Garry

      Comment



      • #4
        If someone at AD sees this thread, I think a "PLC code for analog filtering" would be a good adder to THIS PAGE.
        Last edited by Todd Dice; 08-01-2019, 06:42 PM.
        Why worry? If you've done the best you can, worrying won't make it any better

        - Walt Disney

        Comment



        • #5
          Here's how I filter my inputs in a Click PLC.
          Attached Files

          Comment



          • #6
            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)

            Comment



            • #7
              Originally posted by Adisharr View Post
              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.
              Originally posted by Garry View Post
              +1 Adisharr

              Originally posted by Garry View Post
              Here is a quick ladder logic of the average.
              Click image for larger version  Name:	Average Analog Input Sample.png Views:	0 Size:	21.6 KB ID:	124388
              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.


              Originally posted by Bolt View Post
              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.


              Originally posted by Tinker View Post
              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.

              Originally posted by Tinker View Post
              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.

              Comment



              • #8
                This post has very helpful in an application I'm doing right now. Thanks for asking it.
                Why worry? If you've done the best you can, worrying won't make it any better

                - Walt Disney

                Comment



                • #9
                  Originally posted by DavidH View Post
                  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.[/LEFT]
                  CLICK is exactly what ADC wants it to be to cater to the users they targeted with it. To add more to it is to increase the complexity and associated support cost. It is absolutely unbeatable for what it was designed for, but once you get outside that, you will quickly give the savings back many times over. You can burn through $100-$150 in development time in a blink.

                  Comment

                  Working...
                  X