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.

TIMER VALUE TO ANGLE for POWER FACTOR METER:

Status
Not open for further replies.

karan123

Member level 3
Joined
Feb 2, 2009
Messages
55
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,710
Hello All,

I am working on Project of Measurement of Power factor with PIC18F4520 MCU with External

Crystal Osc 4 MHz and MPLAB XC8. [Capture mode, every rising edge]

My Voltage ZCD and Current ZCD are working fine as checked on CRO.

Can any body give me given how to convert

Time value to cos (phi) in C. I am doing as below:

Code:
void Capture_init() 
{ 

/* 
                    CCPxM3:CCPxM0
                    [B]0101= Capture mode, every rising edge[/B]
*/
			CCP1CON=0x05; 
			CCP2CON=0x05; 
/*
                        bit 5-4 T1CKPS1:T1CKPS0:Timer1 Input Clock Prescale Select bits
                            [B]  11= 1:8 Prescale value[/B]
                        bit 2 T1SYNC:Timer1 External Clock Input Synchronization Select bit
                            [B] When TMR1CS = 1:[/B]
*/
			T1CON=0x34; 
			TMR1H=0; 
			TMR1L=0; 
   	                 while(1) 
			{ 
					for(i=0;i<10;i++) 
					{ 
							CCP2IF=0; 
							while(CCP2IF==0); 
							TMR1ON=1; 
							CCP1IF=0; 
							while(CCP1IF==0); 
							TMR1ON=0; 
							time=CCPR1H; 
							time=(time<<8)+CCPR1L; 
							avg=avg+time; 
					} 
					avg=avg/10; 	
					cmd(0xC0) ;
					printf("%d",avg);  // Display
                                       [B] // Clear Variable to Next Round[/B]
	                                TMR1H=0; 
					TMR1L=0; 
					TMR1IF=0;avg=0; 
                         }
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top