# Interfacing low AC voltage to A/D on PIC IC

#### wellyboot

Joined Jun 1, 2005
16
I have been looking into designing a project that uses a hall effect sensor to measure AC current, (50hz 240v mains AC)
the sensor i have got is CSLA2CD

and has the following datasheet:
http://pdf1.alldatasheet.com/datashe...C/CSLA2CD.html

the sensor can measure upto 72Amps, and has a linear output that will basically track the input waveform eg. AC voltage output
the device outputs half the supply voltage at 0amps, and the output range is 25-75% of the supply voltage.

The range of current i wish to measure is 0 - 50amps

I think the easier solution is to convert the AC voltage to a DC level

Does anyone have a circuit diagram that can inferface the sensor with the A/D input of a PIC eg PIC16F872?

Thanks
Dave

#### beenthere

Joined Apr 20, 2004
15,819
You don't state the supply voltage, but if it's less than the upper limit for the ADC in the PIC, you can just convert it as is. Use the PIC and a look-up table to convert to engineering units.

#### kender

Joined Jan 17, 2007
264
I think the easier solution is to convert the AC voltage to a DC level
Quick & dirty solution (which has a serious limitation, which can be mitigated):
- AC-couple the output of your sensor with a series capacitor.
- Run the AC-coupled voltage through a rectifier, which will (depending on the rectifier topology: full- or half-wave) cut off or invert the negative side of the AC. The signal becomes DC again
- Filter the output of the rectifier with capacitor to ground.
- A/D

But the limitation is that the diodes in the rectifier don’t start conduction at 0V. If the diodes are Si, they will start conducting at 0.7V. If they are schottkys, they will start conducting at least at 0.3V. So, with this simple approach there will be a minimum current corresponding to 0.3V, below which you will not be able to measure (you’ll get zer0).

What can eliminate this limitation is an OpAmp precision rectifier. Take a look here:
http://sound.westhost.com/appnotes/an001.htm
http://en.wikipedia.org/wiki/Precision_rectifier

#### wellyboot

Joined Jun 1, 2005
16
Thanks for the advice, Im looking at trying out the precision rectifier idea

#### kender

Joined Jan 17, 2007
264
or heres another approach, which requires less hardware but more firmware

- AC-couple the output of your sensor with a series capacitor.
- Run the AC-coupled voltage through a half-wave rectifier. The signal becomes almost DC again. Almost, because the level between the humps is -0.7V, but that doesnt matter, because its negative.
- Connect the output of the rectifier to the PICs A/D. The signal is slightly negative, but the A/D will tolerate it and give you zer0, when the input is negative. Effectively, your A/D will play a role of a precision rectifier.

You know that the waveform coming into the A/D is a half-wave rectified sine. Sample and integrate in firmware over one hump *,***. Knowing the frequency of the sine** and the integral over half-period, you can calculate everything else.

--------------------------
* You dont need to be looking for precisely 1 hump. You can integrate between ½ period and 1 period.
** If you detect the beginning and the end of the hump, you will know the frequency too.
*** You could also look for a max measurement. That would, probably, be less precise but it would require less firmware and math.

#### wellyboot

Joined Jun 1, 2005
16
The only trouble is im not to clued up on the programming side, i use picbasic pro ADCIN command to read the A/D pin and work from there.

I have now built a precision full wave rectifier, figure 6 on the following link:
http://sound.westhost.com/appnotes/an001.htm

I have conected my sensor via a coupling cap to the input, im using 2x 6v batterys to make a split rail power supply: +6v - GND - -6v, the diodes im using are 1n5817 schottkys, all resistors have 1% tollerence, ive built the circuit on plain strip board (no copper strips)

ive done a test on the circuit with the sensor outputing 400mv AC 50hz
the output of the circuit is about 350mv DC but the output starts to rise upto 3.5v DC and drops back down to 350mv, and repeats this every couple of seconds. i could only measure these values with a digital multimeter as i have no scope to check the waveforms, my meter can measure frequency and i do have 100hz at the o/p with no smoothing cap conected.

Any ideas where its going wrong?