Troubleshooting
Why a PIC ADC reads erratic three-phase voltage sensing inputs
Short answer
Changing ADCON1 or rescaling will not fix fluctuating phase channels: a 5 Vac or 9 Vac RMS secondary swings to about ±7.1 V or ±12.7 V peak and reverses polarity, so each channel needs attenuation plus bias, or rectification, before the ADC. Define the 380 V and 440 V cutoffs as phase-to-phase or phase-to-neutral first, since on a balanced system 380 V and 440 V line-to-line equal about 219 V and 254 V line-to-neutral.

On this page
Your fluctuating phase channels are not a register problem: a 5 Vac or 9 Vac transformer secondary is raw AC, swinging to about ±7.1 V or ±12.7 V peak, and no ADC setting copes with that. This walkthrough is for you if you are conditioning three phase-sensing channels for a PIC ADC and setting 380 V and 440 V cutoffs; each channel needs attenuation plus bias, or rectification, first.
The answer #
Rescaling the result, changing the ADC reference register, or trying to hold every input at a constant voltage will not stabilize the channels. The one channel that reads correctly is the one whose conditioning circuit is complete; the channels that swing between roughly 0 and 5 V are seeing raw AC. A transformer secondary rated 5 Vac or 9 Vac is AC: it reverses polarity every half-cycle and its peak exceeds its nameplate RMS by a factor of the square root of two. Each ADC channel needs attenuation plus a bias (for waveform sampling) or rectification (for an average indication) before any register setting matters. De-energize the sensing circuits and verify absence of voltage before opening the enclosure or touching the secondary wiring; work on the low-voltage side only, and never probe the primaries live.
Why the secondary is not an ADC signal #
A sine wave's peak is its RMS value times √2 ≈ 1.414. So a secondary described as 5 V, if that is 5 V RMS, peaks at:
5 V × 1.414 = 7.07 V
and swings symmetrically to −7.07 V. A 9 V RMS secondary, the common suggestion for a phase-to-neutral tap, peaks at:
9 V × 1.414 = 12.73 V
and swings to −12.73 V. A PIC ADC input accepts roughly 0 to VREF (5 V in this design). Negative half-cycles forward-bias the input protection and positive peaks exceed the rail, so the converted numbers are garbage that flickers between near zero and near full scale. That is exactly the reported symptom. Loading and transformer regulation move the actual secondary voltage around its nameplate value, so measure each secondary under its real burden, not open-circuit.
Two valid architectures exist:
- Waveform sampling: divide the secondary down, bias it to mid-supply (for example 2.5 V), sample faster than the line frequency, subtract the bias in software, and compute RMS from the AC component. Never count the bias as supply voltage.
- Precision rectification: rectify and filter to a DC level proportional to amplitude, divide it into range, and calibrate against a true-RMS meter, since the DC output follows waveform shape, not RMS.
Decide which method the firmware uses before calling a fluctuating reading a fault; a sampling design is supposed to present a changing signal.
Which voltage the 380 V and 440 V cutoffs describe #
On a balanced sinusoidal system, V_LL = √3 × V_LN. If the 440 V high and 380 V low limits are phase-to-phase values, their phase-to-neutral equivalents are:
- 380 V / 1.732 = 219.4 V
- 440 V / 1.732 = 254.0 V
If the limits are phase-to-neutral values instead, those conversions do not apply and the primaries must be connected phase-to-neutral, which requires a neutral conductor; a protective earth is not a substitute. Check the supply arrangement and measure both quantities where a neutral exists before buying transformers.
Two consequences follow. First, a transformer sized for roughly 230 V phase-to-neutral service must not be reconnected across a higher phase-to-phase voltage without checking its primary rating. Second, multiplying each measured phase-to-neutral magnitude by √3 does not reproduce the actual phase-to-phase voltage during unbalance. If the protection must respond to real line-to-line voltage, sense those voltages directly with appropriately rated isolated channels, or compute them from synchronized waveform samples. Where no neutral exists, use isolated sensing rated for the actual phase-to-phase connection; the same isolated-divider front end used in three-phase energy metering is the reference architecture.
Where the signal chain creates false readings #
Trace each channel from the primary connection through the secondary, conditioning circuit, ADC pin, reference, and scaling math. A correct reading on one channel proves only that channel's path. The failure points:
- Primary connection: phase-to-neutral versus phase-to-phase mix-up gives a consistent scaling error and protects the wrong quantity.
- Secondary: wrong ratio, excessive loading, or an open return gives unexpected amplitude or a floating input.
- Conditioning circuit: missing divider, missing bias, or no return to controller ground produces clipping, negative excursions, or a channel that drifts with adjacent channels. The common mode of a phase-to-neutral vs phase-to-phase measurement also changes what the front end must reject, as it does in UPS phase-to-neutral and phase-to-phase compatibility.
- Reference and common: a shared reference that moves with supply or load makes several channels drift together.
- Channel selection: mux logic that selects the wrong channel or does not allow settling repeats values or contaminates them after switching.
Separate reference configuration from channel selection. Verify the intended analog-pin and reference arrangement against the PIC16F877 datasheet, then check the channel-selection logic independently. Neither setting repairs a missing return connection or an unsuitable conditioning circuit.
Locate the fault before touching software #
- De-energize, lock out, and verify absence of voltage on the sensing primaries before opening anything.
- Record the architecture: neutral availability, each primary connection, secondary ratings, reference source, conditioning method, and the quantity each channel is meant to represent.
- With power removed, trace each channel's return to the ADC ground. Confirm the isolated secondary circuits do not float and that the primary-to-secondary barrier is intact.
- Energize the sensing circuits only. Measure every secondary under its actual load and compare against the primary reading and the transformer ratio.
- Scope each ADC input relative to controller ground: check minimum, maximum, clipping, bias, and ripple against the input limits in the device datasheet.
- Trend the reference voltage together with the channel readings. Correlated movement across channels points to a shared supply, reference, or ground-path problem, not three independent phase changes.
- Bench-test the ADC: disconnect the conditioning outputs, apply known signals inside the documented input range, and test each channel alone, then in the normal multiplexing sequence.
If a channel reads correctly alone but shifts when sampled after another channel, the problem is source impedance and acquisition settling. The sampling capacitor must charge to the new input after each switch; a high-impedance divider output retains influence from the previously selected channel. Buffer each input or extend the acquisition time per the datasheet requirement before changing conversion timing.
Set the cutoffs from conditioned measurements #
Choose the conditioning method that produces the quantity the protection logic needs, then scale in firmware from a calibration at the working voltage, not from nameplate arithmetic alone. For the phase-to-neutral case with 9 V RMS secondaries at nominal voltage, a divider that maps the ±12.73 V peak to about ±2.5 V around a 2.5 V bias keeps every sample inside 0 to 5 V with margin; the firmware RMS value then compares against 219.4 V low and 254.0 V high. For a rectified design, calibrate the DC-to-RMS constant at both the low and high end, because diode loss is a larger fraction of the signal at low voltage. The decision in every case: fix the front end first, define the quantity second, scale the software last. Related front-end questions, such as why a control transformer secondary shows voltage to ground, follow the same trace-the-return rule.
Questions asked
Can I just rectify each secondary and read the DC with the ADC?
Yes, with a precision rectifier followed by a divider sized so the peak DC stays below the reference. A simple diode rectifier loses about 0.6 V across the diode and its output follows average, not RMS, so the scaling changes with waveform shape and must be calibrated against a true-RMS meter at the working voltage.
Why does a channel read correctly alone but drift when multiplexed with the others?
The ADC sampling capacitor must charge to the new input through the source impedance after each channel switch. If the conditioning output impedance is high, the previous channel's voltage contaminates the reading. Add a buffer or a larger sampling capacitor at each input and lengthen the acquisition time per the device datasheet's acquisition requirement.
Do I need a neutral conductor to measure three-phase voltage?
No. Without a neutral you measure phase-to-phase through isolated transformers rated for that full voltage, or you reconstruct phase quantities from synchronized samples of all three line-to-line voltages. A protective earth conductor must not be used as the voltage reference for sensing channels.
What isolation does a small step-down transformer give me?
It gives a primary-to-secondary barrier rated by its insulation class, typically reinforced insulation for mains work. Keep the barrier intact: do not tie the primary side to controller ground, and verify the transformer's isolation rating covers your system voltage in the manufacturer's datasheet.


