Part 2 of 4. Page 1 covered the DDS word, power rules, wiring, and the perfboard baseboard. This page covers the two user interfaces: the command-line tool for scripts and the terminal UI for live scope work.
Trying the tool from the command line
The command-line tool is the fastest way to prove that the chain works. With a serial-wired AD9850 module and the default 125 MHz oscillator, ad985x freq 20M loads a 20 MHz tuning word.
The response line shows both the user-level state and the exact bytes sent to the chip:
|
1 2 3 4 |
OK FREQ=20000000 PHASE=0 PWR=0 FTW=0x28F5C28F W=00 28 F5 C2 8F |
That byte string is useful during bench work. If the scope shows nothing, I do not have to wonder what the code intended to load, because the tool has already printed the control byte, the tuning word, the phase and the power state. The tuning word can be checked by hand: 20 MHz times 232 divided by 125 MHz is 687194767.36, which rounds to 687194767, or 0x28F5C28F.
The same command grammar works for reset, raw bytes, phase, power, status, capability checks, and stream playback. Examples include ad985x phase 90deg, ad985x pwr down, ad985x reset, ad985x raw 00 28 F5 C2 8F, and ad985x stream examples/sweep.txt --interval-ms 500.
Every explicit command reloads the DDS even when the state has not changed. This is on purpose. With a write-only chip, repeating a command is a valid way to recover after a loose jumper, a missing power rail or a reset, so the software must not skip a reload only because its cache says that nothing changed.
Using the TUI at the bench
The terminal UI became more useful than I expected because it matches how a scope session really goes. A frequency slider, phase control, power toggle, reset button, raw-byte panel, stream playback, and response log are all visible at once. The TUI sends the same commands through the same engine as the CLI and has no DDS logic of its own.
Running ad985x-tui --simulate opens the same interface against the software model, so the TUI can be used on a development machine without a Pi or DDS module attached:
|
1 2 3 4 5 6 7 8 |
> CAPS < OK CAPS V=0.5.0 MODE=SERIAL CHIP=AD9850 > FREQ 20000000 < OK FREQ=20000000 PHASE=0 PWR=0 FTW=0x28F5C28F W=00 28 F5 C2 8F SIM: latched W=00 28 F5 C2 8F FTW=0x28F5C28F PHASE=0 PWR=0 MODE=SERIAL |
The last line comes from the simulated chip, and it is produced independently of the encoder. The simulation watches the transitions on the virtual pins, samples the data bus or the serial input, and decodes the word that a real chip would have latched. When the command layer says it sent 00 28 F5 C2 8F and the simulated chip independently reports the same latched word, the byte order and serial bit order have been checked before the module is even connected.
Failure modes I wanted the software to catch
The failures on the bench are simple, and they cost a lot of time.
An unpowered DDS module accepts every GPIO sequence from the Pi and produces no output. The chip has no readback, so software cannot tell the difference between a successful load into a powered device and forty bits clocked into a module without supply. So the first rule is: when all outputs are flat, check the 3.3 V supply and the common ground first.
Reset is another trap. After reset, the AD9850 returns to parallel mode. If the driver assumes serial mode survived, it will shift forty good serial bits into a chip that is interpreting the bus as parallel data. The tool tracks that reset happened and re-enters serial mode before the next serial load.
The analog outputs can mislead too. The comparator square outputs are better for frequency counting because they give the scope clean edges. Counting the sine output directly can wobble from measurement gating and make a correct tuning word look suspicious. The small potentiometer on the blue AD9850 module controls the comparator threshold, which shows up as square-wave duty cycle; for these tests I adjusted it close to 50 percent. If the square outputs are missing or ragged, that trimmer is the first thing to check. If one sine pin looks weak while the square outputs are fine, probe the other sine output before blaming the chip.
These observations shaped the tool more than the normal case did. The driver keeps its own state, rejects dangerous W0 bits, reloads on explicit commands, warns on profile mismatches, re-enters serial mode after reset, and gives simulation output that can be compared against the command response.
The next page shows how this is built: the C++ core library, the Linux GPIO backend, and why the CLI and TUI are thin frontends over the same engine.