From b32c4d9d619f469935e24f596d4ff570e5ea5925 Mon Sep 17 00:00:00 2001 From: jaseg Date: Sat, 23 Nov 2024 14:24:09 +0100 Subject: [PATCH] Move stimulus instead of sampling pulse, eliminates ADC alignment issue The ADC can only trigger on whole clock pulses, so when we move the sampling pulse in fractional increments, the relative alignment of the ADC's sampling phase w.r.t. sampling pulse moves around +/-0.5 clock periods. Since our opamps ring a bit, that leads to an artifact in the measurements with a period of 32 samples (one whole clock pulse). Moving the stimulus pulse instead fixes this issue, as now the alignment between the sampling pulse and the ADC's sampling is constant. --- fw/src/main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/fw/src/main.c b/fw/src/main.c index 3d623ce..8ea7dd9 100644 --- a/fw/src/main.c +++ b/fw/src/main.c @@ -7,9 +7,9 @@ uint64_t sync_time_us; void update_leds(void); -int global_sampling_offset = 16; +int global_sampling_offset = 50; int stimulus_width = 0x20*8; -int sampling_width = 0x20*8; +int sampling_width = 0x20*2; int sampling_phase = 0; uint16_t adc1_raw[128]; uint16_t adc2_raw[COUNT_OF(adc1_raw)]; @@ -257,8 +257,8 @@ int main(void) { HRTIM1->sTimerxRegs[1].TIMxCR = HRTIM_TIMCR_MSTU; HRTIM1->sTimerxRegs[1].PERxR = HRTIM1->sMasterRegs.MPER; HRTIM1->sTimerxRegs[1].RSTxR = HRTIM_RSTR_MSTPER; - HRTIM1->sTimerxRegs[1].CMP3xR = 160 * 0x20; - HRTIM1->sTimerxRegs[1].CMP4xR = 160 * 0x20; + HRTIM1->sTimerxRegs[1].CMP3xR = (global_sampling_offset + 18) * 0x20; + HRTIM1->sTimerxRegs[1].CMP4xR = (global_sampling_offset + 40) * 0x20; HRTIM1->sTimerxRegs[1].TIMxDIER = HRTIM_TIMDIER_CMP3IE; HRTIM1->sMasterRegs.MCR |= HRTIM_MCR_TCCEN | HRTIM_MCR_TDCEN | HRTIM_MCR_TBCEN; @@ -427,12 +427,9 @@ void HRTIM1_Master_IRQHandler(void) { HRTIM1->sMasterRegs.MICR = HRTIM_MICR_MREP; - int t = 0 + sampling_phase; - HRTIM1->sTimerxRegs[3].CMP3xR = t + 0x20 * 0; - HRTIM1->sTimerxRegs[3].CMP4xR = t + 0x20 * 8; - HRTIM1->sTimerxRegs[1].CMP3xR = t + 0x20 * 30; - HRTIM1->sTimerxRegs[1].CMP4xR = t + 0x20 * 30; - GPIOC->BRR = (1<<10); + int t = (global_sampling_offset + 24) * 0x20 - sampling_phase; + HRTIM1->sTimerxRegs[2].CMP1xR = t; + HRTIM1->sTimerxRegs[2].CMP2xR = t + stimulus_width; } void update_leds() {