Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Dspic30f2010 Reset Problem

Status
Not open for further replies.

rmrps

New Member
Hi Friends I am using dspic30f2010 microcontroller with 12.288Mhz i want to sense the ac voltage this is my code in that i am using timer interrupt for sense the analog input the problem is the devise get reset please give me the suggestion where to change the code also give me the suggestion some other methods to sense the ac voltage thanks in advance

Code:
int main(void)
	{

	TRISB=0xFF;
	TRISE=0x00; 
	Lcd_Initialize() ;

	ADCON1 = 0;
	ADCON2 = 0;
	ADCON3 = 0x9;
	ADPCFG = 0x0;
	ADCHS = 0x07;
	ADCON1bits.ADON = 1;

	R_Ph_Rms_Vol=0; 
	Phase_interrupt =0;

	T1CON=0;
	TMR1=0;
	PR1=16000;
	IFS0bits.T1IF=0;
	IPC0bits.T1IP=4;
	IEC0bits.T1IE=1;
	T1CONbits.TCS = 0;
	T1CON=0x8000;

	while(1)
		{

		if(Time_Update==1)
			{

			for(R_i=0;R_i<20;R_i++)
				{ 
				R_Ph_Voltage[R_i] = R_Ph_Voltage[R_i]-512; 
				R_Ph_Ana_Vol[R_i] = (R_Ph_Voltage[R_i]*5.0)/1023.0;	
				R_Ph_Ana_Vol[R_i] = R_Ph_Ana_Vol[R_i] * R_Ph_Ana_Vol[R_i];
				}
			R_Ph_Rms_Vol = 0;

			for(R_i=0;R_i<20;R_i++)
				{
				R_Ph_Rms_Vol = R_Ph_Rms_Vol + R_Ph_Ana_Vol[R_i];	
				}
			R_Phase = R_Ph_Rms_Vol;	 R_Phase = sqrt(R_Phase/20.0);
			R_Phase = R_Phase *284.00;
			Phase1 = (int)R_Phase;

			R_Ph_Rms_Vol=0; 
			Phase_interrupt =0;

			k=Phase1;
			l=k/1000; Status1[6] = l + 48; k=k%1000;
			l=k/100; Status1[7] = l + 48; k=k%100;
			l=k/10; Status1[8] = l + 48; k=k%10;
			Status1[9] = k + 48;

			Lcd_Command(0x80);
			for(l=0;l<=18;l++)
				{
				Lcd_Send_data(Status1[l]);
				}	
			Time_Update = Time_Update & 0x01; 

			}
		}
	return (0);

	}


void __attribute__((interrupt,auto_psv)) _T1Interrupt(void)
	{
	IFS0bits.T1IF = 0;
	if(Phase_interrupt!=20)
		{
		R_Ph_Voltage[Phase_interrupt] = Read_Adc(0);
		Phase_interrupt++;
		}
	}

int Read_Adc(int channel)
	{
	unsigned char Delay=0;
	if(channel > 0x000F) return(0);
	ADCHS = channel;
	ADCON1bits.SAMP = 1;
	for(Delay = 0; Delay < 5; Delay++);
	IFS0bits.ADIF = 0;
	ADCON1bits.SAMP = 0;
	while(!IFS0bits.ADIF);
	return(ADCBUF0);
	}
 
Last edited by a moderator:
Here are a few suggestions/comments:

When is the dsPIC resetting? Periodically? Instantly? Every 10 minutes? When I look at it hard?....

You really need to comment your code if you want people to help you troubleshoot it. I don't have the time to decipher every line to try and understand what you are doing.

Did you shut off the watch dog timer in the configuration bits?

PICs (and most microcontrollers for that matter) cannot tolerate negative voltages on any of their pins which means you can't directly measure AC voltages. If your analog front end doesn't correct this, that could cause your device to reset.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top