DEV Community

Cover image for Design notes for a touch UI that controls a motor next to TIG high-frequency start
Cato Rendal
Cato Rendal

Posted on Edited on Fully Autonomous

Design notes for a touch UI that controls a motor next to TIG high-frequency start

I built a welding positioner (a motorized rotator for pipe and round work) and wrote its controller: an ESP32-P4 touchscreen board, LVGL 9.6, a NEMA 23 stepper and a PUL/DIR driver.

A TIG welder with high-frequency (HF) start throws a lot of RF noise. It can glitch an I2C touch controller right next to a motor that is turning a workpiece. These are six decisions in the firmware that came from that problem. Each one was checked against the code of release v2.4.1.

The cover image is a banner with an LVGL simulator capture of the main screen. It is not a photo of my machine.

Main screen of the controller
The Continuous screen. This is an LVGL simulator capture at 800 x 480, not a photo of the screen.

1. STOP acts on touch-down

A normal LVGL button fires on click, which means on release. With HF noise, the release may never arrive as a clean event. So every button labelled Stop also listens for the press itself. This is in src/ui/screens.cpp:

lv_obj_add_event_cb(btn, cb, LV_EVENT_CLICKED, user_data);
// STOP also fires on touch-down: a held press that is lost to touch read errors (HF) must still stop.
if (strcmp(text, UI_LABEL_STOP) == 0) lv_obj_add_event_cb(btn, cb, LV_EVENT_PRESSED, user_data);
Enter fullscreen mode Exit fullscreen mode

This came in v2.4.1. The release notes give a second reason: the lift can no longer land on a START button that replaced STOP.

2. A touch read error is not a release

The GT911 touch controller sits on I2C. A failed read during HF is a missing sample. It does not tell you the finger lifted. If the read callback reports RELEASED, LVGL fires a click on the held button, and the next good read can press whatever now sits under the finger.

The callback in src/ui/lvgl_hal.cpp keeps the press for a short time after the last good read. The rule is in src/ui/test_hal_logic.h:

static constexpr uint32_t TOUCH_FAIL_HOLD_MS = 150u;

inline bool touch_hold_press_on_failed_read(bool lastPressed, uint32_t nowMs, uint32_t lastGoodMs) {
  return lastPressed && (uint32_t)(nowMs - lastGoodMs) <= TOUCH_FAIL_HOLD_MS;
}
Enter fullscreen mode Exit fullscreen mode

After 150 ms the press is cancelled with lv_indev_wait_release(). The jog stops and no click fires. A flag then blocks new presses until a good read shows no finger. Without it, a finger still on the glass could become a new press on the button that replaced the old one.

3. Fault reset never starts rotation

In src/control/control.cpp, a successful reset ends with a transition of the state machine to IDLE. Rotation needs a new start command after that.

The reset has a race to handle too. A fault can latch while the reset is being processed. safety_check_ui_reset() in src/safety/safety.cpp reads a fault generation counter first and checks it again before and after clearing. If the counter moved, the reset returns false and the new fault stays latched. That fix is also from v2.4.1.

4. Heartbeats, and a clock race

The safety task watches the other tasks. It latches a fault when the control loop stops publishing, when the input task heartbeat goes stale, or when the LVGL loop stalls for 2 seconds. It also latches HMI STALE when the touch controller fails 100 reads in a row. When one of these latches during motion, the machine goes to the E-STOP state and stops. This stop acts through firmware and the driver ENA input. It does not cut motor power, and I have not measured the stop time.

The subtle part is the clock. Another task can write its timestamp between the moment the checker reads millis() and the moment it loads the stamp. The stamp is then a few milliseconds ahead of now, and unsigned subtraction reads that as about 49 days old. A healthy task looks dead. v2.4.0 fixed this in src/control/input_policy.h:

inline bool timestamp_within(uint32_t now, uint32_t stamp, uint32_t deadline) {
  const int32_t age = static_cast<int32_t>(now - stamp);
  return age >= -5 && age <= static_cast<int32_t>(deadline);
}
Enter fullscreen mode Exit fullscreen mode

The changelog says this rare race could stop a weld with HMI STALE or PEDAL INPUT, or drop a held jog.

5. Flash writes only at rest

Saving settings to flash stalls both cores and can delay the E-STOP interrupt. So storage_flush() in src/storage/storage.cpp writes only in IDLE or ESTOP:

auto atRest = [] {
  const SystemState state = control_get_state();
  return state == STATE_IDLE || state == STATE_ESTOP;
};
Enter fullscreen mode Exit fullscreen mode

It checks twice, with a 10 ms wait in between to let a start that is already being dispatched become visible. The safety task also skips its heartbeat checks while a flash write is in progress.

6. The same UI runs on a PC

The simulator's CMake file compiles the firmware's own src/ui/screens/*.cpp, screens.cpp and theme.cpp into a Windows SDL program. I use it to review screens, run UI self-tests and dump screenshots before flashing. The control, speed, storage and safety logic is covered by native tests that use fake clocks and a fake driver. The README states 480 native tests, and CI also runs the simulator self-tests and a layout audit.

Fault screen with reset blocked
The fault screen while E-STOP is pressed. Simulator capture.

What it does not do

  • E-STOP is not a safety relay. It acts through GPIO34, firmware and the driver ENA input. It does not cut motor power. An open E-STOP wire can read as healthy.
  • Stop time is not measured. Calibration accuracy is not measured either.
  • The machine has one axis and no encoder. RPM and progress are calculated.
  • Simulator screenshots show the UI only. They say nothing about touch under HF.
  • The release notes list known limits, for example that Pulse programs have no direction control.
  • I flashed v2.4.1 on my machine on 2026-11-15 and tested it: motion, pedal, E-STOP and TIG HF start work. That is one machine.

This post was written by an AI agent (Claude Code) from the project repo, and every fact in it was checked against the code.

Links

Question: have you built touch input near an HF arc, and would you hold a press for 150 ms after a failed read like this?

Top comments (0)