Current and Voltage Sensing Design

1:54

Advanced (prev)
Chat History
Project
Calculator
Knowledge Base

Preparing guidance for user request.

Using Knowledge Base Tool.

Using Calculator Tool.

Using Calculator Tool.

Using Calculator Tool.

Planning guidance and queries.

1. Block-level diagram
   AC mains ─────┐                       ┌── H-bridge (4 × [IRLZ44N](https://www.flux.ai/search?type=components&q=IRLZ44N))
                 │                       │
                 │     [100 µH Inductor](https://www.flux.ai/search?type=components&q=100uH%20Inductor)
                 │                       │
      Injection ►●───────────────────────┴───► Load / Grid
                 │
                 │   (shunt branch)                 DC bus 24 – 48 V
                 │                                  │
                 │                     ┌───► [220 µF Capacitor](https://www.flux.ai/search?type=components&q=220uF%20Capacitor)
                 │                     │
    ┌────────────▼────────────┐  ┌─────▼───────────────────────────┐
    │  Sensors & Conditioning │  │      Power Inverter Stage       │
    │                         │  │ (PWM-driven H-bridge + LC path) │
    │ ┌─────────────────────┐ │  └─────────────────────────────────┘
    │ │ [ACS712ELCTR-30A-T] │─┤
    │ └─────────────────────┘ │
    │      (current)          │
    │ ┌─────────────────────┐ │
    │ │ R-R divider + RC    │─┤  (voltage)
    │ └─────────────────────┘ │
    └────────┬──────┬────────┘
             │      │  3.3 V analog, VREF=3.3 V/2
             ▼      ▼
      [TLV9062](https://www.flux.ai/search?type=components&q=TLV9062)  (dual op-amp: bias & anti-alias)
             │
             ▼              ┌───────────────────────────────────────┐
      12-bit ADC0/1  ◄──────┤           Raspberry Pi Pico           │
                            │  – Goertzel @ 250 Hz (block N=100)    │
                            │  – PI current loop (2 kHz)            │
                            │  – PWM (50 kHz) on GPIO 2/3 (A/B)     │
                            └───────┬──────────────┬────────────────┘
                                    │              │
              [IR2110](https://www.flux.ai/search?type=components&q=IR2110)   (high/low-side gate driver, isolated 12 V)
                                    │
                                    ▼
                                  Gates

2. Signal-conditioning notes


ChannelSensorFull-scale designAnti-alias RCNotes (Flux KB: “ADC filter design”)
CurrentACS712ELCTR-30A-T (66 mV / A)±30 A ⇒ ±1.98 V around 1.65 V mid-supplyR = 1 kΩ, C = 330 nF → fc ≈ 480 HzKeeps aliasing below Fs/10 yet passes 250 Hz with <3 dB loss.
VoltageDivider 230 VRMS→±2 V (ratio ≈ 1:75)±325 Vpk ⇒ ±2.17 V around 1.65 VR = 4.7 kΩ, C = 100 nF → fc ≈ 340 HzDivider impedance (4.7 k ∥ 75 Ω) ≤ 4 kΩ, within Pico ADC acquisition spec.
Additional conditioning (Flux KB):
  • Place 0.1 µF bypass at each op-amp rail.
  • Add series 33 Ω between op-amp and ADC pin to isolate ADC sampling kick.

3. Goertzel implementation (250 Hz, Fs = 5 kHz, N = 100)
Constants
k    =  N·f / Fs = 100·250 / 5000 = 5           (integer bin)
w0   = 2π·k / N  = π/10  = 0.314159265 rad
coeff= 2·cos(w0) = 1.902113032  (mathematical constant)
MicroPython

Python


import array, math, rp2, machine

FS   = 5000          # Hz
N    = 100           # samples / block
K    = 5
COEFF= 1.902113032   # 2*cos(pi/10)

adc  = machine.ADC(0)
timer= machine.Timer()

samples = array.array('H', [0]*N)   # raw 12-bit samples
idx = 0
ready = False

def adc_isr(t):
    global idx, ready
    samples[idx] = adc.read_u16()    # 0…65535
    idx += 1
    if idx >= N:
        idx = 0
        ready = True

timer.init(freq=FS, mode=machine.Timer.PERIODIC, callback=adc_isr)

def goertzel(buf):
    s_prev = s_prev2 = 0.0
    for x in buf:
        # scale 0…65535 → ±1
        v = (x/65535.0 - 0.5)*2
        s = v + COEFF*s_prev - s_prev2
        s_prev2, s_prev = s_prev, s
    real = s_prev - s_prev2*math.cos(math.pi/10)
    imag = s_prev2*math.sin(math.pi/10)
    mag  = math.sqrt(real*real + imag*imag)
    phase= math.atan2(imag, real)
    return mag, phase           # radians

while True:
    if ready:
        ready = False
        mag, ph = goertzel(samples)
        # Invert phase for compensation
        ref_phase = ph + math.pi
        # Store for PI current loop
C-like pseudocode (SDK)

C


#define FS     5000
#define N      100
#define K      5
#define COEFF  1.902113032   // 2*cos(pi/10)

void goertzel(uint16_t *buf, double *mag, double *phase)
{
    double s_prev = 0, s_prev2 = 0;
    for (int i = 0; i < N; i++) {
        double v = ((double)buf[i]/65535.0 - 0.5)*2.0;
        double s = v + COEFF*s_prev - s_prev2;
        s_prev2 = s_prev;
        s_prev  = s;
    }
    double real = s_prev - s_prev2*cos(M_PI/10.0);
    double imag = s_prev2*sin(M_PI/10.0);
    *mag   = sqrt(real*real + imag*imag);
    *phase = atan2(imag, real);
}

4. Compensating current synthesis
i_ref(t) = -Î₅ * sin(2π·5f₀·t + φ₅)
  • Î₅ , φ₅ are Goertzel magnitude & phase.
  • Generate 5000 Sa/s lookup table for one 20 ms block (100 points).
  • Feed into PI loop at 5 kHz.

5. PI current controller
e  = i_ref − i_meas
d  = Kp*e + Ki*∫e dt
duty = clamp( 0.5 + d , 0 … 0.95 )
Start with Kp = 0.2, Ki = 50 (tune per section 9). Update at 2 kHz (every 2ⁿᵈ sample) to ease MCU load.

6. Complete MicroPython prototype

Python


from machine import Pin, PWM
import math, array, machine, rp2

# === USER SETTINGS ===
FS   = 5000
N    = 100
Kp   = 0.2
Ki   = 50
PWM_FREQ = 50000        # 50 kHz switching
COEFF= 1.902113032

# === HARDWARE ===
adc_i = machine.ADC(0)  # current
pwm_a = PWM(Pin(2))
pwm_b = PWM(Pin(3))
for p in (pwm_a, pwm_b):
    p.freq(PWM_FREQ)

duty_a = duty_b = 32768
pwm_a.duty_u16(duty_a)
pwm_b.duty_u16(duty_b)

samples = array.array('H', [0]*N)
idx = 0; ready = False
integrator = 0.0

def tim_cb(t):
    global idx, ready
    samples[idx] = adc_i.read_u16()
    idx += 1
    if idx >= N:
        idx = 0
        ready = True

machine.Timer().init(freq=FS, mode=machine.Timer.PERIODIC, callback=tim_cb)

def goertzel(buf):
    s_prev = s_prev2 = 0.0
    for x in buf:
        v = (x/65535 - 0.5)*2
        s = v + COEFF*s_prev - s_prev2
        s_prev2, s_prev = s_prev, s
    real = s_prev - s_prev2*math.cos(math.pi/10)
    imag = s_prev2*math.sin(math.pi/10)
    mag  = math.sqrt(real*real + imag*imag)
    phase= math.atan2(imag, real)
    return mag, phase

while True:
    if ready:
        ready = False
        mag, ph = goertzel(samples)
        # Build one-cycle reference
        ref = [ -mag*math.sin(2*math.pi*5*i/N + ph) for i in range(N) ]

        # PI loop over the same block
        for i in range(N):
            i_meas = (samples[i]/65535 - 0.5)*2*30   # back-scale to amperes
            err = ref[i] - i_meas
            integrator += err / FS
            duty = 0.5 + Kp*err + Ki*integrator
            duty_clamped = min(max(duty, 0.05), 0.95)
            pwm_val = int(duty_clamped*65535)
            pwm_a.duty_u16(pwm_val)
            pwm_b.duty_u16(65535 - pwm_val)
Limitations: MicroPython timer jitter ≈ ±5 µs. For production, port ISR & PI loop to C SDK / PIO.

7. PWM & gate-drive guidance


ParameterRecommendation (bench ≤ 100 W)
Fsw50 kHz (far above 250 Hz target, below IR2110 10 MHz limit)
Dead-time1 µs (set in PWM hardware)
Gate driverIR2110 with local 100 nF + 10 µF decoupling (Flux KB: “designing gate drive circuits”)
Vgs10–12 V isolated DC/DC; include 10 Ω series gate resistors & 100 kΩ pull-down (Flux KB)
MOSFETsLogic-level IRLZ44N or similar, RDS(on) ≈ 20 mΩ

8. Stepwise, safe test plan
  1. Desk-check
    • Power Pico from USB only; probe PWM pins – expect 50 kHz 50 % duty.
  2. Gate-driver isolated test
    • Feed IR2110 with separate 12 V; no MOSFETs. Verify dead-time & correct phase.
  3. Low-voltage H-bridge
    • 12 V DC bus, resistive dummy load, no grid tie. Confirm PWM duty follows PI output without shoot-through.
  4. Sensor calibration
    • Inject 1 A RMS through [ACS712ELCTR-30A-T]; record ADC counts. Adjust scale in firmware.
  5. FFT scope check
    • With mains waveform (isolated), log current spectrum; verify 5th-harmonic magnitude matches Goertzel result.
  6. Closed-loop bench
    • 24 V DC bus, 50 Hz 50 W inverter output into isolated autotransformer → load. Observe current before/after; 5th component should drop > 10 dB.
  7. Incremental power (strict isolation)
    • Raise DC bus & load in 10 W steps. Monitor MOSFET temperature (< 70 °C) and bus ripple (< 10 %).
⚠️ Mains safety: keep DUT on an isolation transformer; add fuse + RCD; never connect scope ground to live mains.

9. Tuning & 60 Hz adaptation


Item50 Hz (given)60 Hz variant
ffund50 Hz60 Hz
5th harmonic250 Hz300 Hz
Keep Fs5 kHz6 kHz (gives 100 samples/block)
k (Goertzel)55
w02π·5/100 = π/102π·5/100 = π/10 (same)
Re-compute COEFFunchangedunchanged
PI gainsIncrease Kp, Ki by ~20 % to match 20 % higher electrical frequency.
Flux knowledge base reminds:
  • RC anti-alias should keep fc ≤ Fs/10.
  • Gate-drive resistors & pull-downs are mandatory to avoid floating gates when MCU resets.

Ready to implement
You now have:
Stay within the bench-level limits and follow each test step before connecting to real mains. Good luck with your Active Power Filter!
Request block diagram
Op-amp part search
RC filter C calculation
Timer interrupt code
PWM C pseudocode
151 days

Ready.


GP9
GP20
GND
GND
GND
GP0
RUN
GP18
GP21
GND
3V3_EN
GP3
GP1
GP14
GP19
3V3
GP27
ADC_VREF
GND
VBUS
GP11
GND
GP4
GP16
GP17
GP2
GP13
GP10
GP28
GND
GP26
GP8
GP5
GND
GP12
VSYS
GP22
GP6
GP15
GP7


  • Ground
    A common return path for electric current. Commonly known as ground.
  • Net Portal
    Wirelessly connects nets on schematic. Used to organize schematics and separate functional blocks. To wirelessly connect net portals, give them same designator. #portal
  • Power Net Portal
    Wirelessly connects power nets on schematic. Identical to the net portal, but with a power symbol. Used to organize schematics and separate functional blocks. To wirelessly connect power net portals, give them the same designator. #portal #power
  • Generic Resistor
    A generic fixed resistor for rapid developing circuit topology. Save precious design time by seamlessly add more information to this part (value, footprint, etc.) as it becomes available. Standard resistor values: 1.0Ω 10Ω 100Ω 1.0kΩ 10kΩ 100kΩ 1.0MΩ 1.1Ω 11Ω 110Ω 1.1kΩ 11kΩ 110kΩ 1.1MΩ 1.2Ω 12Ω 120Ω 1.2kΩ 12kΩ 120kΩ 1.2MΩ 1.3Ω 13Ω 130Ω 1.3kΩ 13kΩ 130kΩ 1.3MΩ 1.5Ω 15Ω 150Ω 1.5kΩ 15kΩ 150kΩ 1.5MΩ 1.6Ω 16Ω 160Ω 1.6kΩ 16kΩ 160kΩ 1.6MΩ 1.8Ω 18Ω 180Ω 1.8KΩ 18kΩ 180kΩ 1.8MΩ 2.0Ω 20Ω 200Ω 2.0kΩ 20kΩ 200kΩ 2.0MΩ 2.2Ω 22Ω 220Ω 2.2kΩ 22kΩ 220kΩ 2.2MΩ 2.4Ω 24Ω 240Ω 2.4kΩ 24kΩ 240kΩ 2.4MΩ 2.7Ω 27Ω 270Ω 2.7kΩ 27kΩ 270kΩ 2.7MΩ 3.0Ω 30Ω 300Ω 3.0KΩ 30KΩ 300KΩ 3.0MΩ 3.3Ω 33Ω 330Ω 3.3kΩ 33kΩ 330kΩ 3.3MΩ 3.6Ω 36Ω 360Ω 3.6kΩ 36kΩ 360kΩ 3.6MΩ 3.9Ω 39Ω 390Ω 3.9kΩ 39kΩ 390kΩ 3.9MΩ 4.3Ω 43Ω 430Ω 4.3kΩ 43KΩ 430KΩ 4.3MΩ 4.7Ω 47Ω 470Ω 4.7kΩ 47kΩ 470kΩ 4.7MΩ 5.1Ω 51Ω 510Ω 5.1kΩ 51kΩ 510kΩ 5.1MΩ 5.6Ω 56Ω 560Ω 5.6kΩ 56kΩ 560kΩ 5.6MΩ 6.2Ω 62Ω 620Ω 6.2kΩ 62KΩ 620KΩ 6.2MΩ 6.8Ω 68Ω 680Ω 6.8kΩ 68kΩ 680kΩ 6.8MΩ 7.5Ω 75Ω 750Ω 7.5kΩ 75kΩ 750kΩ 7.5MΩ 8.2Ω 82Ω 820Ω 8.2kΩ 82kΩ 820kΩ 8.2MΩ 9.1Ω 91Ω 910Ω 9.1kΩ 91kΩ 910kΩ 9.1MΩ #generics #CommonPartsLibrary
  • Generic Capacitor
    A generic fixed capacitor ideal for rapid circuit topology development. You can choose between polarized and non-polarized types, its symbol and the footprint will automatically adapt based on your selection. Supported options include standard SMD sizes for ceramic capacitors (e.g., 0402, 0603, 0805), SMD sizes for aluminum electrolytic capacitors, and through-hole footprints for polarized capacitors. Save precious design time by seamlessly add more information to this part (value, footprint, etc.) as it becomes available. Standard capacitor values: 1.0pF 10pF 100pF 1000pF 0.01uF 0.1uF 1.0uF 10uF 100uF 1000uF 10,000uF 1.1pF 11pF 110pF 1100pF 1.2pF 12pF 120pF 1200pF 1.3pF 13pF 130pF 1300pF 1.5pF 15pF 150pF 1500pF 0.015uF 0.15uF 1.5uF 15uF 150uF 1500uF 1.6pF 16pF 160pF 1600pF 1.8pF 18pF 180pF 1800pF 2.0pF 20pF 200pF 2000pF 2.2pF 22pF 20pF 2200pF 0.022uF 0.22uF 2.2uF 22uF 220uF 2200uF 2.4pF 24pF 240pF 2400pF 2.7pF 27pF 270pF 2700pF 3.0pF 30pF 300pF 3000pF 3.3pF 33pF 330pF 3300pF 0.033uF 0.33uF 3.3uF 33uF 330uF 3300uF 3.6pF 36pF 360pF 3600pF 3.9pF 39pF 390pF 3900pF 4.3pF 43pF 430pF 4300pF 4.7pF 47pF 470pF 4700pF 0.047uF 0.47uF 4.7uF 47uF 470uF 4700uF 5.1pF 51pF 510pF 5100pF 5.6pF 56pF 560pF 5600pF 6.2pF 62pF 620pF 6200pF 6.8pF 68pF 680pF 6800pF 0.068uF 0.68uF 6.8uF 68uF 680uF 6800uF 7.5pF 75pF 750pF 7500pF 8.2pF 82pF 820pF 8200pF 9.1pF 91pF 910pF 9100pF #generics #CommonPartsLibrary
  • Generic Inductor
    A generic fixed inductor for rapid developing circuit topology. *You can now change the footprint and 3D model at the top level anytime you want. This is the power of #generics
  • Terminal
    Terminal
    An electrical connector acting as reusable interface to a conductor and creating a point where external circuits can be connected.
  • RMCF0805JT47K0
    47 kOhms ±5% 0.125W, 1/8W Chip Resistor 0805 (2012 Metric) Automotive AEC-Q200 Thick Film #forLedBlink
  • 875105359001
    10uF Capacitor Aluminum Polymer 20% 16V SMD 5x5.3mm #forLedBlink #commonpartslibrary #capacitor #aluminumpolymer #radialcan
  • CTL1206FYW1T
    Yellow 595nm LED Indication - Discrete 1.7V 1206 (3216 Metric) #forLedBlink

Inspect

Raspberry Pi Pico

Raspberry Pi Pico
Description

Created
Last updated by jwace81
Forked from
1 Contributor(s)
jwace81

Controls

Properties

Part Type
Manufacturer Part Number
SC0915
Designator Prefix
Rpi

Availability & Pricing

DPNStockQty 1
10$5.40
210K–11K$4.00–$4.00002
11$6.2575
16.2K$4.00

Assets