DEV Community
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. 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);
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;
}
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(now - stamp);
return age >= -5 && age <= static_cast(deadline);
}
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 ...
Powered by Readybot.io
External Link
Platform
You are about to visit:
https://example.comThis will open in a new tab. Make sure you trust this link.