ControlForge SDR Receiver Guide
James M. Belcher Founder, JMB Technical Services LLC October 2026 | ControlForge v1.0.1819
1. What it is
An RTL-SDR dongle becomes a radio receiver your ST program controls. It covers 0.5–1766 MHz in six modes:
| Mode | Use | Default bandwidth | Range |
|---|---|---|---|
WFM | broadcast FM | 200 kHz | 50–240 kHz |
NFM | narrow FM: weather, marine, 2 m, FRS | 12.5 kHz | 3–36 kHz |
AM | airband, AM broadcast | 10 kHz | 2–36 kHz |
USB / LSB | single sideband (HF voice) | 2.4 kHz | 0.5–4 kHz |
CW | Morse | 500 Hz | 50–2000 Hz |
Around that: squelch, live RF gain, frequency correction, a scanner (band, memories, seek), recording to MP3 or WAV, a spectrum feed for analysis, and ISM listening, which decodes wireless sensors (433/915/345 MHz) while the receiver is otherwise idle.
Every call takes an optional trailing device index (default 0) for a second dongle.
2. Setup
-
The audio device opts in (it starts
rtl_tcp, from thertl-sdrpackage). In the--configfile:- name: audio0type: audiosettings:fm_sdr: true # allow sdr:// and fm:// sourcesfm_command: rtl_tcp # the rtl_tcp to runfm_addr: "" # or an rtl_tcp already running, host:portfm_device: 0 # rtl-sdr device indexfm_gain_db: 0 # 0 = the tuner's automatic gainfm_deemphasis_us: 75 # 75 Americas/Korea, 50 elsewhere -
Arm the
audiocapability in the same file (capabilities.audio.enabled: true). Without it every call is denied. -
Play the receiver. The receiver only demodulates while something plays
sdr://<device>:AUDIO_STREAM_PLAY('audio0', 0, 'sdr://0'). Retuning, a mode change or a scan changes what you hear without restarting the stream. A setting made while nothing plays is remembered and applies when playback starts.
A ready-made program with a full HMI page (knob, spectrum, waterfall,
memories, scanner, calibration) is in examples/radio/.
3. Tune and listen
PROGRAM P_Weather
VAR
started : BOOL := FALSE;
ok : BOOL;
why : STRING;
level_dbfs : LREAL;
audible : BOOL;
END_VAR
IF NOT started THEN
ok := SDR_SET_GAIN(22.0); (* manual gain: auto clips a strong station *)
ok := ok AND SDR_TUNE(162525000, 'NFM', 0); (* NOAA weather, 162.525 MHz; 0 = default bandwidth *)
ok := ok AND SDR_SET_SQUELCH(-50.0); (* mute below -50 dBFS *)
IF ok THEN
ok := AUDIO_STREAM_PLAY('audio0', 0, 'sdr://0');
ELSE
why := SDR_ERROR(); (* why the last setter refused *)
END_IF;
started := TRUE;
END_IF;
level_dbfs := SDR_SIGNAL_DB(); (* the S-meter *)
audible := SDR_SQUELCH_OPEN();
END_PROGRAM
- Every setter returns FALSE on a refusal (a frequency out of range, a
bad mode), and
SDR_ERROR()says why. It reads''after a success. - Frequencies are DINT hertz. 162.525 MHz is
162525000. - In AM, NFM and WFM the tuned frequency is the carrier. In USB, LSB and CW it is the dial (suppressed-carrier) frequency.
- Squelch compares the power inside the channel filter
(
SDR_SIGNAL_DB, dBFS) with the level, with 3 dB of hysteresis.SDR_SET_SQUELCH(-200.0)(or lower) turns it off. fm://97.1also works as a source: it tunes to that FM station in WFM and plays it through the same receiver.
4. Gain: don't overload the dongle
The most common bad-reception cause is too much gain. Above about 0.1 %
of samples at the ADC rails (SDR_OVERLOAD_PCT) the dongle overloads:
stations look "fat" and the spectrum grows false skirts. On the bench, auto
gain on the whip clipped 43 % of samples on a local FM station; 20–25 dB
manual gave 0 %.
PROGRAM P_GainWatch
VAR
overload : BOOL;
gain : LREAL;
ok : BOOL;
END_VAR
overload := SDR_OVERLOAD_PCT() > 0.1;
IF overload THEN
gain := SDR_GAIN_DB();
IF gain < 0.0 THEN
gain := 30.0; (* leave automatic gain first *)
END_IF;
IF gain >= 2.0 THEN
ok := SDR_SET_GAIN(gain - 2.0);
END_IF;
END_IF;
END_PROGRAM
SDR_SET_GAIN takes the gain in dB and the tuner picks its nearest step; the
RTL-SDR's top step is 49.6 dB, so anything up to the 60 dB the call accepts
lands there (above 60 it returns FALSE). Below 0 means automatic. SDR_SET_BIAS_TEE(TRUE) puts 5 V on the antenna port for an
active antenna or LNA. Never with a passive antenna that shorts the port.
5. Scanning
Three ways to scan, all stopped by SDR_SCAN_STOP() or a manual tune:
| Call | What it scans |
|---|---|
SDR_SCAN_BAND(start_hz, stop_hz, step_hz) | a range, at the current mode and bandwidth |
SDR_SCAN_LIST(hz_array, mode_array, bw_array, n) | memories: each entry has its own mode and bandwidth |
SDR_SEEK(direction, step_hz, low_hz, high_hz) | from the tuned frequency up (> 0) or down, wrapping; stops on the first signal |
The array arguments are array NAMES, as strings ('GVL_Mem.hz'), not
the arrays themselves.
VAR_GLOBAL (GVL_Mem)
hz : ARRAY[1..4] OF DINT := [162400000, 162475000, 162550000, 121500000];
mode : ARRAY[1..4] OF STRING := ['NFM', 'NFM', 'NFM', 'AM'];
bw : ARRAY[1..4] OF DINT := [0, 0, 0, 0];
END_VAR
PROGRAM P_MemScan
VAR
started : BOOL := FALSE;
ok : BOOL;
state : INT;
on_entry : DINT;
END_VAR
IF NOT started THEN
ok := SDR_SET_SQUELCH(-55.0); (* a set squelch is also the scan's stop level *)
ok := ok AND SDR_SCAN_TIMING(60, 2000); (* 60 ms a channel, hold 2 s after a signal drops *)
ok := ok AND SDR_SCAN_LIST('GVL_Mem.hz', 'GVL_Mem.mode', 'GVL_Mem.bw', 4);
started := TRUE;
END_IF;
state := SDR_SCAN_STATE(); (* 0 off, 1 searching, 2 holding *)
on_entry := SDR_SCAN_INDEX();
END_PROGRAM
- A stop is the channel power reaching the squelch level. With the
squelch off, it is 10 dB over the noise floor the scanner learns
(
SDR_SCAN_FLOOR_DB, the median of the last 32 empty channels). - It holds while the signal stays, then moves on after the hang time.
SDR_SCAN_SKIP()moves on at once. - A scan only moves while something plays
sdr://. It runs in the receiver's demod loop. - Read-backs:
SDR_SCAN_STATE,SDR_SCAN_INDEX,SDR_SCAN_HITS,SDR_SCAN_COUNT.
6. Recording
AUDIO_STREAM_RECORD(device, ch, path [, gated]) records a stream channel
until AUDIO_STREAM_RECORD_STOP. .mp3 is encoded by the box's ffmpeg;
.wav is written directly. The path is held to the data directory.
PROGRAM P_ScanLog
VAR
started : BOOL := FALSE;
ok : BOOL;
END_VAR
IF NOT started THEN
ok := SDR_SET_SQUELCH(-55.0);
ok := ok AND AUDIO_STREAM_PLAY('audio0', 0, 'sdr://0');
(* gated: record only blocks with sound - with the squelch set, just the transmissions *)
ok := ok AND AUDIO_STREAM_RECORD('audio0', 0, 'scanner_log.mp3', TRUE);
started := TRUE;
END_IF;
END_PROGRAM
- The tap is before the channel gain: volume and mute do not change the file.
- A retune or station change keeps recording into the same file.
- A recording stops past
record_max_mb(default 2048) with an error. A task that stops ends the recordings it started. - Read-backs:
AUDIO_STREAM_RECORDING,AUDIO_STREAM_RECORD_SECONDS,AUDIO_STREAM_RECORD_ERROR.
7. Wireless sensors (ISM listening)
Off by default. When on, and while nothing plays the receiver and no scan runs, it hops a band list (default 433.92 / 915 / 345 MHz, 60 s each) and decodes sensors into a table, one entry per model + id + channel. The moment a stream attaches or a scan starts, it hands the receiver back.
PROGRAM P_Sensor
VAR
started : BOOL := FALSE;
ok : BOOL;
i : DINT;
temp_c : LREAL;
rh : LREAL;
stale : BOOL;
END_VAR
IF NOT started THEN
ok := SDR_ISM_ENABLE(TRUE); (* off by default; listens only while the receiver is idle *)
started := TRUE;
END_IF;
i := SDR_ISM_FIND('Acurite-592TXR', 1234, 'A'); (* -1 until the sensor has been heard *)
IF i >= 0 THEN
temp_c := SDR_ISM_FIELD(i, 'temperature_C');
IF SDR_ISM_HAS_FIELD(i, 'humidity') THEN
rh := SDR_ISM_FIELD(i, 'humidity');
END_IF;
stale := SDR_ISM_AGE_MS(i) > 300000; (* nothing for 5 minutes: treat the reading as lost *)
END_IF;
END_PROGRAM
- Supported model:
Acurite-592TXR(fieldstemperature_C,humidity,battery_ok). SDR_ISM_STATE: 0 off, 1 waiting (the receiver is busy), 2 listening, 3 waiting (no tuner declared for this device).- A quiet sensor or a dead one?
SDR_ISM_AGE_MS. Entries are never removed while the runtime runs (up to 1024). - Errors are errors, never a silent 0: a bad table index, a missing field,
or an unknown model.
SDR_ISM_FINDreturns −1 only for a sensor not heard. SDR_ISM_BANDS(hz_array, n, dwell_ms)sets your own hop list (1–16 bands).SDR_ISM_READINGScounts transmissions,SDR_ISM_REPEATSthe repeat copies folded into them,SDR_ISM_REJECTS(model, reason)what a decoder refused ('length','checksum', …).
8. Frequency calibration
A cheap dongle's crystal is off by some ppm. SDR_FREQ_ERROR_HZ measures
where the carrier really is relative to the tuned frequency, averaged over
about a second, in AM, NFM, WFM and CW (not USB/LSB, which have no carrier).
SDR_FREQ_ERROR_OK says when the value is a real measurement.
To calibrate: tune a carrier of known frequency (NOAA 162.525 MHz in NFM
works in the US), let it settle, then apply
SDR_SET_PPM(ppm + round(-error / reference_hz * 1e6)) and measure again.
examples/radio/POU_Radio.st does this, including retrying the other
direction if the first correction made it worse. rtl_tcp takes whole ppm,
so up to ±0.5 ppm stays (±81 Hz at 162 MHz).
9. Spectrum and analysis
SDR_SNAPSHOT(i_array, q_array, n): the wide I/Q, 1.92 MS/s around the dongle centre (SDR_CENTER_HZ).SDR_CHANNEL_SNAPSHOT(i_array, q_array, n): the channel I/Q around the tuned frequency atSDR_CHANNEL_RATE(48 kS/s in the narrow modes, 240 kS/s in WFM), before the channel filter, so neighbours show.SDR_SET_ZOOM(1|4|16|64): narrows the fine view (narrow modes ±24 kHz, ±6 kHz, ±1.5 kHz, ±375 Hz).- WFM only:
SDR_PILOT_DB(the stereo pilot) andSDR_RDS_READ(the RDS subcarrier's baseband). - The FFT lives in ST, on the compute engine
(
examples/radio/POU_SDR_DSP.st): 1024–4096 points, Hann or Blackman-Harris windows. 4096 is the ceiling the VM's array memory allows; finer resolution comes from the zoom.
10. Function reference
Setters (return BOOL; FALSE on a refusal, see SDR_ERROR())
| Function | Signature |
|---|---|
SDR_SET_FREQ() | SDR_SET_FREQ(hz: DINT [, device]) : BOOL |
SDR_SET_MODE() | SDR_SET_MODE(mode: STRING [, device]) : BOOL |
SDR_TUNE() | SDR_TUNE(hz: DINT, mode: STRING, bandwidth: DINT [, device]) : BOOL |
SDR_SET_BANDWIDTH() | SDR_SET_BANDWIDTH(hz: DINT [, device]) : BOOL |
SDR_SET_SQUELCH() | SDR_SET_SQUELCH(dbfs: LREAL [, device]) : BOOL |
SDR_SET_GAIN() | SDR_SET_GAIN(db: LREAL [, device]) : BOOL |
SDR_SET_PPM() | SDR_SET_PPM(ppm: DINT [, device]) : BOOL |
SDR_SET_BIAS_TEE() | SDR_SET_BIAS_TEE(on: BOOL [, device]) : BOOL |
SDR_SET_CW_PITCH() | SDR_SET_CW_PITCH(hz: DINT [, device]) : BOOL |
SDR_SET_DEEMPHASIS() | SDR_SET_DEEMPHASIS(us: LREAL [, device]) : BOOL |
SDR_SET_ZOOM() | SDR_SET_ZOOM(factor: INT [, device]) : BOOL |
SDR_ERROR() | SDR_ERROR([device]) : STRING |
Receiver read-backs
| Function | Returns |
|---|---|
SDR_FREQ_HZ() / SDR_CENTER_HZ() | tuned frequency / dongle centre, Hz (DINT) |
SDR_MODE_NAME() | 'WFM', 'NFM', 'AM', 'USB', 'LSB' or 'CW' |
SDR_BANDWIDTH_HZ() | the channel filter's width, Hz |
SDR_PASSBAND_LO_HZ() / SDR_PASSBAND_HI_HZ() | the filter's edges relative to the tuned frequency, Hz |
SDR_SIGNAL_DB() | power inside the channel filter, dBFS (the S-meter) |
SDR_LEVEL_DBFS() | mean signal power at the dongle, dBFS |
SDR_SQUELCH_DB() / SDR_SQUELCH_OPEN() | the squelch level / TRUE while audio passes |
SDR_GAIN_DB() / SDR_OVERLOAD_PCT() | the gain setting (−1 = auto) / % of samples at the ADC rails |
SDR_PPM() / SDR_BIAS_TEE() / SDR_CW_PITCH() / SDR_DEEMPHASIS_US() | the current settings |
SDR_FREQ_ERROR_HZ() / SDR_FREQ_ERROR_OK() | measured carrier offset / whether it is a measurement |
SDR_ACTIVE() / SDR_STREAMING() | demodulating / I/Q arriving |
SDR_TUNER_STATE() / SDR_TUNER_ERROR() | 'off', 'starting', 'streaming', 'retrying' / why not streaming |
SDR_RETUNES() | how many times the station changed |
Scanner
| Function | Signature |
|---|---|
SDR_SCAN_BAND() | SDR_SCAN_BAND(start_hz: DINT, stop_hz: DINT, step_hz: DINT [, device]) : BOOL |
SDR_SCAN_LIST() | SDR_SCAN_LIST(hz_array: STRING, mode_array: STRING, bw_array: STRING, n: DINT [, device]) : BOOL |
SDR_SEEK() | SDR_SEEK(direction: INT, step_hz: DINT, low_hz: DINT, high_hz: DINT [, device]) : BOOL |
SDR_SCAN_TIMING() | SDR_SCAN_TIMING(dwell_ms: DINT, hang_ms: DINT [, device]) : BOOL |
SDR_SCAN_STOP() / SDR_SCAN_SKIP() | end the scan here / move past the channel it holds |
SDR_SCAN_STATE() | 0 off, 1 searching, 2 holding |
SDR_SCAN_INDEX() / SDR_SCAN_HITS() / SDR_SCAN_COUNT() / SDR_SCAN_FLOOR_DB() | where it is / stops so far / list length / learned noise floor |
Analysis
| Function | Signature |
|---|---|
SDR_SNAPSHOT() | SDR_SNAPSHOT(i_array: STRING, q_array: STRING, n: DINT [, device]) : DINT |
SDR_CHANNEL_SNAPSHOT() | SDR_CHANNEL_SNAPSHOT(i_array: STRING, q_array: STRING, n: DINT [, device]) : DINT |
SDR_CHANNEL_RATE() | the channel snapshot's sample rate |
SDR_ZOOM() / SDR_ZOOM_CENTER_HZ() | the fine view's factor / its centre frequency |
SDR_PILOT_DB() | the FM stereo pilot, dB (WFM) |
SDR_RDS_READ() | SDR_RDS_READ(i_array: STRING, q_array: STRING, max: DINT [, device]) : DINT |
ISM sensors
| Function | Signature |
|---|---|
SDR_ISM_ENABLE() | SDR_ISM_ENABLE(on: BOOL [, device]) : BOOL |
SDR_ISM_BANDS() | SDR_ISM_BANDS(hz_array: STRING, n: DINT, dwell_ms: DINT [, device]) : BOOL |
SDR_ISM_STATE() / SDR_ISM_FREQ_HZ() / SDR_ISM_COUNT() | listening state / band now / sensors in the table |
SDR_ISM_FIND() | SDR_ISM_FIND(model: STRING, id: DINT, channel: STRING [, device]) : DINT |
SDR_ISM_MODEL() / SDR_ISM_ID() / SDR_ISM_CHANNEL() | entry i's identity |
SDR_ISM_FIELD() | SDR_ISM_FIELD(i: DINT, name: STRING [, device]) : LREAL |
SDR_ISM_HAS_FIELD() | SDR_ISM_HAS_FIELD(i: DINT, name: STRING [, device]) : BOOL |
SDR_ISM_AGE_MS() / SDR_ISM_READINGS() / SDR_ISM_REPEATS() | ms since the last transmission / transmissions / repeats folded |
SDR_ISM_REJECTS() | SDR_ISM_REJECTS(model: STRING, reason: STRING [, device]) : DINT |
11. What was checked on the air
On an RTL-SDR Blog V4 with a bench whip (2026-10-07): NOAA 162.525 MHz heard in NFM at −43 dBFS against a −58 floor; FM seek stopped on four local stations; MP3 recorded. Nothing was heard on AM broadcast or 49 m shortwave even at 40 dB; HF needs a long-wire antenna. HF, SSB, CW on real signals and the bias tee are not yet verified on air.
See also
- Contract and acceptance tests:
docs/features/sdr-receiver.md - Design:
docs/design/SDR_RECEIVER.md - Example with HMI:
examples/radio/ - Synthesizer & Audio