Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC gone hang when connected to a current sensor

Status
Not open for further replies.

embed_techie

Newbie level 4
Newbie level 4
Joined
Mar 19, 2013
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,310
Helloo

Im doing a project using PIC16f877A.Project aims at controlling current consumption during peak hours.It includes a current sensor and RTC.Current sensor used was ACS714 module which gives an analog output.PIC I had used here got an ADC peripheral and so i connect the senor output to AN0 of the PIC.Without load the ADC output is ok .But when load is given current sensor output is changing but the PIC is going hang.The circuit I have used is attached below.

1, opto-coupler circuit is used to measure unit consumed and is connected to external interrupt pin RB0
2, A relay circuit was used to switch the main supply
3, ACS712/714 used to measure the current which connected to analog pin of PIC


Please help me to solve this problem...

 
Last edited:

what is your ADC sub-routine? is it interrupt based or poll based?
share the main program.
 

I have used a poll based routine for ADC and interrupt based for measuring units..ADC measure function and interrupt function is attached .A display function was used to send the ADC value serially.

Code:
int measure(unsigned char channel)  	//fn to measure current sensor o/p
{ 
	int tmp1=0;
	ADCON0=channel;
	__delay_ms(10);
	GO=1;
	while(GO);
	tmp1=ADRESH<<8|ADRESL;
	return(tmp1);
}

void display(unsigned int b)            //to display adc result in serial window
{	int arr[4]={0,0,0,0},i=0;
	while(b!=0)
	{	arr[i++]=b%10;
		b=b/10;
	}
	for(i=3;i>=0;i--)
	{	TXREG=arr[i]+'0';
		while(TRMT==0);
	}
	TXREG='\r';
	while(TRMT==0);
	__delay_ms(200);
}


void interrupt isr()                    //isr for taking units which is connected to RB0 of PIC
{
	 if(INTF)
 	 {
	 	 INTF=0;
	  	count++;
		  
	  	eeprom_write(0,count&0x00ff);
		eeprom_write(1,((count>>8)&0x00ff));
		  
	  	if(count>5) 
		{
			unit++; count=0;
	  		eeprom_write(2,unit&0x00ff);
			eeprom_write(3,((unit>>8)&0x00ff));
		}
		status=1;
	}
}
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top