1 2 Previous Next 23 Replies Latest reply on Jan 7, 2020 1:25 PM by BoTa_264741

    ADC Signal Averaging


      Hi all,


      I am currently working on a sensorless Brushed DC motor speed monitoring. For this, I am using a current sense amplifier and feeding it into an ADC.


      Considering the current is a ripple waveform, I figured the best way to read this current is to calculate an average value.


      Would anyone have any idea on how to do this?



        • 1. Re: ADC Signal Averaging



          I've created Brush Motor control designs in my professional career.  To smooth out the motor currents, I implemented a "windowed" average scheme.  The "window" in effect is averaging the last 'n' readings.


          One way to create a "windowed" average in SW is to create a circular RAM buffer of 'n' samples. The buffer is continuously updated from the ADC and the oldest samples ('n+1' or more) are overwritten.  You can then determine how often to add all the samples in the buffer and then divide by 'n' for your "windowed" average.


          There are some potential disadvantages of this scheme to consider.

          • It is common  to create sample counter reset to zero. When you start your motor and gain you new samples the sample counter increments until 'n'.  When you perform your averaging, you add all values in the buffer and divide by the number of the sample count.  This is to prevent a falsely lower reading because you haven't filled all the buffer with real values yet.  Once you have 'n' samples, the sample counter remains at 'n'.
          • Because you are eventually taking 'n' samples for the average, there  is the time latency if you are making certain decisions in SW on this average value.  The latency is about 'n' * the sample rate.  There are multiple techniques to reduce the latency.
            One way is to create a smaller "windowed" averager within the larger one ('m' where 'm' < 'n').  This average on the latest samples will detect variances sooner.
            Another way is to set a lower and/or higher delta threshold above and below the current average.  If the latest sample falls over/under the average + threshold, you do something in your SW.  An example of using this technique is sensing if an obstacle can be detected in the path of the mechanism the motor is driving.


          I hope this answers some of your questions.



          1 of 1 people found this helpful
          • 2. Re: ADC Signal Averaging


            I haven't worked with motors. Can you describe what are the requirements, e.g. ripple frequency, current feedback rate, etc.?


            • 3. Re: ADC Signal Averaging

              Thanks for the detailed answer!

              Let me just try to explain what you said to see if I understand correctly:


              You are saying to create a buffer of n samples, each one will be replaced by the incoming sample and then the next one so on and so fort until you reach the max number of samples within that buffer, then you perform the calculation of the average correct?


              If this is the case, I am having a little trouble trying to understand how to populate a buffer with whatever new ADC value that came in. How would you do this? Would you set up an interrupt for every time a conversion is made?


              One method I was previously trying is the following:


              I am averaging the samples for a set window of time, this window is determined by the frequency of the PWM with which I am driving the motor. The way I was trying to do this is the following:


              I set up an interrupt for a terminal count of the PWM block, this interrupt would the tell the main C to perform the average calculation of the current, spit out the value, and then clear said interrupt.


              For some reason, this did not work for me.


              I will try your method though (If my explanation made sense).

              • 4. Re: ADC Signal Averaging

                There are no specific requirements, however from my understanding, it should depend on a bunch of factors (motor speed and PWM frequency).


                All I am trying to do is perform a calculation of the average current flowing through the motor.

                • 5. Re: ADC Signal Averaging


                  What is PWM frequency?

                  • 6. Re: ADC Signal Averaging



                    I am averaging the samples for a set window of time, this window is determined by the frequency of the PWM with which I am driving the motor. The way I was trying to do this is the following:

                    It appears you are performing a form of "windowed" averaging.  PWMing the motor control does present some complication to the motor current measurement.


                    Can you share your motor drive circuit?

                    What is your target PWM frequency?

                    What is your maximum operational voltage?

                    What is the stall current of your motor at the maximum operational voltage?


                    Answering these questions may help me to construct a reliable motor control circuit.


                    It is possible depending on circuit for the current sense that measuring the current when the PWM is OFF,  you will measure near zero current.  Averaging this portion of "PWM OFF" current will skew your averages lower.



                    • 7. Re: ADC Signal Averaging



                      Attached is a drawing of the overall system:

                      Adc and Bdc are just flat DC voltages that remain constant to drive upper switches while the lower ones are being driven by PWM.


                      The stall current of the motor (For 7V which is the max operating voltage) is of 0.39A.


                      PWM Frequency = 5.8 KHz

                      • 8. Re: ADC Signal Averaging

                        The sense opamp is an internal opamp from the PSoC.

                        • 9. Re: ADC Signal Averaging


                          For low-voltage / low current app, I recommend ready-to-use motor driver, such as TB6612fng. It is inexpensive and available from multiple sources. I think that current averaging (PWM) should be done in analog (e.g. diff Amp followed by Multiple Feedback 2-nd order LP filter with Fc ~ 100 Hz). The driver losses are small, I would put sensing resistor before driver to minimize noise (otherwise it jumps from high side to low side). Since PSoC pins are limited to <Vdda, there might be an issue using internal Opams for a high-side measurement. Maybe current can be measured on the low-side of the driver instead (see attached AN)? The best would be using one of INA161, etc



                          TI_low-side current sampling_01a.png

                          • 10. Re: ADC Signal Averaging

                            I meant to display it on my drawing but the differential opamp is being offset using a VDAC and a follower opamp (Offset to 1.024V).


                            About Analog averaging, why set the cutoff to 100 Hz? Also would it jut be a passive LPF or an active one?

                            • 11. Re: ADC Signal Averaging


                              I am not expert in analog. Please refer to this TI annotation note


                              I suspect that signals will be weak in presence of the switching noise. There are special Opamps from TI with built-it shunt and very high CMRR (130-160dB) for this purpose.


                              • 12. Re: ADC Signal Averaging

                                The problem with an RC filter is that it would require a huge time constant to the point that it would be too slow to read the average value.

                                • 13. Re: ADC Signal Averaging


                                  This App Note should be helpful.

                                  Maximintegrated: High-Side Current-Sense Measurement: Circuits And Principles


                                  Adafruit analog and I2C high-side current sensors (and low $ on eBay / Ali)



                                  • 14. Re: ADC Signal Averaging



                                    The high-side current sense amps suggested by /odissey1 minimize this offset error and are differential input which is a very good thing.


                                    Thanks for the drawing.  It is missing some information for me to advice you.  For example: You mentioned the stall current at 7V is 0.39A.  It must be a small motor.  What is the value of Rsense?


                                    Suggestion:  If you can tolerate a loss of 0.4V in voltage to the motor, you can have Rsense = 1 ohm.  At 0.4A full-scale, you will get a 0.4V drop across Rsense.  At 0.4V full-scale, this is enough voltage signal above the noise floor. Because Rsense (in your drawing) is inline with the motor, V1 or V7 could be as high as 7V.  You would need to use an external opamp with 7V as its VDD or you would need to scale V1 and V7 to guarantee V1 or V7 ever exceeds 5V if you want to eliminate the external opamp and go directly into the PSoC.

                                    Another suggestion is to place Rsense in the GND leg path.  This removes the possibility for the voltages to exceed 1V and eliminates two resistors.  It also allows the ADC to be single-ended.


                                    Attached is a copy of the above schematics for your review.




                                    1 2 Previous Next