Skip to content

Add multi-mode control (CC/CP/CR/CV/Discharge), OLED UI, and discharge curve recording to RP2040 electronic load firmware#1

Draft
Copilot wants to merge 4 commits intorust-mainfrom
copilot/design-fast-ui-for-advanced-loads
Draft

Add multi-mode control (CC/CP/CR/CV/Discharge), OLED UI, and discharge curve recording to RP2040 electronic load firmware#1
Copilot wants to merge 4 commits intorust-mainfrom
copilot/design-fast-ui-for-advanced-loads

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 30, 2026

The firmware was a bare prototype: raw PWM duty-cycle via rotary encoder, no measurement feedback, no operating modes, no display. This replaces it with a fully-featured embedded load controller.

New modules

src/control.rs

  • ControlMode enum: ConstantCurrent, ConstantPower, ConstantResistance, ConstantVoltage, Discharge
  • compute_current_ma() — translates each mode's setpoint + ADC measurements into a current demand; CV uses a proportional software loop
  • current_to_dac() — maps milliamp demand to PWM duty-cycle for the external analog current-regulation loop

src/discharge.rs

  • DischargeCurve stored as static mut (≈10.5 KiB in BSS); records up to 1 800 voltage/current/time samples (30 min @ 1 Hz), accumulates capacity in mAh, latches on cutoff

Main loop rewrite (src/main.rs)

Peripheral GPIO Notes
I2C0 SSD1306 OLED 0/1 400 kHz, 128×64
ADC voltage sense 26 ÷8 divider, maps 0–26 V
ADC current sense 28 shunt + amp, configurable mV/A
Encoder button 2 debounced; short = mode cycle, long = load toggle
PWM DAC 27 existing, now driven by control law

Loop runs at 1 kHz. ADC sampled every 10 ms, display refreshed every 100 ms, discharge data recorded every 1 s. Under-voltage cutoff in DIS mode stops the load and finalises the curve automatically.

Display layout (FONT_6X10, 128×64):

CC  [ ON  ]
SET   1.500 A
V11.23V  I 1.50A
P16.88W  R 7.49O
─────────────────
0:05:23  1234mAh
[voltage bar]        ← DIS mode only

Dependencies added (Cargo.toml)

  • ssd1306 = "0.8.4" + embedded-graphics = "0.8.1" — display driver and graphics primitives
  • heapless = "0.8.0" — stack-allocated String for write! formatting
  • embedded-hal-0-2 (alias for embedded-hal = "0.2") — required because rp2040-hal 0.10 ADC still uses the embedded_hal_0_2::adc::OneShot trait despite the project otherwise targeting embedded-hal 1.0

Housekeeping

  • .gitignore added; pre-existing tracked target/ artifacts removed from the tree
Original prompt

Want to design a fast UI and controlling using rust to have discharge curves, voltage, current power or resistance targets with any other features of advanced electronic loads. The hardware output is a dac value that controls the input for an analog loop that regulates load current through an open drain mmos


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI changed the title [WIP] Design fast UI for controlling discharge curves and targets Add multi-mode control (CC/CP/CR/CV/Discharge), OLED UI, and discharge curve recording to RP2040 electronic load firmware Mar 30, 2026
Copilot AI requested a review from electricalhog March 30, 2026 05:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants