ADC Signal Averaging

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
CaDu_3933941
Level 4
Level 4
50 replies posted 25 replies posted 10 replies posted

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?

Thanks

0 Likes
1 Solution
lock attach
Attachments are accessible only for community members.

CaDu,

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.

pastedImage_0.png

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.

pastedImage_0.png

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

Len

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
23 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

CaDu,

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.

Len

Len
"Engineering is an Art. The Art of Compromise."

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

0 Likes

CaDu,

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.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Len,

Attached is a drawing of the overall system:

pastedImage_0.png

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

0 Likes
lock attach
Attachments are accessible only for community members.

CaDu,

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

/odissey1

TB6612fng.jpg

TI_low-side current sampling_01a.png

0 Likes

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?

0 Likes

CaDu,

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

http://www.ti.com/lit/ml/slyy154/slyy154.pdf 

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.

/odissey1

0 Likes

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.

0 Likes

CaDu,

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)

https://www.adafruit.com/product/1164

https://www.adafruit.com/product/904

0 Likes
lock attach
Attachments are accessible only for community members.

CaDu,

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.

pastedImage_0.png

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.

pastedImage_0.png

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

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

LePo,

I should mention that part of the purpose of this is also to estimate motor speed and attempt to implement close loop speed control (PID).

0 Likes

CaDu,

Motor current and RPM are not related! You need some encoder on the shaft.

/odissey1

0 Likes

Sorry for my limited knowledge on Brushed DC Motors, but I thought the motor speed and current related the following way

pastedImage_0.png

I understand that this would be a really rough reading, however, the reason why I am attempting sensorless speed monitoring is because the way the DC motor is enclosed in the body of the RC car which's speed I'm trying to control. Otherwise, I would have used an Encoder by now.

0 Likes

CaDu,

The equations you presented are in theory correct.  In summary the back-EMF VBEMF is primarily due to the load on the armature and the resistance of the armature coils.  What it doesn't account for very well is resistivity friction losses in the brushes, the change in armature resistance when the motor is running (heating effect) and other esoteric factors.

Therefore the estimation of speed is just that:  An estimation.  The question you must ask yourself is how accurate I do need to be?  If not much, this might be a reasonable method to a sensor-less approach to speed determination.  If you need a more accurate value,  you've always best off putting a tach sensor on one of the non-drive wheels of the RC car.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Accuracy is not priority (This is a personal project), so as long as the current read can tell me something about how fast the motor is rotating, then that would be fine. About the tachometer, I would still have to think about how I would attach it, I bought the RC car off of Amazon and the body is a little hard to work with.

For now, All I am worried about is a clean current signal that I can work with.

0 Likes

CaDu,

This YouTube video describes issues measuring motor current on H-bridge

Linear Technology - Precision Current Monitoring for Electric Motors and Solenoids - YouTube

-- use precision Opamp for shunt voltage measurements!

Honestly, measuring RPM is much simpler and reliable for PID control. For example a small magnet can be attached to the shaft or wheel, and small magnetic angle sensor will report digitized angle

Very simple way to drive BLDC only with encoder and MCU!!!!!! - YouTube

/odissey1

0 Likes

The sense opamp is an internal opamp from the PSoC.

0 Likes
odissey1
Level 9
Level 9
First comment on KBA 1000 replies posted 750 replies posted

CaDu,

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

/odissey1

0 Likes

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.

0 Likes

Ok,

What is PWM frequency?

0 Likes

Low-side current sense is a good solution.

Len,  V DAC has a high output impedance.  Bypass capacitor for v dac_ref is required?

I used a simple moving average Filter with an adjustable reinitialization threshold

and buffer size from 2 to 1024    VoltageDisplayMean41.zip.      The component is here.

You use PWM, then the threshold will have to be disabled.

odyssey1, is it possible to use your approach in the case of PWM?

Evgeniy

0 Likes

Evgeniy,

I've used low-side sense in the past.

Pros:

  • Design can use single-end inputs to ADC.
  • Maximum input voltage issues (Common-mode) are minimized.

Cons:

  • Motor current re-circulation is not monitored.  Therefore nullifying the PWM OFF effect on the sense reading might be important. For example a "Track and Hold" component can be helpful to stabilize the input when the PWM signal clocks it.  There are other techniques that can be employed.

Motor-leg sense:

Pros:

  • Motor current re-circulation is monitored.  This can help stabilize the current reading provide an averaged reading close to the true current.
  • A differential signal provides better immunity to Common mode issues that might be present with potential VSS bouncing.

Cons:

  • Maximum voltage limits need to be considered when directly interfacing to the 5V (or 3.3V) PSoC.

Using the VDAC with a cap to stabilize it is always a good idea.  However, the ADC vref input is fairly high-impedance. If the user wants to use the dithering VDAC, the cap may become mandatory.

Len

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Evgeniy,

>odyssey1, is it possible to use your approach in the case of PWM?

- The weighting window is a FIR filter averaging over 5-10 periods to cancel out effects of absence of sync between AC and ADC clock. It works OK for sine-like functions with small crest-factor (peak/average). For shortest PWM pulse spike, the crest-factor will be 256 (huge), leading to errors. Also averaging over 10 periods (10 * 256 / 5.8 kHz = 0.44Hz) makes feedback slow. Since PWM is generated locally, syncing ADC and PWM should be easy, and the current can be averaged per each PWM period. Probably, the Filter component can handle that if the current signal is slightly smoothed out in the analog path, e.g. LPF with Fc~1kHz, making ~50 effective samples per period, so that all ADC samples will fit Filter taps (~100).

/odissey1