Skip to content

Trend: a record from its start with min, max and mean per point - #152

Open
vvzvlad wants to merge 20 commits into
bve:mainfrom
vvzvlad:trend-record
Open

vvzvlad wants to merge 20 commits into
bve:mainfrom
vvzvlad:trend-record

Conversation

@vvzvlad

@vvzvlad vvzvlad commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

Builds on #150: its ten commits come first here, the last eight are this PR.

Trend is one more time/div step after 1 h/div (Right at 1 h/div, or Acquisition → Time / div →
Trend
; SCPI :ACQuire:TRENd ON|OFF). It keeps 2048 points of CH1/CH2 min, max and mean and the
DMM's min, max and mean in record bank 3, which Roll leaves idle. When it fills, neighbouring points
merge and the time per point doubles, so the whole record since RUN stays on screen and the time/div
grows steadily. A point sums at most 2^24 samples; a trend that would merge past that (after about
6.6 years with both channels at the 64K record, 3.3 years otherwise) stops as STOP stops it, with
Trend limit reached. Each channel draws as its min–max band with the mean line;
the status pill shows TREND and the time since RUN, also under menus. STOP freezes the record with the samples
of the point it stops in (the last point keeps its own count, given in the CSV header), RUN starts a new
one, Save waveform CSV.gz writes min/mean/max per channel and point. The trend key takes one settings
slot on top of #150: DocumentSlots 342, StringBytes 3376, MaxBytes 4584. A held trend survives AutoSetup.

Testing

  • pio run builds all four environments without new warnings
  • Tested on ZT703S
  • Tested on ZT706S
  • Not tested on hardware (explain why): no ZT706S here

On ZT703S: trends of CH1 and the DMM over tens of minutes, the band and mean lines, the pill's clock
running with a menu open, a trend CSV read back from the device; after the rebase, a trend started
over SCPI. On the host: a point with 65,535 DMM readings at 1 V and 65,535 at 3 V gives 2 V; frames
stay non-empty with the rate within 3e-5 up to the limit; a full run to the limit (2^35 samples); a STOP after a merge to two
samples per point keeps the last single sample. On 0.22.5 over SCPI: :STOP, then :WAV:PRE? 53–72 ms
later gets the final record, unchanged 2 s later, and :ACQ:FRAM? names it.

Checklist

  • The change does not write to the factory block (0x08000000–0x0801FFFF)
  • vendor/ is unchanged, or a third-party component is updated as a whole
  • README updated if the behaviour or the installation changed

@bve

bve commented Nov 25, 2026

Copy link
Copy Markdown
Owner

Thanks for adding the Trend recorder. This builds on #150, so its DMM freshness issue also applies here. I reproduced two additional issues in host tests.

  • Once a point reaches 65,535 DMM readings, further readings still update the extrema but stop contributing to its mean. A test point with 65,535 readings at 1 V followed by 65,535 at 3 V reported a mean of 1 V. The correct mean is 2 V. DMM aggregation
  • As Trend merges points, the reduced sample-rate denominator can exceed 32 bits. I tested the boundary directly using the rate from the stock 360 MHz profile with both channels on and the 64K record setting. At a merge factor of 1,048,576, about 76 days in that configuration, snapshot() starts returning an empty frame. Please support that rate or make the recording limit explicit and visible when it is reached. Snapshot rate

@vvzvlad

vvzvlad commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Fixed both.

  • A point's DMM count is 32 bits and adds on merge: 65,535 readings at 1 V and 65,535 at 3 V give 2 V.
  • When a point's rate no longer fits 32 bits, its numerator and denominator are halved together until
    they do, so the frame stays non-empty with the rate within 3e-5 of the exact one.
  • The next limit is the point's 32-bit sum of 8-bit samples, 2^24 samples per point: about 6.6 years
    in your configuration, 3.3 years otherwise. There the trend does not merge further; it stops as STOP
    stops it, with Trend limit reached, and RUN starts a new record.

Checked with host tests, including a full run to the limit, and on a ZT703S. Rebased onto #150.

@bve

bve commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Thanks for fixing the DMM mean and the long-record rate. I confirmed that merging 65,535 readings at 1 V with 65,535 readings at 3 V gives a mean of 2 V.

There is still a data-loss case at STOP. The current bucket closes only when it reaches its full sample count. STOP holds the latest published record, and CSV uses the same completed buckets. In a host test, after a merge to two samples per bucket, I added one final sample and verified that it was absent from the retained record. The omitted interval grows as the buckets get longer.

Please publish the final partial bucket at STOP and use its actual sample count for the mean. This PR also includes #150 and inherits its integration blockers with v0.22.0. Bucket aggregation · STOP path

@vvzvlad

vvzvlad commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Fixed. At STOP the open point becomes the record's last point with its own sample count: its mean, minimum, maximum and DMM readings are over those samples, its CSV row is at their middle, and the CSV header gives its size (# trend: samples_per_point=8,last_point_samples=5). The record is published at the moment of STOP on every path into HOLD (the key, SCPI :STOP, the trend limit, HOLD during AutoSetup), and until it is published no reader gets the frame from before STOP.

A host test of your case: a merge to two samples per point, one more sample, STOP. The held record has 1025 points, the last of one sample, and the CSV writes 1025 rows; 1024 before the fix. A separate harness around rolling.cpp and held_scope.cpp with the real FrameStore and leases checks :WAV:PRE? right after :STOP, a host holding a frame, and HOLD during AutoSetup. On a ZT703S: trends of 3 and 7 s, :STOP, :WAV:PRE? 40–54 ms later gives records of 3.058 and 7.032 s, the same byte for byte 2 s later, and :ACQ:FRAM? names this final record (the same number as in the :WAV:FRAM? reply).

Rebased onto 0.22.2 on top of #150; each of the 8 commits builds. The trend key adds one slot to #150: 338/3440, MaxBytes 4520 (the longest file is 4517 bytes).

@vvzvlad

vvzvlad commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #150. Budget 340/3408, MaxBytes 4560 (the longest file is 4558 bytes). All eight commits build, and the STOP and HOLD host tests give the same output as before the rebase.

@vvzvlad

vvzvlad commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto the new #150. The trend's status pill uses your TextRef status_, and TREND stays in English like the other capture states (added to that list in TRANSLATING.md). scripts/ui_sources.py gets src/acquisition/trend.cpp for test_ui_screens.

Budget 342/3376, MaxBytes 4584. Free DTCM drops by 256 bytes against main. Every commit builds, and the six CI checks pass.

@vvzvlad
vvzvlad force-pushed the trend-record branch 3 times, most recently from eecf9e3 to 420a068 Compare November 29, 2026 22:29
Glow's 12800-byte scratch had an ITCM section of its own (.scope_glow).
It is used only inside the synchronous software draw callback and is
cleared per channel before use. The spectrum's real and imaginary
arrays (16384 bytes in DTCM) are refilled by every calculation, and a
spectrum is computed only from Model::project, never during a draw.

SpectrumStorage now holds those arrays as raw work bytes. The FFT
begins its arrays there with placement new at each calculation, and
Glow begins its scratch there at each draw, reached through the Model.
The .scope_glow section, its zeroing at reset and its term in the ITCM
check are gone; DTCM use is unchanged.
rollAuto, longerRecord and interleave hold 0..2 and took a 32-bit word
each. As bytes, Preferences shrinks from 624 to 616 bytes on both
boards: room for new Scope choices under the stack check in
preferences.hpp. Their order, defaults, file keys and accepted values
are unchanged (an interleave_mode above 255, rejected by valid()
before, is now rejected by the parse; both refuse the file).
Analyze > Display > View > DMM keeps the multimeter chip powered while
the scope runs (latch bit 13 on top of every scope word) and draws its
readings as a third trace beside CH1/CH2. DMM function picks what it
measures and is shared with the DMM mode. The trace draws in Roll
(200 ms/div and slower); every timebase shows its value. A second F1/F2
press steps CH1, CH2 and DMM among those shown; with DMM selected the
arrows set its units/div (1-2-5) and position.

The DMM UART receives through its own DMA stream beside the capture;
the link watchdog power-cycles the chip by the bit alone. While SCPI's
parallel mode serves the DMM, the trace leaves the chip to it and does
not run. The readings ring (1024 entries) lives in arena bank 3,
which Roll leaves idle; any other capture invalidates it.
The multimeter trace becomes a channel beside CH1/CH2: its own colour
role (DMM) in every scheme, a "D" zero tag in the left margin, the line
on every timebase placed by time on the record's axis (the last reading
held to the record's end), level cursors on it with the delta in its
units, and Mean/Min/Max/P-P/RMS over the visible window in the footer:
its own REL page while both channels show, a hidden channel's panel
otherwise. The readouts it shows are stored as dmm_measurements.

The readings ring moves from the Roll spare bank to its own ITCM
section (768 entries), so captures no longer invalidate it; builds with
the USB trace keep it out.

The settings budget grows with it: dmm_measurements and the DMM colour
role take six slots, and display.language from 7781a38, which main's
numbers do not count yet, one more, so 340 slots and 3408 string bytes
(8848 bytes of tree, as before), and MaxBytes rises from 4480 to 4568 for
the longest valid file, 4562 bytes on the ZT706S, 19 of them for
display.language.
Timebases continue past 20 s/div to 1 h/div (10 hours on screen). Past
20 s/div the capture runs in Roll with the trigger in Auto, sampling as
at 20 s/div, and each point shown is the mean of the samples it spans.
The DMM line follows the same rule: at slow timebases each point is the
mean of the readings within its span, and the line starts where the
record starts.

The DMM gets a channel menu like CH1/CH2 (MENU on its scale/position:
Enabled and Function), its zero tag becomes "M", and the reading overlay
over the plot is gone. With the DMM on, CH1 and CH2 can both be off: the
DMM takes the plot and the footer, the trigger shows AUTO without a
channel, and FFT, reference capture and SCPI single/normal sweeps refuse
a hidden channel. AUTO also fits the DMM's units/div to its readings;
readings off screen are marked at the plot edge.

A scope CSV.gz carries the DMM readings in a dmm column. A HOLD on the
DMM screen keeps its function in the scope too: the DMM channel menu
refuses another until it is released in the DMM.

A timebase of 1000 s/div and up takes two digits more than 20 s/div in
the settings file: the longest valid file grows to 4564 bytes on the
ZT706S, within MaxBytes (4568).
DISPlay:TEXT[:DATA] "<text>" shows a message over any screen until a
key, DISPlay:TEXT:CLEar or a new text; DISPlay:TEXT? returns it. The
message wakes a dark screen and the key that dismisses it does nothing
else, except REL/Power held, which still powers off.

The scope's DMM line starts again whenever another function is
selected, also within one quantity (DC to AC amps) and when the
function was selected while the capture was stopped.
Switching from the DMM screen to the Scope with the DMM trace on kept the
last reading Ok while the meter chip was still powered off. The trace
start now expires it, as entering the DMM screen does: the reading is
stale until a new packet arrives, and the charge counter starts a new run.
With the DMM as a third channel, the selection stepped by input number,
so with the channels swapped it went CH2, CH1, DMM on screen. It now goes
left slot, right slot, then the DMM.
The DMM channel's timebases past 20 s/div always roll in Auto; a pulse
width, runt or rise/fall trigger is kept and applies again at 20 s/div
or faster.
The DMM line, its zero, the dDMM level cursor readout, AUTO's scale fit
and the Up/Down reach of its zero counted 8 divisions, so on the square
grid a units/div did not match a square. They now take the grid's own
divisions, as the channels do: 5 on the square grid, 8 otherwise. The
plot rows per division are Painter::meterDivision() for all three
drawings; test_meter_scale checks AUTO's fit on both grids.
Trend is one more time/div step after 1 h/div (Right at 1 h/div, or
Acquisition -> Time / div -> Trend; SCPI :ACQuire:TRENd ON|OFF). The
capture runs as the 20 s/div Roll; a TrendBuffer in record bank 3, which
Roll leaves idle, keeps 2048 points of CH1/CH2 min, max and sum and the
DMM's min, max and count-weighted mean. When it fills, adjacent points
merge and the time per point doubles, so the whole record from RUN stays
on screen at 1.25 s/div, 2.5 s/div and so on, with no length limit.

Each channel is drawn as its min-max band with the mean line, the DMM on
its own scale; the plot note shows the elapsed time. STOP freezes the
record and RUN starts a new one. Save waveform CSV.gz writes min/mean/max per
channel and point. Any CH setting restarts the record; a DMM function
change restarts only the DMM part, a DMM range change keeps it.

The trend key takes one slot of the settings tree's string bytes (342
slots, 3376 bytes), and MaxBytes rises from 4568 to 4584 for the longest
valid file, 4577 bytes on the ZT706S.
After its first halving the record always spans the whole plot: the
published window is the stored points, so time/div grows continuously
instead of the record falling back to the right half at each halving.

The band, the DMM line, the TREND note, the START OF RECORD shading and
the trend CSV are drawn and written from the published copy alone (its
size, points per sample, window and rate), not only while it matches the
frame on show: the frame reaches the display after its DMA copy, and the
gap between made the plot fall back to plain traces at every point.

Review fixes: a held trend keeps its own time/div (no 20 s/div redraw
after STOP), no "Next" title in a trend, AutoSetup's trials leave the
frozen record alone, the trend is forgotten as soon as a non-trend
request is accepted, the DMM's deferred gap reaches the trend, the CSV's
DMM quantity is the copy's, and comments say the time/div grows.
AutoSetup's trials take the trial area, so accepting their request no
longer forgets a held trend: cancelled or failed, AutoSetup returns to
it with its band. The band and shading are the record's own view only:
zoomed, panned or held at the next capture's time/div the frame's means
are drawn, as the time/div label and the cursors follow that view. No
pending time/div is shown for a staged trend either. A gap mark or OL
among a column's points breaks the DMM line before it, and the trend
CSV's header takes its sequence and timestamp from the copy.
The note needs a rolling frame on show as well as a valid copy: AutoSetup
keeps a held trend's copy while its trials show their own frames. The
DMM gap reaches the trend once, where the readings resume; a mark at the
stop as well broke the line a column early.
The plot note gives way to the status pill: TREND (STOP when held) with
the time since RUN as mm:ss, h:mm:ss from an hour on, so it keeps its
width; while running it counts on the frames' clock, a second at a time,
not a stored point at a time. A trend's time/div, on its card and on
the plot's scale label, keeps its trailing zeros (3.49s, 3.50s, 3.51s;
Format::steady) instead of jumping between 3.5s and 3.51s.
The trend's elapsed time is its own call (ScopeScreen::trend), made also
while a settings menu or a panel is open: the pill shows above them, and
its seconds no longer stop there and jump on closing. The plot's scale
label takes the steady format on the same condition as the card.
…e limit

A point counted its DMM readings in 16 bits and stopped adding to the sum
at 65,535 while the extrema went on, so 65,535 readings at 1 V and 65,535
at 3 V gave a mean of 1 V. The count is 32 bits and adds on merge; a
point holds at most about 5.5 million readings.

A point's sample rate is reduced as points merge; past a merge factor of
2^20 (about 76 days at 360 MHz with both channels and the 64K record) its
denominator left 32 bits and snapshot() returned an empty frame. The
numerator and denominator are now halved together until both fit, within
3e-5 of the exact rate at the limit.

The next limit is the point's int32 sum of 8-bit samples: 2^24 samples. A
full trend at that size does not merge; it stops as STOP stops it and
shows "Trend limit reached" (about 6.6 years in that configuration, 3.3
otherwise). RUN starts a new record. The mean's rounding is 64-bit, which
overflowed at the limit.
STOP held the record as last published, and its CSV wrote the same
points: the point being filled, up to a 1024th of the record, was lost,
and so were the points closed in the 16 ms before STOP. At STOP the open
point is now the record's last, with the samples it has: its means are
theirs, its DMM part the readings that came, and it never merges, as RUN
starts a new record.

The record is published at the STOP itself, on every way into HOLD: the
key, :STOP, the trend's limit, and HOLD during AutoSetup, where it
replaces the frame AutoSetup kept. No reader is given the frame from
before it. A file export or a USB host still reading that frame holds
the record back: until it lets go nothing is given out (the view keeps
what it shows, a host's query and a save wait), and it is published
then. Stopped, the record takes no DMM reading or restart, as AutoSetup's
and the zero's trials run under a held one.

The plot's column means, the CSV's means and the held elapsed time weigh
that point by its own samples. Its CSV row is at their middle, to the
microsecond, and the header's trend line gives last_point_samples. A
full record takes no more samples, so its limit stop has none open.
The trend's DMM line counted 8 divisions like the live one did; it now
takes the grid's own through Painter::meterDivision(), as meterTrace
does: 5 on the square grid.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants