Rewire GPIO↔HMC472A so GPIO(n) = step bit (n-1): GPIO1→V6(0.5dB), GPIO2→V5(1dB), ... GPIO6→V1(16dB) This enables single-instruction GPIO updates: GPIO.out_w1tc = (step & 0x3F) << 1 GPIO.out_w1ts = (~step) & 0x7E Replaces 28-line loop with 4-line bitwise code.
128 lines
5.6 KiB
Markdown
128 lines
5.6 KiB
Markdown
# HMC472A Attenuator Controller Wiring
|
||
|
||
## Connection Diagram
|
||
|
||

|
||
|
||
## Pin Mapping (Optimized for Bitwise Ops)
|
||
|
||
The wiring is arranged so GPIO number = step bit position + 1, enabling single-instruction bitwise operations in firmware.
|
||
|
||
| ESP32-S2 Mini | HMC472A Module | Step Bit | Attenuation |
|
||
|---------------|----------------|----------|-------------|
|
||
| GPIO1 | V6 | Bit 0 (LSB) | 0.5 dB |
|
||
| GPIO2 | V5 | Bit 1 | 1 dB |
|
||
| GPIO3 | V4 | Bit 2 | 2 dB |
|
||
| GPIO4 | V3 | Bit 3 | 4 dB |
|
||
| GPIO5 | V2 | Bit 4 | 8 dB |
|
||
| GPIO6 | V1 | Bit 5 (MSB) | 16 dB |
|
||
| 5V (VBUS) | +5V | — | Power |
|
||
| GND | GND | — | Ground |
|
||
|
||
### Why This Mapping?
|
||
|
||
```c
|
||
// Old approach (loop required):
|
||
for (int i = 0; i < 6; i++) {
|
||
pin = ATTEN_PINS[5-i]; // Reverse mapping
|
||
if (step & (1 << i)) set_low(pin);
|
||
}
|
||
|
||
// New approach (pure bitwise):
|
||
GPIO.out_w1tc = (step & 0x3F) << 1; // Set LOW where step=1
|
||
GPIO.out_w1ts = (~step & 0x3F) << 1 & 0x7E; // Set HIGH where step=0
|
||
```
|
||
|
||
The step value bits map directly to GPIO register positions. No loop, no lookup table.
|
||
|
||
## HMC472A Module Header Pinout
|
||
|
||
The 8-pin header on the HMC472A module (top to bottom when viewing from component side):
|
||
|
||
| Pin | Signal | ESP32 GPIO | Description |
|
||
|-----|----------|------------|--------------------------|
|
||
| 1 | +5V | 5V VBUS | Power supply (+5V DC) |
|
||
| 2 | V6 | GPIO1 | 0.5 dB (step bit 0, LSB) |
|
||
| 3 | V5 | GPIO2 | 1 dB (step bit 1) |
|
||
| 4 | V4 | GPIO3 | 2 dB (step bit 2) |
|
||
| 5 | V3 | GPIO4 | 4 dB (step bit 3) |
|
||
| 6 | V2 | GPIO5 | 8 dB (step bit 4) |
|
||
| 7 | V1 | GPIO6 | 16 dB (step bit 5, MSB) |
|
||
| 8 | GND | GND | Ground |
|
||
|
||
## Logic Levels
|
||
|
||
**Active-LOW control:**
|
||
- **LOW (0V)** = Attenuate (apply the dB value)
|
||
- **HIGH (3.3V or 5V)** = Pass (0 dB contribution)
|
||
|
||
The HMC472A accepts 0–5V TTL/CMOS logic. The ESP32-S2's 3.3V GPIO output is fully compatible.
|
||
|
||
## Attenuation Examples
|
||
|
||
| Step | Binary | GPIO State (1-6) | Total Attenuation |
|
||
|------|------------|------------------|-------------------|
|
||
| 0 | `0b000000` | `HHHHHH` | 0 dB |
|
||
| 1 | `0b000001` | `LHHHHH` | 0.5 dB |
|
||
| 5 | `0b000101` | `LHLHHH` | 2.5 dB |
|
||
| 31 | `0b011111` | `LLLLLH` | 15.5 dB |
|
||
| 63 | `0b111111` | `LLLLLL` | 31.5 dB |
|
||
|
||
Formula: `attenuation = step × 0.5 dB` where step = 0–63
|
||
|
||
## Wiring Diagram (Text)
|
||
|
||
```
|
||
ESP32-S2 Mini HMC472A Module
|
||
(Left Header) (8-pin Header)
|
||
|
||
3V3 ─┤ 1 ┌─────┐
|
||
──────────────────────────────┐ │ +5V │← 1
|
||
GPIO1 ─┤ 2 ───────────────────│ V6 │← 2 (0.5 dB)
|
||
GPIO2 ─┤ 3 ───────────────────│ V5 │← 3 (1 dB)
|
||
GPIO3 ─┤ 4 ───────────────────│ V4 │← 4 (2 dB)
|
||
GPIO4 ─┤ 5 ───────────────────│ V3 │← 5 (4 dB)
|
||
GPIO5 ─┤ 6 ───────────────────│ V2 │← 6 (8 dB)
|
||
GPIO6 ─┤ 7 ───────────────────│ V1 │← 7 (16 dB)
|
||
GND ─┤ 8 ───────────────────│ GND │← 8
|
||
└─────┘
|
||
(Right Header)
|
||
5V ─┤ 16 ─────────────────┘ (to +5V)
|
||
```
|
||
|
||
**Note:** The diagram shows straight-through wiring (no crossovers) because the optimized mapping aligns GPIO numbers with the module header in reverse order.
|
||
|
||
## ESP32-S2 Mini Physical Pinout
|
||
|
||
```
|
||
┌─────────────────┐
|
||
│ USB-C │
|
||
└─────────────────┘
|
||
3V3 ─┤ 1 16 ├─ 5V (VBUS) ──► +5V
|
||
GPIO1 ─┤ 2 15 ├─ GPIO15 (LED) │
|
||
GPIO2 ─┤ 3 14 ├─ GPIO14 │
|
||
GPIO3 ─┤ 4 13 ├─ GPIO13 │
|
||
GPIO4 ─┤ 5 12 ├─ GPIO12 │
|
||
GPIO5 ─┤ 6 11 ├─ GPIO11 │
|
||
GPIO6 ─┤ 7 10 ├─ GPIO10 │
|
||
GND ─┤ 8 9 ├─ GPIO9 │
|
||
└─────────────────┘ │
|
||
↓ ↓ ↓ ↓ ↓ ↓ │
|
||
V6 V5 V4 V3 V2 V1 ◄───────────┘
|
||
(HMC472A control pins + power)
|
||
```
|
||
|
||
GPIOs 1–6 are on the left header, pins 2–7. Direct ribbon cable from S2 Mini left header to HMC472A control header (reversed).
|
||
|
||
## KiCad Schematic
|
||
|
||
A full KiCad schematic is available at `hmc472-controller.kicad_sch` for detailed EDA work.
|
||
|
||
## Notes
|
||
|
||
1. **No level shifting required** — ESP32-S2 3.3V GPIO drives HMC472A directly
|
||
2. **Boot state** — GPIOs default HIGH at boot = 0 dB attenuation (safe)
|
||
3. **Glitch-free switching** — Firmware uses register-level writes (`GPIO.out_w1ts`/`GPIO.out_w1tc`)
|
||
4. **Power** — The S2 Mini's 5V pin sources USB VBUS directly, sufficient for HMC472A's 2.5 mA draw
|
||
5. **Bitwise optimization** — GPIO = bit + 1 mapping eliminates loop in firmware
|