ADC input error

Thread Starter

Col

Joined Apr 19, 2012
44
Hi,

I have a rectifier circuit which im using to measure an AC current via a hall sensor (ACS714). As I want to measure a simple DC I have a strong low pass filter, or rectifier (a series diode with a 10uF capacitance). I use a circuit as advised in the ACs714 data sheet (although I add an amplifier gain stage after the sensor before the rectifier. This sensor works well... until I arrive at the input of my microcontroller (STM32) ADC...

http://imageshack.us/photo/my-images/607/acs714appcircuit.png/

The (12bit) ADC seems to force a value of Vref/2 at the pin, and returns a sample of 0x0800. I have tested the ADC by applying voltage, via a potentiometer and it works fine.

Is there a problem with having the huge capacitance to ground at the input of the ADC or perhaps the diode? Any suggestions how I can sample my sensor voltage properly?

Tnx
 

ErnieM

Joined Apr 24, 2011
8,377
Hi,

I have a rectifier circuit which im using to measure an AC current via a hall sensor (ACS714). As I want to measure a simple DC I have a strong low pass filter, or rectifier (a series diode with a 10uF capacitance). I use a circuit as advised in the ACs714 data sheet (although I add an amplifier gain stage after the sensor before the rectifier. This sensor works well... until I arrive at the input of my microcontroller (STM32) ADC...



The (12bit) ADC seems to force a value of Vref/2 at the pin, and returns a sample of 0x0800. I have tested the ADC by applying voltage, via a potentiometer and it works fine.

Is there a problem with having the huge capacitance to ground at the input of the ADC or perhaps the diode? Any suggestions how I can sample my sensor voltage properly?

Tnx
If I understand the ACS714 device its output is a direct reflection of the input: you drive it with an AC and the output is also an AC. Hence the D1 and C1 you added to get the wave peak, looks like you were reading the Volume III on diodes & rects here.

That circuit you added may work in a simulator but I would not use it, as it has a very slow response to decreasing currents: there is no way to discharge that cap! So the first change is to add a resistor across it, the value would depend on "everything else," first the cap value it is across, and how fast you want it to respond. 10uF is huge to do this BTW.

The accuracy is very dependent on that diode as it will not be a fixed drop, so you may well want a better peak detector. Here's one I found:



If you use a nice rail to rail single supply op amp you don't need the 10K pullup on the first amp, and you don't need that 2nd amp at all.

Placing a large cap at the input of the A2D is fine, the A2D will still read the voltage correctly.

Now getting 0x8000 is a curious number. With your pot in place do you get readings above this or is your A2D "maxed out" when you read it?
 

Thread Starter

Col

Joined Apr 19, 2012
44
Thanks for your detailed reply.

Yes I played around with this precision rectifier circuit you suggested.... I'm measureing current at 50Hz, and I want to be able to sample my measured AC waveform, as well as AC switchon transients. This is why I've opted for a gain stage followed by this 'clumsy' rectifier. I just want a current level estimate and my loads will be all steady state.

Of course... a discharge resistor for the cap! I'll added a 200k resistor in parallel, should give me a 500ms time constant. Cheers :)
 

ErnieM

Joined Apr 24, 2011
8,377
With hindsight always being 20-20 I had another idea: any modern A2D will work much faster then a 50 (or 60) Hz AC wave so you may well be able to dump the peak detector entirely, as long as you synch your measurement to the AC line frequency.

I did such a synch connection once in a PIC project simply by connecting the AC line thru a 500K resistor directly to an input pin: the large resistor worked against the input protection diodes to limit the current to a small value, and the input signal was thus a square wave with changes that match the AC zero crossings.

Now that project was directly connected to the AC line thru signal and ground and I can't recommend doing that here due to our Terms Of Service (TOS) limits, so I will recommend using a small transformer to do this. You may already have that transformer to power your unit, or may need to add a very small transformer to get the isolation.

The basic scheme would be to get a change of input to fire an interrupt, which starts a timer to wait till mid-cycle, then that event fires off the A2D measurement. You could get true cycle by cycle measurements with no delay or lag between an event and your reading.

It will be quite helpful to have an oscilloscope to set this up. Keep a spare I/O pin handy and drive that high while making the A2D measurement. You can then look on the screen to adjust delays so the pulse matches the peak. Or, make a fixed current and adjust the delay till you get a maximum reading.

Cheers!
 

THE_RB

Joined Feb 11, 2008
5,438
I would use a third option; sample the current ADC at a high rate and just use an algorithm to extract the data you want.

If you want the peak current then sample (say) 100 times per 50Hz cycle, then take the 20 consecutive samples which are the largest. That will be the "peak" 20% portion of the cycle.

In essence that algorithm also performs the 50Hz sync as part of its operation.

Algorithm can be something like this, sampling 100 times per cycle;
1. average new sample with the 19 previous samples (is avg of 20 samples)
2. if average is larger than the largest average in the last 80 tests; record it as the new "largest average"
3. if average is very small, assume the cycle is done and save the largest average that was found
(will repeat and auto sync each cycle)
 
Top