commit 0c8b61b27fb4bd8e7428923de397c19b4725699c Author: Michael Sloan Date: Thu Sep 3 17:12:25 2026 -0400 Initial commit: Phase Angle Fixer with README, AGENTS.md, and Cursor rules. Co-authored-by: Cursor diff --git a/.cursorrules b/.cursorrules new file mode 100644 index 0000000..6373427 --- /dev/null +++ b/.cursorrules @@ -0,0 +1,6 @@ +# Phase Angle Fixer — Cursor rules + +- This repo is a single-page web app: one file, `index.html` (HTML + CSS + JS). No build step, no package.json. +- Full project summary and where to edit: see `AGENTS.md`. +- Phase angle logic: angles in degrees, normalized to (-180, 180]; ABC = Vb-Va ≈ -120°, Vc-Va ≈ +120°. V-I angle φ = I − V; pf = cos(φ). +- When editing, keep all UI and logic in index.html; do not split into separate JS/CSS files unless the user asks. diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4cf4445 --- /dev/null +++ b/.gitignore @@ -0,0 +1,21 @@ +# OS +.DS_Store +Thumbs.db +desktop.ini + +# Editor / IDE +.idea/ +.vscode/ +*.swp +*.swo +*~ + +# Local / env (if you add later) +.env +.env.local +*.local + +# Logs / temp +*.log +tmp/ +temp/ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..28efc4a --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,48 @@ +# Phase Angle Fixer — AI / Agent Summary + +This file helps AI assistants and tools understand the repo quickly (project “DNA”). + +## What this repo is + +- **Single-file web app** (`index.html`): HTML + CSS + JavaScript, no build step, no backend. +- **Purpose:** Check and fix three-phase power meter **phase angles** (Va, Ia, Vb, Ib, Vc, Ic). It suggests wiring fixes, phase rotation (ABC vs ACB), CT/PT polarity, meter settings (CT/PT ratio, phase correction), and shows phasor + time-domain plots. +- **Users:** People who commission or troubleshoot power meters and need to verify/correct phase angles and phase sequence. + +## Tech stack + +- Vanilla JS (no frameworks). +- No package manager; fonts loaded from Google Fonts (DM Sans, JetBrains Mono). +- All logic and UI in one file: `index.html`. + +## Key concepts in code + +- **Angle convention:** Angles in degrees; normalized to (−180°, 180°] (NASPI-style). Difference = subtract then wrap. +- **Phase sequence:** ABC (positive) = Vb−Va ≈ −120°, Vc−Va ≈ +120°. ACB (negative) = opposite; also “B and C swapped” pattern. +- **V–I angle:** φ = I − V (phasor difference). pf = cos(φ). Used for power factor, polarity (≈ ±180° → reversed CT), and unity-PF meter correction. +- **Meter setup:** Optional CT ratio, PT ratio, nominal voltage, CT type (standard / Rogowski / residual). Multiplier = (CT ratio) × (PT ratio). These are used in fix suggestions when present. + +## File roles + +| File | Role | +|------------|------| +| `index.html` | Entire app: inputs, analysis, charts (radial + sinusoidal), fix list, ref notes. | +| `README.md` | Human-facing overview, run instructions, references, structure. | +| `AGENTS.md` | This file; for AI/agents. | +| `.gitignore` | Ignore OS/editor/temp files. | +| `LICENSE` | MIT. | + +## How to run + +Open `index.html` in a browser (file:// or any static server). No install. + +## Where to change things + +- **UI copy / labels:** In `index.html`, in the `` card sections and in JS strings (e.g. `suggestion`, `msg`). +- **Phase logic:** In `index.html`, inside `analyze()`: `rotationOk`, `near()`, swap detection, voltage balance, CT polarity, unity-PF fixes. +- **Meter setup / multiplier:** `getMeterSetup()` and the block that writes `meterMultiplierWrap` and `rctNote`. +- **Charts:** `drawRadialChart(norm)` and `drawLineChart(norm)`; both use `CHART_ITEMS` and normalized angles. +- **References / links:** In ref notes and formula blocks in `index.html`; also listed in README. + +## References the app cites + +NASPI TR-006, electronics-tutorials.ws phasors, learnabout-electronics phase/phasors, NJIT ECE 449 Lab 3 (phase sequence), EEP (phase sequence CW/CCW), Electrical Ampere (phase angle). All URLs are in the app and in README. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..db130d2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Phase Angle Fixer contributors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..00e379c --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# Phase Angle Fixer + +A single-page web app for checking and correcting **voltage and current phase angles** on three-phase power meters. Enter angles for Va, Ia, Vb, Ib, Vc, Ic and get diagnostics, wiring suggestions, meter settings, and phasor/time-domain visuals. + +## Features + +- **Phase angles (degrees)** — Input Va, Ia, Vb, Ib, Vc, Ic with optional CT/PT ratios and nominal voltage +- **Phase rotation** — Expects ABC (positive sequence): Vb−Va ≈ −120°, Vc−Va ≈ +120°; detects ACB or B/C swap +- **V–I phase angle & power factor** — φ = I − V, pf = cos(φ); labels resistive / inductive / capacitive +- **Unity PF mode** — Toggle “Expect close to unity power factor” for CT polarity (positive/negative) and meter phase correction suggestions +- **Wiring & CT/PT** — Suggestions for physical wiring, CT on wrong phase, S1/S2 polarity, and meter CT/PT ratio +- **Meter setup** — Optional CT ratio, PT ratio, nominal voltage, CT type (standard / Rogowski / residual); computed meter multiplier +- **Angle views** — Phasor diagram (radial) and sinusoidal waveform (time domain) +- **References** — Logic follows NASPI TR-006, electronics-tutorials phasors, NJIT Lab 3 phase sequence, EEP CW/CCW, Electrical Ampere + +## How to run + +No build step. Open in a browser: + +```bash +# From repo root +open index.html +# or +start index.html +``` + +Or drag `index.html` into a browser, or use a local server (e.g. `npx serve .`). + +## Project structure + +``` +. +├── README.md # This file +├── AGENTS.md # AI / agent-oriented project summary +├── index.html # Single-file app (HTML, CSS, JS) +├── .gitignore +└── LICENSE # MIT +``` + +## References (embedded in app) + +- [NASPI TR-006](https://www.naspi.org/sites/default/files/reference_documents/naspi_2016_tr_006_phase_angle_calculations_final.pdf) — Phase angle calculations +- [Electronics-Tutorials: Phasors](https://www.electronics-tutorials.ws/accircuits/phasors.html) +- [Learnabout-Electronics: Phase and Phasors](https://learnabout-electronics.org/ac_theory/ac_ccts.php) +- [NJIT ECE 449 Lab 3: Phase Sequence](https://ecelabs.njit.edu/ece449/lab3.php) +- [EEP: Phase sequence CW/CCW](https://electrical-engineering-portal.com/proper-phase-sequence-cw-ccw-electric-motors-generators) +- [Electrical Ampere: Phase angle](https://electricalampere.com/phase-angle/) + +## License + +MIT — see [LICENSE](LICENSE). diff --git a/index.html b/index.html new file mode 100644 index 0000000..36cc9f2 --- /dev/null +++ b/index.html @@ -0,0 +1,993 @@ + + + + + + Phase Angle Fixer — Power Meter + + + + + + +
+

Phase Angle Fixer

+

Enter voltage and current phase angles (degrees) for each phase. Uses ±180° convention per NASPI TR-006.

+ +
+

Phase angles (degrees)

+
+
+ +
+
Vₐ
+
Iₐ
+
+
+
+ +
+
Vᵦ
+
Iᵦ
+
+
+
+ +
+
Vc
+
Ic
+
+
+
+
+ +
+

When on, suggests positive/negative CT (reversed polarity) when V−I angle is near ±180°.

+
+ +
+

Meter / transformer setup

+

Optional. Used for multiplier and to tailor fix suggestions (e.g. “set CT ratio to 100:5”).

+
+
+ +
+ + : + +
+
+
+ +
+ + : + +
+
+
+ + +
+
+ + +
+ +
+
+
+ +
+

Summary — what needs fixing

+
+
+
+ +
+

V–I phase angle & power factor

+

Phase angle φ = I − V (phasor difference). Power factor pf = cos(φ). Per phasor convention: positive φ = current lags voltage (inductive); negative φ = current leads voltage (capacitive). Resistive: φ ≈ 0°.

+
+
+ Phase angle & phasors
+ Electronics-Tutorials: Phasors — v(t) = Vm cos(ωt + θ) ↔ V∠θ; lead = +θ, lag = −θ; CCW, 0° = real axis.
+ Learnabout-Electronics: Phase and Phasors — phase shift, phasor diagrams and calculations (AC theory).
+ Electrical Ampere — pf = cos(φ), φ = cos⁻¹(pf); φ = tan⁻¹(X/R); φ = 360°×(Δt/T). +
+
+ +
+

Angle views

+

Per phasor convention: each quantity is a phasor (magnitude ∠ phase); 0° = right (real axis), CCW = positive angle.

+
+
+

Phasor diagram (radial)

+ +
+
+
+

Sinusoidal waveform (time domain)

+ +
+
+
+
+ +
+

Normalized angles (±180°) & differences

+ + + + + + + + + + + + +
PhaseV enteredI enteredV normI normV–I angle (PF)
+

Angles: Subtract then wrap to (−180°, 180°] (phasor angle difference; phasors, phase & phasors). Phase sequence: We expect ABC (positive sequence): Va reference 0°, Vb ≈ −120° (lagging), Vc ≈ +120°; so Vb−Va ≈ −120°, Vc−Va ≈ +120°. ACB (negative sequence) gives Vb−Va ≈ +120°, Vc−Va ≈ −120°. CW/CCW can mean motor rotation (NJIT Lab 3: abc = CW positive, acb = CCW negative) or phasor diagram (EEP: ABC = CCW, ACB = CW)—conventions vary. Phase sequence affects motor direction, paralleling transformers, and two-wattmeter method.

+ +
+
+ + + +