FAQ
TL;DR: Building a 3‑phase energy meter with distortion? One user targeted “100 harmonics” up to 5 kHz; “I am measuring up to 100 harmonics.” [Elektroda, Muhammad Ali, post #21667954]
Why it matters: Designers ask how to code real/reactive power with harmonics and handle peak/off‑peak tariffs in C for embedded LCD‑based meters.
Quick Facts
- Goal: real and reactive power under non‑linear loads; up to the 100th harmonic (~5 kHz). [Elektroda, Muhammad Ali, post #21667954]
- Toolchain noted: MikroC; LCD wired to PORTB RB0–RB5 in sample code. [Elektroda, aman Fatima, post #21667963]
- Review norm: share an algorithm/flow chart before code review. [Elektroda, Mark Harrington, post #21667962]
- Tariff ask: peak/off‑peak bands described as “range is 100–200.” [Elektroda, aman Fatima, post #21667961]
What does this thread try to achieve?
It documents a 3‑phase energy meter design that measures real and reactive power even with harmonics, with a target of up to the 100th harmonic (≈5 kHz). Requests include an algorithm, C code guidance, and tariff handling. [Elektroda, Muhammad Ali, post #21667954]
How do I approach three‑phase energy measurement when harmonics exist?
Define your measurement scope first: three voltages, three currents, and harmonics up to 5 kHz. Then outline an algorithm before coding. A clear flow chart was requested for effective help. Quote: “provide a flow chart.” [Elektroda, Mark Harrington, post #21667962]
What sampling bandwidth did the original target imply?
The goal cited “measuring up to 100 harmonics,” equating to components up to about 5 kHz in a 50 Hz system. Plan your anti‑aliasing and sampling accordingly, with headroom for filter roll‑off. This preserves high‑order harmonic energy. [Elektroda, Muhammad Ali, post #21667954]
What is MikroC in this context?
MikroC is the C compiler and IDE used in the shared snippet that drives an LCD via PIC microcontroller PORTB lines. If you adopt it, mirror the shown pin mapping or adjust library calls. [Elektroda, aman Fatima, post #21667963]
How should I structure my C code before posting for review?
Start with a flow chart covering sampling, per‑phase processing, accumulation windows, and tariff logic. Reviewers requested algorithm first to avoid paging through raw code. Quote: “provide a flow chart.” [Elektroda, Mark Harrington, post #21667962]
Can I see an example of LCD wiring used here?
Yes. The shared MikroC snippet maps LCD RS/EN to RB4/RB5 and data lines D4–D7 to RB0–RB3, with corresponding TRISB direction bits. Match wiring to your code or update the sbit bindings. [Elektroda, aman Fatima, post #21667963]
Why did the posted tariff code not compile?
It used invalid C identifiers and assignments, such as spaces in variable names (e.g., OffPeak hours) and comma misuse in assignments. Use underscores and proper types to resolve these syntax errors. [Elektroda, aman Fatima, post #21667963]
How were peak and off‑peak tariffs described?
One participant asked to calculate peak and off‑peak tariffs with a stated “range is 100–200.” Treat that as a user‑defined band and implement tiered logic accordingly. [Elektroda, aman Fatima, post #21667961]
What’s a simple three‑step plan to get useful help on this topic?
- Share a flow chart of your algorithm.
- Post minimal, compiling C code that matches the flow.
- State targets (e.g., “100 harmonics to 5 kHz”) and questions.
“Otherwise I’ve got to page through lines and lines of C code.” [Elektroda, Mark Harrington, post #21667962]
What exactly was the harmonic measurement goal here?
The goal was to cover linear and non‑linear loads while capturing real and reactive power with harmonics up to the 100th, i.e., components reaching roughly 5 kHz. That frames bandwidth and algorithm choices. [Elektroda, Muhammad Ali, post #21667954]
How should I phrase requests for algorithms or code on the forum?
State your planned method and share diagrams first. Helpers emphasized algorithm visibility before code to speed feedback. Quote: “I prefer to make life easier… I do need some participation.” [Elektroda, Mark Harrington, post #21667962]
What microcontroller display setup did the code imply?
An HD44780‑style LCD in 4‑bit mode, with explicit sbit mappings for control and data lines on PORTB. This pinning dictates both hardware wiring and library calls. Keep names consistent to avoid build errors. [Elektroda, aman Fatima, post #21667963]
What failure modes should I watch for in tariff code?
Watch for invalid identifiers, missing braces, and undeclared integers. In the snippet, misnamed variables and incomplete loops caused compile errors. Clean naming and strict scoping prevent such failures. [Elektroda, aman Fatima, post #21667963]
Who asked for harmonic‑aware power measurement and what was the scope?
Muhammad Ali requested three‑phase energy measurement for linear and non‑linear loads, with both real and reactive power, up to about 5 kHz (100 harmonics). [Elektroda, Muhammad Ali, post #21667954]
What should I provide if I can’t code the full C solution yet?
Post your theory, measurement plan, and a flow chart. A helper stressed that sharing the approach is essential for others to assist effectively with code later. [Elektroda, Mark Harrington, post #21667962]