What do the numbers mean, Irms A? What's the expected value? How do you calculate AC current from instantaneous sensor output voltage?I see different values from 0.25 to 1.85 when I connect 40W bulb.
What is the max rating of the sensor ? 5A, 20A or 30A ? Are you measuring AC or CD Current ?
What do the numbers mean, Irms A? What's the expected value? How do you calculate AC current from instantaneous sensor output voltage?
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC CODE AREA///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void ADC_Init()
{
ADCON0 = 0x81;
ADCON1 = 0x84;
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //If Invalid channel selected
return 0; //Return 0
//ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GODONE = 1; //Initializes A/D Conversion
while(GODONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void ADC_main()
{
process();
TRISA = 0xFF; //PORTA as input
process();
ADC_Init(); //Initializes ADC Module
process();
[COLOR="#FF0000"] Factor = 264;
ADCResult = ADC_Read(0); //Reading Analog Channel 0
ADCResult = ADC_Read(0);
ADCResult = ADCResult + ADC_Read(0);
ADCResult = ADCResult + ADC_Read(0);
ADCResult = ADCResult/3;
A = (ADCResult-512)*Factor ;
finalresult = (int)(A+0.5); //////float to int conversion
z = (char)finalresult; /////////int to char coversion
x=z%10;
dat=(z % 1000) / 100 + 48 ;
dat0 = '.' ;
dat1=(z % 100) / 10 + 48 ;
dat2=z % 10 + 48 ;[/COLOR]
process();
__delay_ms(10); //Delay
flag = 1;
process();
}
I think he will calculate like this.
http://henrysbench.capnfatz.com/hen...surements/acs712-arduino-ac-current-tutorial/
What is the problem you are facing ? The sensor gives 5V output for 5A. It is linear.
What is the problem you are facing ? The sensor gives 5V output for 5A. It is linear.
Show full code. What type is ADC_Result ? double ?
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////*********Headers & Definations*******///////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
#include <htc.h>
#include<pic.h>
#include<string.h>
#include<stdio.h>
#define _XTAL_FREQ 20000000
//////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////*********Declaration********/////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void Uart_Initial_Tx_Rx(unsigned long baud);
void Uart_Data(unsigned char data);
void Send(const char *ptr);
void Send_Message();
void delay();
void delay1();
void process();
void process2();
void ADC_main();
float V,A;
unsigned char data1,x,z,dat0,dat,dat1,dat2,q,d1,d2,d3,d4,ADCResult,Factor,once;
int finalresult,i,j,k,m,t,flag,flag2;
////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////********MAIN CODE AREA**********////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
void main()
{
TRISD0 = 1;
TRISD1 = 1;
TRISD2 = 0;
TRISD3 = 0;
TRISD4 = 0;
TRISD5 = 0;
TRISD6 = 0;
TRISD7 = 0;
RD7 = 0; ////Process LED
RD6 = 0; ////theft load indication
RD5 = 0;
RD4 = 0;
RD3 = 0; ///Turn off ENERGY meter Relay
RD2 = 0;
//RD1 = 1;
process();
Uart_Initial_Tx_Rx(9600);
ADC_main();
once = 1;
process();
while(1)
{
if(RD0==0) ////////////////////Phase cut
{
if(once==1)
{
//ADC_main();
Send_Message();
process();
once = 0;
_delay(50);
}
}
else if(RD1==0) ////////Mis call Input
{
RD3 = 1; ///Turn off ENERGY meter Relay
process();
}
else if(dat>0x31)
{
if(flag == 1)
{
Send_Message();
flag = 0;
for(t=0;t<10000;t++)
{
process2();
}
process();
}
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////******GSM Modem Initilize********///////////////////////
////////////////////////////////////////////////////////////////////////////////////////
void Uart_Initial_Tx_Rx(unsigned long baud)
{
process();
TRISC6 = 0;
TX..EN=1;
BRGH=1;
SYNC=0;
SPEN.=1;
if(baud == 9600 )
SPBRG = 129;
els.e if (baud == 19200)
SPBRG = 64;
else if (baud == 38400)
SPBRG = 32;
else if (baud == 57.600)
SPBRG = 21;
else if (baud == 115200)
SPBR.G = 10;
process();
}
void Uart_Data(unsigned char data)
{
TXRE.G=data;
while(TRMT.!=1);
}
void Send(const char *ptr)
{
while(*ptr.!='\0')
{
TXRE.G=*ptr;
while(TRMT!=1);
ptr++;
}
}
////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////*****DELAY*****////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
void process()
{
RD7 = 1;
delay();
RD7 = 0;
delay();
RD7 = 1;
delay();
RD7 = 0;
}
void process2()
{
RD6 = 1;
delay1();
RD6 = 0;
delay1();
}
void Delay_Ms(int ms)
{
int i,count;
for(i=1;i<=ms;i++)
{
count=498;
while(count!=1)
{
count--;
}
}
}
void delay()
{
for(i=0;i<80;i++)
for(j=0;j<80;j++);
}
void delay1()
{
for(i=0;i<300;i++)
for(j=0;j<255;j++);
}
//////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////*********Text Message**********/////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void Send_Message()
{
process();
Send("AT\r\n");
Delay_Ms(500);
Send("ATE0\r\n");
Delay_Ms(500); /* 500ms delay */
Send("AT+CMGF=1\r\n");
Delay_Ms(500); /* 500ms delay */
Send("AT+CNMI=2,1,0,0,0\r\n");
Delay_Ms(500);
process(); /* 500ms delay */
Send("AT+CMGS=\"+917507942453\"\r\n");
Delay_Ms(500); /* 500ms delay */
Send("Power Theft Detected\r\n");
Delay_Ms(500);
Send("\r\nUser ID ABC12345678MH\r\n");
Delay_Ms(500);
Send("\r\nCurrent in A = ");
Delay_Ms(500);
Uart_Data(dat);
Uart_Data(dat0);
Uart_Data(dat1);
Uart_Data(dat2);
process();
Delay_Ms(500);
Uart_Data(0x1A);
Delay_Ms(500);
process();
/* 500ms delay */
}
/////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////ADC CODE AREA///////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////
void ADC_Init()
{
ADCON0 = 0x81;
ADCON1 = 0x84;
}
unsigned int ADC_Read(unsigned char channel)
{
if(channel > 7) //If Invalid channel selected
return 0; //Return 0
//ADCON0 &= 0xC5; //Clearing the Channel Selection Bits
ADCON0 |= channel<<3; //Setting the required Bits
__delay_ms(2); //Acquisition time to charge hold capacitor
GODONE = 1; //Initializes A/D Conversion
while(GODONE); //Wait for A/D Conversion to complete
return ((ADRESH<<8)+ADRESL); //Returns Result
}
void ADC_main()
{
process();
TRISA = 0xFF; //PORTA as input
process();
ADC_Init(); //Initializes ADC Module
process();
Factor = 264;
ADCResult = ADC_Read(0); //Reading Analog Channel 0
ADCResult = ADC_Read(0);
ADCResult = ADCResult + ADC_Read(0);
ADCResult = ADCResult + ADC_Read(0);
ADCResult = ADCResult/3;
A = (ADCResult-512)*Factor ;
finalresult = (int)(A+0.5); //////float to int conversion
z = (char)finalresult; /////////int to char coversion
x=z%10;
dat=(z % 1000) / 100 + 48 ;
dat0 = '.' ;
dat1=(z % 100) / 10 + 48 ;
dat2=z % 10 + 48 ;
process();
__delay_ms(10); //Delay
flag = 1;
process();
}
Reply to my previous post. What is the crystal frequency you are using ?
I will write a code for you. You test it in hardware. Please provide the info asked below.
Crystal frequency.
LCD Connections.
LCD type - 16x2, 20x2, 20x4, 16x4 ?
Reply to my previous post.
Ok. Burn this hex file to your PIC and then disconnect GSM modem and connect UART to PC and in PC set COMx port baudrate to 9600 bps.
Connect AC712 sensor to RA0. Don't connect any other thing to PIC. MCLR is enabled and so pullup MCLR to 5V using a 10k resistor. Connect sensor inputs in series with the Live wire of the load. Open Termite Serial terminal Software in PC and set COMx port and baudrate properly. See if correct current values are displayed. Also connect a Multimeter in AC Current measurement mode (10A) range and measure the current through the load. Compare the currents.
If this works properly then I will implement GSM code for you and provide you my code.
Are you using SIM900 ?
Ok. You provide me the number to which SMS has to be sent. I will write a basic code which will send the current value to that mobile number as SMS. You can test it now itself. Later I will write you pro code which checks if GSM modem is connected and powered and it will initialize the modem and then while sending AT commands it will check if \r\nOK\r\n response is received or not.
Here it is mentioned that the sensor gives 185 mV / A.
https://www.sparkfun.com/products/8882
So, if you have a 5A sensor. it gives. 185 * 5 mV for 5A. I have to change my code.
- - - Updated - - -
I am attaching a project. Please tell why it is giving wrong results. ACS712 sensor is used. I am only testing it in Proteus. ACS712 sensor gives 0.925V for 5A and so for 5V it will be 27.027 A. I have written code so that if adc RA0 input is 5V then current will be 27.027 A but for 5V adc input it is showing 5A. Is it mikroC bug or Proteus bug ?
I found from some webpage that ACS712 sensor gives 185 mV / A and so it is 27.027 A for 5V.
Please provide the mobile number for which the SMS has to be sent. I will write a code and post the .hex file for testing. It was not a Proteus bug. I had set VDD at 27.027V and it was causing the problem. I deleted that entry in Configure Power Rails... dialog box and it started to work properly.
If you provide the mobile number then i will quickly provide you a .hex file for testing and it will send SMS to that number.
I getting 13.27 A constantly with and without Load.Test this .hex file. If it gives correct current value then I will write more robust GSM code and post it here. Our Compilers are different. I think you are using Hi-Tech PICC. I am using mikroC PRO PIC Compiler.
The document you posted is taken from embedded-lab website and it mentions the same thing which I told that is sensor gives 185 mV / A.
Edit:
Try Rev1 file in hardware and tell if it gives correct current values.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?