cancel
Showing results for 
Search instead for 
Did you mean: 

(Yet another) ADC/DAC synchronization question, STM32H7

Davla_CEKO
Associate

Hi,

I am trying to do synchronous DAC and ADC sampling using timers on the STM32H747.
A simplified diagram of my configuration is shown below.

Davla_CEKO_0-1732890981992.png

Basically I want to continuously set DAC values from a fixed buffer and read the their equivalent "real-world" response via the ADC (into a buffer of same size as the DAC's).

To achieve synchronization timers 2 and 4 have identical configuration and are both triggered from TIM1
(This solution is chosen in order to use PWM functionality to phase shift the ADC to obtain best results. It also allows changing sampling frequency and start/stopping the sampling using TIM1 only)

Unfortunately when running, the ADC buffer is off by 2 samples compared to the DAC - no matter the sampling frequency -  specifically it finished conversions before the DAC is finished setting the output values.

 

Timer and converter configurations are as follows:

Davla_CEKO_1-1732892032134.png

The ADC sampling time is set to 64.4 samples and ADC clock is 50MHz from PLL2CLK.

 

I initialize the DAC, ADC, TIM2 and TIM4 using the HAL:

HAL_DAC_Start_DMA(&hdac1, DAC_CHANNEL_1, (uint32_t*)waveform_default, NS_DAC, DAC_ALIGN_12B_R);
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adc_sram_buf, NS_ADC);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4);

 

But start/stop TIM1 using registers to avoid HAL overhead:

TIM1->CR1 |= TIM_CR1_CEN;

 

Is there any reason the two devices should not be in sync?

 

A similar issue is described here, without any solution:

https://community.st.com/t5/stm32-mcus-products/start-dac-and-adc-at-the-same-time/m-p/640618

 

Thanks!

0 REPLIES 0