**1. what “AC current control” really means** A [microcontroller](https://www.ampheo.com/c/microcontrollers) cannot directly control AC current. Instead, it controls switching, phase, or amplitude, and the external power circuit converts that into a regulated RMS current. ![企业微信截图_20260126180737](https://hackmd.io/_uploads/r1sbT3EUWg.png) At system level, AC current control always has three functional blocks: 1. AC current sensing (feedback) 2. Power modulation element (how you change current) 3. Control algorithm in the MCU (how you decide how much current) This forms a closed-loop current control system. **2. Ways to control AC current (conceptual methods)** **Method A: Phase-angle control (TRIAC-based)** You change when the AC waveform turns on each half-cycle. * Later firing angle → lower RMS current * Earlier firing angle → higher RMS current ✔ Simple ✔ Cheap ✖ Distorts waveform ✖ EMI, poor for precision mA control **Method B: Burst / cycle control (integral cycle)** You turn whole AC cycles on and off. * 10 cycles ON, 10 cycles OFF → ~50% RMS current * Works best with thermal loads ✔ Low EMI ✖ Slow response ✖ Poor for fast or inductive loads **Method C: High-frequency PWM + isolation (best for precision)** You rectify AC, then use: * [MOSFET](https://www.onzuu.com/category/fets-mosfets) / [IGBT](https://www.onzuu.com/category/igbts) * High-frequency PWM * Current feedback The output current is reconstructed as controlled AC current. ✔ Accurate mA control ✔ Clean waveform ✔ Works with inductive loads ✖ More complex **3. Current sensing (how the MCU “knows” the current)** **Option 1: Shunt resistor (low-value resistor)** * Measure voltage drop: V = I × R * Use an isolated amplifier for safety ✔ Accurate ✖ Needs isolation for AC mains **Option 2: Current transformer (CT)** * Naturally isolated * Good for AC only ✔ Safe ✖ Not good at very low mA unless designed carefully **Option 3: Hall-effect current sensor** * Measures magnetic field * Isolated, works for AC ✔ Easy to use ✖ Offset drift at low mA **4. Control loop in the MCU (core idea)** The MCU does not control voltage directly — it controls current error. Typical loop: 1. Measure AC current → convert to RMS value 2. Compare to target current (e.g. 20 mA) 3. Calculate error 4. Adjust: * TRIAC firing angle, or * PWM duty cycle 5. Repeat every cycle This is often implemented as a PI controller. **5. Safety requirement (non-negotiable)** If this involves mains AC: * You MUST use galvanic isolation * Use optocouplers, isolated amplifiers, or transformers * MCU ground must never touch live AC **Practical Examples (with real MCU + circuit choices)** **Example 1: 0–20 mA AC current control using TRIAC (basic, low cost)** Use case: AC lamp, heater, resistive load **Components** * MCU: [STM32F103C8T6](https://www.ampheo.com/product/stm32f103c8t6-131876) * TRIAC: [BTA16-600](https://www.onzuu.com/search/BTA16-600) * Optotriac driver: [MOC3021](https://www.onzuu.com/product/texas-instruments-moc3021-3462257) (non-zero-cross) * Current sense: Small CT or shunt + isolated amplifier * Zero-cross detector: Optocoupler (e.g. H11AA1-type) **How it works** * MCU detects zero crossing * Waits a calculated delay * Triggers TRIAC gate * Adjusts firing angle to control RMS current ⚠ Accuracy below ~10 mA is limited. **Example 2: Precision mA-level AC current source (recommended)** Use case: [Sensors](https://www.ampheo.com/c/sensors), calibration equipment, medical / industrial signals **Architecture** AC → Rectifier → DC bus → PWM current regulator → Reconstructed AC **Components** * MCU: [STM32G030F6P6](https://www.ampheo.com/product/stm32g030f6p6-129893) * Power stage: MOSFET (e.g. logic-level N-MOSFET) * Current sense: 0.1 Ω shunt + isolated amplifier * Isolation: Gate driver or isolated DC/DC * Output: Controlled sinusoidal current **How control works** * MCU generates sine reference * Uses PWM to regulate current * Current loop ensures exact mA output ✔ Accuracy down to <1 mA ✔ Low distortion **Example 3: Isolated AC current loop (4–20 mA AC / industrial)** Use case: Industrial signaling over AC **Components** * MCU: [STM32F407](https://www.ampheo.com/search/STM32F407) * Isolated amplifier: precision current sense amplifier * Power switch: IGBT or MOSFET * Isolation: Transformer or isolated gate driver **Control** * Digital setpoint → RMS current * MCU computes waveform and regulates current **6. MCU features that matter for AC current control** | Feature | Why it matters | | -------------------------- | -------------------------- | | ADC with good resolution | Accurate current sensing | | Timer with capture/compare | Phase control / PWM | | DMA | Stable waveform generation | | Math capability | RMS calculation | | Isolation support | Safety | **7. Summary (engineering takeaway)** A [microcontroller](https://www.ampheoelec.de/c/microcontrollers) never controls AC current directly. It controls switching behavior, and a closed-loop circuit turns that into regulated AC current. **Quick selection guide** * Cheap, rough control → TRIAC phase control * Thermal loads → Burst control * Precise mA current → Rectify + PWM + current feedback