Skip to content

examples/comp: add comparator example tool - #3783

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/apps-comp-test
Sep 15, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
daniel-p-carvalho:feat/apps-comp-test

Conversation

@daniel-p-carvalho

Copy link
Copy Markdown
Contributor

Summary

Adds a dedicated command-line tool examples/comp for testing and interacting with analog comparator devices (/dev/comp*) from NSH.

Features:

  • Read comparator state: comp read
  • Enable/disable comparator via IOCTL: comp enable, comp disable
  • Automated smoke test: comp test
  • Optional dynamic analog threshold test via DAC voltage ramp: comp ramp (when CONFIG_DAC is enabled).
  • Fully portable across architectures (pure POSIX / character driver interface).

Impact

  • Provides an official example tool for the comparator subsystem in NuttX (similar to examples/adc and examples/dac).

Testing

  • Host OS: Linux x86_64
  • Target Board: STMicroelectronics NUCLEO-G431KB (STM32G431KB)
  • Configuration: nucleo-g431kb:comp
  • Toolchain: arm-none-eabi-gcc 13.2.1

Execution Logs on Physical Hardware:

  1. Static state and IOCTL test:
nsh> comp
Running comparator test on /dev/comp0...
  1. Initial output state: 0
  2. ANIOC_COMP_DISABLE: OK
  3. Output state when disabled: 0
  4. ANIOC_COMP_ENABLE: OK
  5. Output state when enabled: 1
Comparator test PASSED on /dev/comp0
  1. Voltage ramp test against internal DAC3-CH2:
nsh> comp ramp
=== Comparator Ramp Test ===
  COMP device : /dev/comp0
  DAC device  : /dev/dac5
  Sweep range : 0 -> 4095 (step 100, delay 5 ms)

     DAC=   0 (~   0 mV) | COMP output: 1
     DAC= 500 (~ 402 mV) | COMP output: 1
     DAC=1000 (~ 805 mV) | COMP output: 1
  -> [TRIP EVENT #1] DAC=1400 (~1128 mV) | COMP output: 1 -> 0
     DAC=1500 (~1208 mV) | COMP output: 0
     DAC=2000 (~1611 mV) | COMP output: 0
     DAC=2500 (~2014 mV) | COMP output: 0
     DAC=3000 (~2417 mV) | COMP output: 0
     DAC=3500 (~2820 mV) | COMP output: 0
     DAC=4000 (~3223 mV) | COMP output: 0

=== Test Summary ===
SUCCESS: Detected comparator transition(s)!
  • Grounded input check: With INP grounded (0V), COMP output stayed at 0 throughout full DAC ramp.
  • High-rail input check: With INP connected to 3.3V, COMP output stayed at 1 until DAC reached 3.14V (~3900), tripping as expected.
  • Verified with checkpatch.sh: 0 errors, 0 warnings.

Add a dedicated NSH tool for testing and interacting with analog
comparator devices (/dev/comp*). Supports reading comparator output
state, enabling/disabling via IOCTL, and performing an automated voltage
ramp sweep using a DAC device when available.

Assisted-by: Gemini:gemini-2.5-pro
Signed-off-by: Daniel P. Carvalho <danieloak@gmail.com>
@daniel-p-carvalho

Copy link
Copy Markdown
Contributor Author

Companion OS/driver PR in nuttx: apache/nuttx#20149

@xiaoxiang781216
xiaoxiang781216 merged commit 72cf59b into apache:master Sep 15, 2026
41 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants