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.
To take the approach of you formulas you need to monitor the voltage and current. Then you need to detetect the 0 crossing of each. Measure the time between the 0 crossings and assuming a fixed frequency you can compute the power factor. An op amp to condition each input connected to a comparitor might make up the inputs to the digital input pins on the uC. You will need to learn how to do timings on the uc. You can probably do the programming using only polling wich is not as flexible as interupts but a bit easier. Walk thru this step by step getting one part to work and then another. If you are new to this sort of thing you have several different sub projects to complete to get the whole thing done.
Be aware that it is very common for an AC load to contain nonsinusoidal components. A simple DC power supply, a rectifier and a capacitor, has a lot of harmonics because no current flows until the instantaneous voltage exceeds the capacitor voltage, then current can be fairly high. These harmonics complicate the measurement but not all that much. The ADC can take quite a few datapoints off a 60Hz wave.
But one thing to look at is that the samples will be confused by frequency components above the Nyquist Rate, which is 1/2 the sample rate. So if you're sampling the waveform at 1Ksample/sec, any harmonics above 500Hz will not represent correctly. One way to fix this is a lowpass analog filter before the ADC to cutoff these components, however, a single pole RC filter may be too soft of a cutoff. An active filter can be designed with a far cleaner cutoff.
Be aware that the PIC, and say an LCD, will probably be grounded on the powerline Neutral. This is unsafe to touch, but you generally won't need to touch them. The real problem involves using your ICD on a Neutral-grounded board: you cannot do this! It could potentially blow the ICD if not your PC. AFAIK you have to discard ICD, program externally, and insert the chip in a socket. And you definitely cannot connect your PC's RS232 serial port to the PIC's UART with the PIC ground tied to Neutral. You'll need optoisolators in between.
But the problems with neutral grounding can be avoided if you can get ahold of a 120v "isolation transformer". A bit uncommon nowadays to find, but always good to have. As the name implies, they isolate the 2 output wires from the input ground entirely, because it's a transformer, but generally with a 1:1 ratio so it's 120vac in/120vac out. This should allow you to safely program and ICD and use the UART directly with the PC.