Skip to content

Commit 901f91e

Browse files
committed
sigcapture: add decimation for capturing slow phenomena
sigcapture_set_decimation(sc, n) stores 1 of every n samples and reports base_frequency/n in the preamble, trading time resolution for a longer capture window (e.g. a multi-second quasi-static current sweep). The ADC hot path skips n-1 of every n sigcapture_wrptr() calls; trigger countdown and the readout are unchanged.
1 parent c6778af commit 901f91e

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

include/mios/sigcapture.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ sigcapture_t *sigcapture_create_vllp(size_t depth_power_of_2, size_t channels,
3636
const sigcapture_desc_t channel_descriptors[],
3737
uint32_t nominal_frequency);
3838

39+
// Store only 1 of every `n` samples (n>=1, 1 = full rate), to capture slow
40+
// phenomena over a longer time window at reduced time resolution.
41+
void sigcapture_set_decimation(sigcapture_t *sc, unsigned int n);
42+
3943
int16_t *sigcapture_wrptr(sigcapture_t *sc);
4044

4145
void sigcapture_trig(sigcapture_t *sc, size_t leading_samples);

src/lib/diag/sigcapture.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ sigcapture_wrptr(sigcapture_t *sc)
2121
if(sc->state != SIGCAPTURE_STATE_RUN)
2222
return NULL;
2323

24+
if(sc->decimation > 1) {
25+
if(++sc->decim_phase < sc->decimation)
26+
return NULL; // skip this sample
27+
sc->decim_phase = 0;
28+
}
29+
2430
if(sc->trig_countdown) {
2531
sc->trig_countdown--;
2632
if(sc->trig_countdown == 0) {
@@ -62,6 +68,17 @@ sigcapture_reset(sigcapture_t *sc)
6268
}
6369

6470

71+
void
72+
sigcapture_set_decimation(sigcapture_t *sc, unsigned int n)
73+
{
74+
if(n < 1)
75+
n = 1;
76+
sc->decimation = n;
77+
sc->decim_phase = 0;
78+
sc->pkt_preamble.nominal_frequency = sc->base_frequency / n;
79+
}
80+
81+
6582
// Transport-neutral readout state machine. Emits, in order: preamble (0xff),
6683
// one descriptor per channel, the captured data columns, then the trailer
6784
// (0xfe). After the trailer it hands the buffer back to the sampler and reports
@@ -172,6 +189,8 @@ sigcapture_alloc(size_t depth_power_of_2, size_t channels,
172189
sc->channels = channels;
173190
sc->storage = storage;
174191
sc->columns_per_xfer = 32 / channels;
192+
sc->decimation = 1;
193+
sc->base_frequency = nominal_frequency;
175194

176195
sc->pkt_preamble.pkt_type = 0xff;
177196
sc->pkt_preamble.channels = channels;

src/lib/diag/sigcapture_internal.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ struct sigcapture {
4545
size_t channels;
4646
uint8_t columns_per_xfer;
4747

48+
// Decimation: store 1 of every `decimation` samples (>=1), to capture slow
49+
// phenomena over a longer window. base_frequency is the full-rate frequency;
50+
// the preamble reports base_frequency / decimation.
51+
uint16_t decimation;
52+
uint16_t decim_phase;
53+
uint32_t base_frequency;
54+
4855
// Readout cursor + frame staging (only touched during READOUT).
4956
uint32_t send_index;
5057
uint32_t xfer_rows;

0 commit comments

Comments
 (0)