2023-11-24 09:12 AM
Good evening to everyone,
I'm trying to sample various signals, both low frequency and high frequency. For the low frequency, I'm using a timer, while for the high frequency, I'm using DMA. I would like to perform read scans with the ADC, selecting the timer for the low frequencies, and then disable it and sample using DMA. I've tried disabling the timer trigger for the ADC and enabling DMA sampling, but perhaps there's something I'm not enabling or disabling correctly. Does anyone have any suggestions?
2023-11-24 09:58 AM
Did you reinit the ADC before enabling DMA?
2023-11-24 10:10 AM
Yes, the idea is to use the adc with the timer in this way :
ADC
hadc1.Init.ScanConvMode = DISABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hadc1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T2_TRGO;
TIMER
sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
While in DMA
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = ENABLE;
hadc1.Init.DiscontinuousConvMode = DISABLE;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 1;
hadc1.Init.DMAContinuousRequests = ENABLE;
and disable the timer. I have noticed that if I first initialise the ADC in DMA and then reinitialise to use the timer for sampling, it does not work.
2023-11-24 11:04 AM
DMA works at low freq. too, so just set tim->adc->dma chain and adjust timer for desired sampling rate
2023-11-24 11:13 AM
Yes, I've already done it, but I can only change the prescaler and period, not the clock. I managed to sample at 5 Hz, but the goal is 1 or 100 mHz. Another thing I noticed is that changing the real-time values doesn't completely match the samples per second I calculated. Do you have any suggestions for this?
2023-11-24 02:07 PM
What timer, TIM2? There are 16-bits & 32-bits, 2 and 5 I think 32-b, at least on F446re. Anyway, even 16-b timer with 16-b prescaller can divide system clock down to 180000000 ÷4294967296= 0.041909515857697 Hz
2023-11-24 02:45 PM
Yes, that is clear. In fact, I am sampling signals at 0.5 Hz with at least 15/20 samples per period. The issue remains on how to sample a low-frequency signal using a timer trigger and then switch to DMA without a timer for frequencies above 100 kHz. To change the settings of the peripherals, is it enough to reinitialize? I tried that, but it doesn't work... Am I missing something?