PIC 16f877 A/D conversion Allegro ACS712


Closed Thread
Results 1 to 33 of 33

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Here is a longer way of looking at what is happening. Not as nice as Darrel's but it may help you understand a bit. This works for sensors that do not start on zero.

    The old formula of
    y = mx-b
    y = output 'amps in your case
    m = slope
    x = input units
    b = offset

    You are wanting to read form 0 to 30 amps.

    Start off by looking at the units as being volts. You have a 2 volt span. This means that every 1 volt input will equal 15 amps. Slope will equal 30 / 2 = 15..
    m = 15

    The offset. Starting at 2.5 volts. 2.5 volts = 0 amps. the offset is 2.5 * 15 = 37.5
    b = 37.5

    Plug all this into the formula and lets say the input is 4.5 volts.
    y = (15 * 4.5) - 37.5
    y = 30 amps

    Now convert this to an 8 bit PIC resolution.
    Like Darrel did I will assume a 0 to 5 volt reference.

    2.5 volts = 127
    At 8 bit resolution each volt is 51 steps.
    Spanning 2 volts or 102 steps will have 4.5 volts equaling 229.

    New value for m is 30 / 102 = 0.2941
    m = 0.2941

    New offset value is 127 * 0.2941 = 37.35
    b = 37.35

    y = (ADC * 0.2941) - 37.35
    ADC = 229
    y = 29.99 amps

    Possible code...
    Code:
    ADC = 229
    z = ADC * 2941  ' equals 673489
    z1 = DIV32 10000  ' z1 = 67
    y = z1 - 37       ' Did you want precision???
    I am sure something is wrong but it may help you understand.
    Dave
    Always wear safety glasses while programming.

  2. #2
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default I get it but must be doing something wrong.

    Darry and Mack thanks very much for your response. I undersatand the 2 different ways you came to your solution. Either my ACS712 is fried or I am doing something wrong. I am passing AC through the 712. No matter which math I use the current reading seems to high but 2 to 3 amps. That is according to my clamp meter I am using taking a reading at the same time and the device I am using to test this. I am running a heat gun which states on the side it's 1200 watt 10amp heat gun.

    Any suggestions? I can post my code it's a very simple program.

    I appreciate the help, I've got to sweep up this big pile of hair I just yanked from my head

    Thanks
    David

  3. #3
    Join Date
    Apr 2009
    Location
    Pittsburgh, PA
    Posts
    17


    Did you find this post helpful? Yes | No

    Default Diagram we use

    I drew this diagram to illustrate the different units involved.

    For a numeric value of 166 read from the analog-to-digital converter, Darrin's equation brings back 11.58 and Mackrackit's brings back 11.47.

    They are close enough given the low resolution arithmetic taking place especially if you just round up to no decimal places.

    I can attest to the annoyance of one meter showing 9 Amps when the equations bring back the numbers above.

    http://www.picbasic.co.uk/forum/albu...0&pictureid=25
    Last edited by ukemigrant; - 3rd August 2009 at 01:06. Reason: Stupid image did not show up

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by DavyJones
    I am passing AC through the 712. No matter which math I use the current reading seems to high but 2 to 3 amps
    What Dave and I both "assumed" was that you were measuring DC currents.
    The part about an A/C signal would have helped in the beginning.

    Being that the heat gun is mainly a resistive load, you could get a much closer reading by finding the highest (peak) voltage and multiply by 0.707, which gives the R-M-S value of a perfect sine wave. Then convert to current.

    The heat gun also has a fan, which is an inductive load, so you'll never get a perfectly "accurate" reading with the 0.707 multiplier. But since the fan is only a small portion of the load it would be closer.

    But I doubt the eventual use of your project will be measuring the current from heat guns. And the type of load makes a HUGE difference.

    If you'll be primarily measuring motor currents, the wave forms will NOT be sine, and .707 will not even come close. In that case, there is only one way to go.

    Run the signal from the current sensor into an R-M-S converter. Don't bother trying to do it in software. I like the LTC1966, but it's a really tiny chip and isn't great for hobby use cause they're too hard to solder.

    There are several other chips available that do the same thing. But for sure you will need an R-M-S (Root Mean Square) reading for any inductive loads.
    <br>
    DT

  5. #5
    Join Date
    Dec 2005
    Posts
    1,073


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    If you'll be primarily measuring motor currents, the wave forms will NOT be sine, and .707 will not even come close. In that case, there is only one way to go.

    Run the signal from the current sensor into an R-M-S converter. Don't bother trying to do it in software. I like the LTC1966, but it's a really tiny chip and isn't great for hobby use cause they're too hard to solder.

    There are several other chips available that do the same thing. But for sure you will need an R-M-S (Root Mean Square) reading for any inductive loads.
    <br>
    You can also take many readings (~100 x the frequency or 6000Hz) and average them but I don't think a PIC can do this fast enough for accuracy. This is how digital wattmeters work.

    If an oscilloscope is not available, it might be possible to get an idea of the waveform using a PC or laptop with a LineIn port for the soundcard. The sampling rate should be adequate unless there are sharp spikes. Since the Allegro output is 0-5V, you can use the same technique I use for IR & RF. See...

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Not knowing more about the project a simple current transformer might be good enough. You would still need to calibrate it though.

    There are pros and cons to every option, but CTs are good enough for power companies to sell with...

    Let us know which way you want to go.
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    Jan 2008
    Location
    Pennsylvania
    Posts
    113


    Did you find this post helpful? Yes | No

    Default Good notes and advice as usual.

    Darryl, Your right I should have mentioned that I was trying to measure an AC current right off the bat my mistake.

    So I've got a couple differnt methods and since I want to learn I'm looking at both of these and am leaning more towards the LTC1966.

    Dave no I did not forget you and I have been taking many samples in my code but that does not seem to be working well for me but I do like your example of how to read this with the line in on the sound card and kind of simulate having an oscilliscope that is pretty cool and I am going to be doing that this evening.

    So to the RMS to DC converter. I'm reading the datasheet for the LTC1966 on it's functionality it sounds like as you said run the output of the 712 through and it is going to give me the DC voltage proportionate to the amps that I am trying to read on the pic correct? I'm going to get one and try it out so I can see this for myself.

    Thanks
    David

Similar Threads

  1. A/D conversion with PIC18F67J50
    By ScaleRobotics in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 8th May 2009, 01:48
  2. A/D conversion problem in 18F2520, 2523, 2550 etc.
    By selimkara in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 16:26
  3. 16f877 A/D help
    By 3adam in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2008, 04:06
  4. A/D converter fails?
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 13th February 2006, 18:57
  5. Strange A/D conversion...
    By Christos_K in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th June 2005, 01:35

Members who have read this thread : 0

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts