PIC 16f877 A/D conversion Allegro ACS712
Hello all... I posted some threads a while back and got some help with the 16F822 and it's A/D conversion process. I worked through the math with a pressure transducer and had thought I worked out the math with the Allegro current sensor ACS712 but I'm pretty sure I was originially wrong on that and now just want to get a second opinion or 2 to see if I finally got it. If anyone has any comments please let me know.
I did find one thread dealing with what I am pretty sure is the ACS712 perhaps a typo on the name or it was called that before I started to use them. In this thread they do math on this device but I think the outcome of this math is going to be a little bit off if they are truly talking about the ACS712. It turns out the company I work for does allot of business with Allegro and the were more then happy to help me out. I did review the data sheet on the Acs712 but initially didn't spot the output voltage until just yesterday. I emailed them and they confirmed the output range of the 712 is 2Vdc which is 2.5Vdc to 4.5Vdc
So my question/observation is using an 8bit number by my calculations the multiplier of the value returned by the pic would be .02272. From the PIC for a 0 to 30 amp reading from the 712 I could expect to see 128 to 216 which gives me 88 to work with divide 2/88 and get .02272 thus my calculation is
amps = reading * 2272
amps = DIV32 1000
Did I get this right or is my math still off? Hope thats not to long winded.
Thanks
David
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
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
A few more thoughts... That is small
Yes that package is pretty small... I've been thinking as Mr. Houston pointed out this is what I was initially doing, taking many readings, I realize that because the reading from the ACS712 is going to go along with the sine wave and at any given point in time it could give me a reading anywhere along the wave I'd been taking hundreds of samples and keeping track of the MAX. then after a couple of seconds display this value. I just got an email from Allegro and they pointed out when reading for AC current that the + reading will be 2.5V to 4.5V and the minus side reading will be from .5V to 2.5V Could I not keep track of the MIN as well since the reading will never go negative and add that into my equation averageing the min and max? Where a reading of 169 on the + side of the scale would be a 94 on the minus side of the scale right? If I grab enough of these readings....
Is this completely wrong to go this route? It seems like it has been working. According to the franklin motor company and my clamp meter it seems like I was really close but my math, in particuliar, my multiplier thats why I started this thread in the first place. It's not imperative that this be a real time reading as long as I can get a reading every couple of seconds then for this application it is going to be fine. What I am doing is basically monitoring the current the submersible pumps are drawing and when the well runs dry the current drops about 1 to 2 amps and when I sense this I can shut the pump down.
David
Thinking about this still this morning
Darrel, I think I might understand now I know that we are off subject from a general pic discussion but I'm going to keep going in this thread it does pertain to working with a pic ultimately so....
I think I am picturing this correctly now. If I take a thousand readings from the PIC and just keep track of the max at some point I will get a peak let's say it's 12 amps. But like you are pointing out that is truly a peak if we were able to get a sample at the top of each waverform over time it would average out to 9 amps which is the true power. The fact that when I sample the A/D I have know idea were in the wave form I am at, at any given point in time, makes it impossible to do just sampling the ACS712 by itself. If I could get a reading form the ACS712 at the top/bottom of each wave then it could be done but then that is what the RMS to DC is going to do for me give me a nice straight DC line.
Did I get it?
1 Attachment(s)
Re: PIC 16f690 Allegro ACS712 + -30Amp
Is this the way to get negative reading? i am new to this, so sorry if i mixed it up.
I use Allegro ACS714 but with a PIF16F690 with A/D set to 8bit, should not be any difference.
It works and can read +30Amp to -30Amp.
The problem is that i use 0V and 5V as reference. I cant figure out to get 0.52V to read 0 and 4.48V to read 255? Is it a math problem or must i add an external ref?
The ACS gives 66mV/A:
Amp Vin Bit
+30A 4.480 255
+10A 3.160
+1A 2.566
0A 2.500 127
-1A 2,434
-10A 1.840
-30A 0.520 0
See CODE below and attached DRAWING
Attachment 5290
Code:
'Define OSC and ADC
DEFINE OSC 4 ' Set internal Oschillator to 4Mhz
DEFINE ADC_BITS 8 ' Set number of bits in result
DEFINE ADC_CLOCK 2 ' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50 ' Set sampling time in uS
' Define LCD pins
Define LCD_DREG PORTC 'LCD data port
Define LCD_DBIT 0 'LCD data starting bit 0 or 4
Define LCD_RSREG PORTC 'LCD register select port
Define LCD_RSBIT 4 'LCD register select bit
Define LCD_EREG PORTC 'LCD enable port
Define LCD_EBIT 5 'LCD enable bit
TRISA = %00001001 ' RA0 = A/D input
ADCON1.7 = 0 ' RA.1 = +Vref, Set PORTA analog and left justify result
PORTb.6 =0 ' Prepare RB0 for high-going pulseout
ANSEL = %00000101 ' Set PORTA.2 analog, rest digital
ANSELH = %00000000
' Variables
outpuls VAR WORD ' Variable for the calculated puls out in mS
POT_POS VAR BYTE ' Potentiometer position CC=0, CCW=255
amp var word ' Ampere 30A-0-30A (0-127-255)
Pause 500 ' Wait for LCD to start
MainLoop: ' The Loop start here!
ADCIN 0,POT_POS ' Read A/D channel 0 to variable SVO_POS
'Check if negative or positive Ampere
IF POT_POS=>127 then
amp=(235 * (POT_POS-127))
else
amp=(235 * (128-POT_POS))
endif
Lcdout $fe, 1, "POT_POS= ", #POT_POS ' Display POT Valu between 0-255 on line 1
' Check if negtive or positive Ampere, only for - minus sign on LCD display
IF POT_POS=>127 then
LCDOut $fe,$C0, "AMP= ",DEC (amp/1000),".", DEC1 amp' Display +Amp on line 2
else
LCDOut $fe,$C0, "AMP= -",DEC (amp/1000),".", DEC1 amp' Display -Amp on line 2
endif
PAUSE 20 ' Constant 20mS pulses(low) between outpuls
GOTO MainLoop ' Forever
End
Re: PIC 16f877 A/D conversion Allegro ACS712
Hello Darrel,
I know the topic is old , but i need help as i am new to analog. Will you be so kind to post the schematic, mostly i am looking at the use of the TLV324. I do not have a clue about op amp, and if i do not find a solution fast to our plant, my boss will send me fishing and get somebody else to replace me. In my case is simpler than the post. I have a machine with 100 heaters, and i would like to use acs712 to detect any burned out heaters, meaning 0 amps. Also i can leave with detecting any heater which is less than one amp. What i want to achieve is to have an optocoupler for each output of ltc1966, and if the current is over or equal with 1 amps to turn the opto ON. the opto will feed a digital input to my micro. If it is simpler i am happy with 0 amps too. what ever it is simpler, no need for calibration, and less components to adjust .
If you would like you can also write me at [email protected]
As the issue stands right now, i am in the hot water because i have 10 days to implement a solution.The maximum current on the heaters (110 VAC) it is 4.5 amps ac.
Thank you