Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
fleemy
PostPosted: Jun 30, 2007 - 11:53 AM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Hi, I am trying to interface the ACS712 Hall Effect current sensor from Allegro. It's a nice little chip with some neat features like; output voltage proportional to AC or DC currents, very stable output voltage offset, ratiometric output from supply voltage.

As far as to interface the sensor with DC currents, there nothing much to it, just sample the output subtract the 2.5V offset and multiply the difference with the output gain.

But it's a different ball game when measuring AC(50Hz in my case) currents, the output follows nicely the AC sine current but the 'zero crossing' is at the offset voltage (+2.5V).

Now my question, how can I synchronize the ADC sampling to read peak current, and in mean time to read or count the frequency?

I tested the sensor with the scope and a AC voltage meter, and the sensor is working fine. I get a nice sine wave on the scope when there's AC current flowing and on the voltage meter I can read in AC millivolts the peak current.

So the sensor is working, but I am wondering will I need some additional hardware to read AC current or could I implement it in software to measure the peak AC current and the frequency?

Marc.

Edit, removed some typo's.


Last edited by fleemy on Jun 30, 2007 - 07:31 PM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
zauberer
PostPosted: Jun 30, 2007 - 04:07 PM
Resident


Joined: Mar 06, 2001
Posts: 552
Location: Moscow

To mesure peak current you need diode and capacitor,
to measure frequency you need resistor devider and AVR internal comparator.
Alexander.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
ka7ehk
PostPosted: Jun 30, 2007 - 06:12 PM
10k+ Postman


Joined: Nov 22, 2002
Posts: 12035
Location: Tangent, OR, USA

Whoa. Just sample with the ADC fast enough (say 10X the sine frequency or higher). You can find peak points pretty easy. Zero crossings are pretty simple also. Just look for one reading on one side of zero and the next on the other side of zero; if you need more accuracy, just interpolate. No need for diodes, R or C.

Jim
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jun 30, 2007 - 07:20 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21248
Location: Orlando Florida

This job can be done in the analog domain or the digital domain using the algo Jim has suggested. Need some specs tho... what is the max current? how small a difference do you want to see? Example... you hang this gizmo on the incoming ac that can supply 10kw and you want to see when you plug and unplug a 1 watt wall wart in the computer room? Need 1 part in 10 thousand... 14 bit a/d. But you might not need that extreme resolution.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
fleemy
PostPosted: Jun 30, 2007 - 07:38 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Alexander thanks for the answer, if figured something like that but I prefer a software method.

Bob, I am using the +/-5A optimized current sensor (max 10A), maybe in the future I’ll need the +/-20A sensor. The lowest reading (it’s more used as a part fail detector) is 10W and the max will be 1500W with a 220V AC supply.

Thanks Jim, that’s what I think I am gone to use.

So to calculate the period I need to subtract the time(r) values from the successive highest and lowest ADC readings multiplied by two? So I need a ‘time stamp’ from the ADC readings to calculate the period?

Wouldn’t the use of the comparator be simpler in that case?

I just started to read the documentation on the comparator trigger function for TIMER1. I guess I can use this function to trigger the timer and then calculate the period of the frequency. To increase accuracy I would use this trigger to start the ADC readings near the peak values, say 10 readings (or more) at a frequency of 10X the source frequency. Could that work and will I need the resistor divider to make the comparator to function?
 
 View user's profile Send private message  
Reply with quote Back to top
fleemy
PostPosted: Jun 30, 2007 - 07:58 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

fleemy wrote:
So to calculate the period I need to subtract the time(r) values from the successive highest and lowest ADC readings multiplied by two? So I need a ‘time stamp’ from the ADC readings to calculate the period?

While reading my answer I now see it’s easier then I thought.

As the ADC reading interval is fixed, I just need to count the number of readings between the highest and lowest successive reading, multiply that with the ADC interval and then by 2, to have the period of the frequency, right?
 
 View user's profile Send private message  
Reply with quote Back to top
ka7ehk
PostPosted: Jun 30, 2007 - 09:34 PM
10k+ Postman


Joined: Nov 22, 2002
Posts: 12035
Location: Tangent, OR, USA

Right.

You may want to average over several periods because the max and min you find may not be the actual max and min of the signal. That depends on your sample rate.

Jim
 
 View user's profile Send private message  
Reply with quote Back to top
fleemy
PostPosted: Jun 30, 2007 - 10:27 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Ok, thanks Jim.

I'll try some code and put it here(that will be working at night as I need to share my time between work, my 18 month and two week old sons, the wife and then the programming…).

Marc
 
 View user's profile Send private message  
Reply with quote Back to top
bobgardner
PostPosted: Jun 30, 2007 - 11:31 PM
10k+ Postman


Joined: Sep 04, 2002
Posts: 21248
Location: Orlando Florida

So its like a 'refridgerator is running' detector.... one approach might be... take a/d readings into a buffer for a half cycle... 8ms.... scan the buffer to see if any sample is farther than N counts away from 0 amps (about 512 on a scale from 0 to 1023). Assuming +-2.5V means +-5A at 220V, that would be 1100W at plus or minus full scale, so 10W would be about 5 counts above or below 512.

_________________
Imagecraft compiler user
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
fleemy
PostPosted: Jul 01, 2007 - 01:04 AM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Hi Bob,

Well yes it's for detecting a coil (10-12W) failure on a solenoid valve, the lowest consumer, and defrosts resistances witch are the highest consumers.

The sensors outputs a 2.5V offset when there’s no current flowing through it. It output’s 180mV/A (for the +/-5A sensor) above the offset for positive currents, 180mV/A under the offset for negative currents. So when applying AC current to the sensor, the output swings above and under the offset voltage at the AC frequency.

The sensor is ‘calibrated’ for +/- 5amps, but the range is 10A.
0.180 x 10 + 2.5 = 4.3V and -0.180 x 10 + 2.5V = 0.7V, so there’s even some room left between the 0-5V rail.

So that leave’s me 9 bit’s of accuracy, if I use the input directly from the sensor. But that will be enough, as I will have approx 6W of resolution for the 10A range.
 
 View user's profile Send private message  
Reply with quote Back to top
TrevorWhite
PostPosted: Jul 01, 2007 - 10:18 PM
Hangaround


Joined: Jan 20, 2003
Posts: 398
Location: Birmingham, England

I have been looking at these. The datasheet seems to indicate these devices have noise in them. You can reduce this noise with a capacity but this also reduces the response of the devices. When I looked at them it seemed to suggest the best accuracy was 100mA? Has anyone else found this or did I read them wrong?

I ask this because you might well not end up with 9bits of accuracy.
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
fleemy
PostPosted: Jul 01, 2007 - 11:46 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

The sensitivity is, depending on the selected sensor, 66 mV, 100 mV and 180 mV for the 30A, 20A and 5A sensors respectively.

The accuracy is 1.5% full range. As it is an analog component the limit in accuracy is the ADC.

The noise is quite significant (5A sensor); 20 mV for 2 kHz bandwidth and 75mV for the max 50 kHz bandwidth. But you could oversample the signal to cancel noise and increase the resolution in mean time.

But it’s true, I have less than 9 bits of accuracy if I read the raw signal on the ADC.

0A = 2.5V, 10A = 2.5V + 0.180 x 10 = 4.3V.

512 (9 bit counts) x (4.3 – 2.5) / (5.0 – 2.5) = ~369 counts for the full range.
 
 View user's profile Send private message  
Reply with quote Back to top
fleemy
PostPosted: Jul 03, 2007 - 03:50 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Well I’ve done some testing, and as Trevor said there’s a lot of noise on the signal. Will do some new testing with different capacitor values you can connect to reduce the noise, but that also reduces the bandwidth. In my case it’s not really relevant as I only need 50Hz of bandwidth.

Here’s the test configuration:
I'am using a simple halogen lamp as current source.


The prototype board:


With the smd ACS712 sensor on the bottom side:


The pictures are not the best quality, as I took them with the cell phone camera.
 
 View user's profile Send private message  
Reply with quote Back to top
zauberer
PostPosted: Jul 03, 2007 - 05:18 PM
Resident


Joined: Mar 06, 2001
Posts: 552
Location: Moscow

You have room to add rectifier Very Happy
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
TrevorWhite
PostPosted: Jul 05, 2007 - 09:28 PM
Hangaround


Joined: Jan 20, 2003
Posts: 398
Location: Birmingham, England

Be really interested to see your results. I have just received samples of the devices myself so some info on the actual noise figures you are getting will be very interesting/useful. Are you able to show some scope traces of the noise?

Trev
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
zauberer
PostPosted: Jul 06, 2007 - 12:26 PM
Resident


Joined: Mar 06, 2001
Posts: 552
Location: Moscow

These is scope trace on my acs704-15.
Alexander.
 
 View user's profile Send private message Send e-mail Visit poster's website 
Reply with quote Back to top
Kartman
PostPosted: Jul 08, 2007 - 11:24 AM
Raving lunatic


Joined: Dec 30, 2004
Posts: 8729
Location: Melbourne,Australia

I've used these devices recently - you need to watch out for stray magnetic fields! don't put a relay or high current carrying tracks nearby!
 
 View user's profile Send private message  
Reply with quote Back to top
fleemy
PostPosted: Jul 08, 2007 - 08:27 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

True, when I put a screwdriver (a little magnetized) near the sensor, the output reacts on it. In a real world application I would shield the sensor on both sides.

Kartman, did you use the bidirectional or the unidirectional sensor? The reason I ask is how did you interfaced the sensor with the µcontroller?

Some people advised me to take multiple readings and then get the highest and lowest values to calculate the peak to peak current; witch was what I thought also the way to go. The problem is that this method does not really give a stable output. The reason I think is that for AC measurements you need to stay synchronized with the signal, otherwise the readings are, what I would call ‘phase shifted’ now end then, witch makes the readings unstable.


I am changing the hardware a little to use the comparator input, feeding the negative comparator input with a fixed 2.5V voltage input from a resistor divider, and using the sensor output for the positive input.


The comparator interrupt (on toggle) triggers a timer, to calculate the period of the signal, but also to trigger the ADC at a fixed delay to read the signal as close as possible to both the peak values.

Could that be done and would it work? What are the other options?


As for the results so far, with some averaging (32), I’ve got it stable to 1 count until the reading goes out of sync.

Zauberer, I’ll try with the rectifier and see how it goes.

Thanks for the responses so far, I appreciate.

As I never went to school for all of this, don’t mind to tell me when I say something stupid.

This experiment is helping me a lot to understand how the µcontroller reacts to changes in code, and the limitations of the resources. Coming from programming in VB on a PC (just for fun) it’s a whole different world.

Marc.
 
 View user's profile Send private message  
Reply with quote Back to top
Kartman
PostPosted: Jul 09, 2007 - 04:33 AM
Raving lunatic


Joined: Dec 30, 2004
Posts: 8729
Location: Melbourne,Australia

I'm sensing current on a full wave rectified AC signal - I sample 10 times and take the highest reading. I don't need accurate current readings.

As for interfacing the sensor - the sensor output is biased to half VCC - I subtract this value in my code. Basically, I have the RC filter described in the datasheet then to the ADC input on the AVR.
 
 View user's profile Send private message  
Reply with quote Back to top
fleemy
PostPosted: Jul 09, 2007 - 12:12 PM
Hangaround


Joined: May 10, 2007
Posts: 396
Location: Brussels, Belgium

Ok, so I only need the RC filter to rectify the signal for a smother output, just as zauberer mentioned. So I take the highest value from 10 samples, subtract 511d from it, then multiply that with 5/1023 and divide that with the square root of two, to have roughly the RMS value of the AC current.

Also as a side note; if I want to divide with floating numbers, is it better if I use (float)int * 1/constant float, or should I just use (float)int /constant float?

Marc.
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits