# Filtering Requirements for ADC on PIC32MX

Discussion in 'Embedded Systems and Microcontrollers' started by jegues, Sep 4, 2013.

1. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
45
Evening gents,

I'm trying to figure out the appropriate filtering requirements for a signal at the input of the ADC for the PIC32MX795F512L.

The input signal of the ADC will be from obtained the output signal of a hall effect sensor. I've attached the datasheet of the hall effect sensor we will be for using for this particular application. Please note the 2.5V bias for a 0A signal.

The expected range for the current measured by the sensor is between 0 - 300A with 100A being the nominal target value. (Assume unidirectional current flow)

I've been reading through the PIC32 ADC reference manual, and from my research so far, the ADC total sample time is simply the addition of its acquisition time and its conversion time.

The acquisition time being,

$T_{acq} = \text{SAMC }*T_{AD}$

while the conversion time is,

$T_{conv} = 12*T_{AD}$

Where the SAMC ranges from a integer value of 1 to 32 and TAD is the period of the ADC clock cycle. (which is from the internal RC oscillator)

If we assume a worst case TAD of 6μs, the only thing left that we have control over is the integer value of the SAMC. So how does one go about deciding on an appropriate sample time?

I figured once I knew my maximum sampling frequency for the ADC I could then use Nyquists theorem to determine the appropriate cut off frequency for a LPF to prevent the input signal from aliasing the output of the ADC.

Finally, since the analog inputs on the PIC only have a safe operating range from 0 to 3.3V, the voltage signal from the hall effect sensor must also be altered and limited accordingly to prevent damage to the PIC.

My thoughts for solving the requirements above was to use something like the following. (See analog design note attached)

With this sort of arrangement I could use the two-op-amp instrumentation amplifier to remove the 2.5V bias from the hall effect sensor(by setting one of the second op-amp input to 2.5V), and set the gain accordingly to achieve 3.3V output at the maximum sensor current of 300A. Furthermore, the single supply for the op-amp A3 could be set to 3.3V, effectively clipping its output at a safe level regardless of how large of a signal swing seen at its input. Additionally, the 2nd order low-pass filter could then be tuned to my maximum sampling frequency to prevent aliasing.

What do you guys think? I've tried simulating the circuit shown in the attached design note but I've had limited success.

Perhaps once we figure out a practical maximum sampling frequency for the ADC, and focus in on the appropriate filtering and signal conditioning required we can then focus on simulating and reworking the circuit found in the analog design note.

Thanks for all the help!

File size:
463.3 KB
Views:
28
File size:
113.6 KB
Views:
20
2. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,943
1,816
Rather than base the filter on the theoretical max sampling frequency (which may leave you zero time to actually process the signal) base it on the signal you are measuring.

What is the source of this current you are measuring? How fast does it change?

Base the filter on that requirement... and it also tells you how fast you need to sample the signal.

(Have to go now, will try to check the PIC32 ADC ref manual later; can't answer anything without a fresh read: too many details!)

3. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
45
Hi ErnieM!

The current we're measuring is for a DC motor controller application.

We're actually going to be using two channels on the ADC. One channel has a user controlled potentiometer that will be used to control the duty cycle of the PWM waveform, the other channel will have the feedback from the motor via the hall effect sensor. Using both channels, (desired signal & actual signal) we can see how well the motor is following the users commands.

The current from the potentiometer shouldn't be changing drastically in any short amount of time (i.e. >1ms?), as it will be controlled and changed by the hands of a human. As for the feedback from the motor, I'm unable to tell you how fast the feedback signal from the motor will be changing. (I haven't had the chance to measure it under operation) Regardless, I would think that you wouldn't want rapid fluctuations in the feedback signal to be processed anyways as they could cause erratic behavior in the motor. You wouldn't want to consider these rapid fluctuations when comparing the actual signal with the desired signal. You'd definitely want to smooth out the actual signal before comparing it to the desired signal.

I hope this makes things more clear. I look forward to hearing from you!

Thanks again!

Last edited: Sep 5, 2013
4. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,943
1,816
If your signal gets sampled at that 1 us (1KHz) rate then you need a filter cutoff well below that frequency to keep artifacts out of the measurement.

Can you post a link to the PIC32 ref manual you are using? I did a quick look at lunch but did not find what I wanted. If you check say the PIC18F4550, section 21.1 data sheet they have all the information on calculating a minimum required acquisition time... I could not find most of those parameters in the pic32 data sheet. They have tobe out there, I just have not located them yet.

5. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,943
1,816
I just noticed that table 31-37 of the data sheet gives a fixed minimum sampling time for these devices... Someone in tech support must have clued the data sheet guys to just cut to the chase.

6. ### jegues Thread Starter Well-Known Member

Sep 13, 2010
735
45
Hi ErnieM!

Wow! Thanks for finding that for me, that should surely simplify things for me!

You mention a signal being sampled "at that 1 us (1kHz) rate". Where did this come from?

Are you telling me that based on the source of the current described, and how fast it would change, a 1kHz sampling rate would be good enough?

I was told by another engineer that as long as the controller can react and adjust itself in any time frame less than ~10ms, it should be relatively unnoticeable for the human controlling the motor. If this is true, then we should be able to cook up a fast enough sampling frequency to easily meet this requirement.

As for the filtering, I'll probably tune the cut off frequency for the LPF at a fifth of the maximum sampling frequency of the ADC. This should be well under the theoretical limit determined by Nyquists theorem. (This would be a half the sampling frequency) This would ensure anti-aliasing.

Have you had any time to look at my proposal regarding the two op-amp instrumentation amplifier followed by the 2nd order LPF? Check the design note I posted in the original post. Does this circuit look like it could be fitted to suit my particular application?

Thanks again for all you help! I look forward to hearing from you.

7. ### ErnieM AAC Fanatic!

Apr 24, 2011
7,943
1,816
1 us is a typo. It should be 1 ms as you said.