2014-08-04 03:05 AM
Hi all!
I'm trying to configure DMA2 to trigger an interrupt on ''transfer complete'' event. I'm using DMA2 to transfer data from ADCs to memory. However, it seems that DMA2 never triggers an interrupt, but data is transfered to memory! Please find attached my main.c.Thanks!2014-08-04 04:28 AM
It seems that I did not configure well ADCs and/or DMA2 to operate in parallel. What I want is to ADC1, ADC2 and ADC3 scan 4 channels (each) but in parallel, so that 1st channels of ADC1, ADC2, ADC3 are scanned at the same time, and then 2nd channel etc. After scanning is done, I also want to transfer data into memory using DMA.
Any ideas?Best,Marko.2014-08-04 04:53 AM
Hello Marko,
as far as I have seen, you start the conversion before even configuring the DMA. Within main() you first call ADC_Configure() in which ADC_SoftwareStartConv is called. Afterwards you call DMA_Configure(). bs2014-08-04 05:08 AM
Thanks! I'll move this line after DMA is configured.
However, I want for this ADC sequence to be triggered by timer. Can you please take a look at new main.c that I wrote. So now I configured: ADC_Mode =ADC_TripleMode_RegSimult; DMA_InitStructure.DMA_PeripheralBaseAddr = ((uint32_t)0x40012308); // not sure for this address, I've found it in some example Since I want for this ADC sequence to be triggered by timer, I'm not sure how to configure that. Should I configure this external trigger only for ADC1? Thanks! Best, Marko. ________________ Attachments : main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Gv&d=%2Fa%2F0X0000000bkZ%2F1EZpGwMjexYQ.0h.sEMxoOYCxtt9DjKCvzwRBaTJ594&asPdf=false2014-08-04 05:58 AM
I managed to make it work. Thank you for your suggestion to move start of AD conversion!
One can find attached my main.c, maybe it will be of some help for someone. Best, Marko ________________ Attachments : main.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Gq&d=%2Fa%2F0X0000000bka%2FkUrcAUTaN8KzkopcsOtUi_cdwV7znTY0mUJy6Y5JjpU&asPdf=false2014-08-04 06:10 AM
2014-08-04 06:13 AM
You might want to review your timer settings to get more accurate sample times.
2014-08-04 06:58 AM
Hi clive1!
I'm not sure what do you mean by ''might need to tweak the triple mode used'' - I looked for those 2 examples you posted, but I can't find what I have to change.By ''review your timer settings'' you probably mean to increase time period as much as possible (for 16b timer it is 65536), which will allow me to increase base frequency? In that way I can get time periods with higher resolution.I noticed strange behavior of AD total conversion time. When following the formula in reference manual: (# cycles + 12 cycles) times (sample time), I calculate conversion time that is twice smaller than actual - actual time was recorded by oscilloscope. I even tested the clock frequency of APB2 using timer and oscilloscope, and it is really 80-84 MHz, and e.g. if I use Div4 on ADC clock (which means frequency of 20 MHz, i.e. time period of 0.05 us), and performing 4 conversion, formula would give: 4 times (3 cycles + 12 cycles) times 0.05 us equals 3 us, but I measure 7.2 us. This happens for all Div's and for all sampling-time-cycles. Do you know maybe why?Thank you for your help!Best,Marko.2014-08-04 07:31 AM
So what's your APB clock? 42 MHz
TIM_TimeBaseInitStructure.TIM_Prescaler = 3; // 42 MHz / (3+1) = 10 MHz (0.1 us) TIM_TimeBaseInitStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStructure.TIM_Period = 9999; // period: 1000 us = 1 ms TIM_TimeBaseInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TimeBaseInitStructure.TIM_RepetitionCounter = 0x00;
42,000,000 / 40,000 = 1,050 Hz 952.38 ms So the first sample (1) is paced by the clock, subsequent samples 2-4 depends on the conversion time.2014-08-04 07:45 AM
Its 42 MHz for timers TIM3 and TIM4, whereas TIM4 is only used to trigger AD conversion (every 1 ms). ADCs are on APB2 (with 84 MHz clock), and are configured with Div4 prescaler, which means 20 MHz clock.
I know that 1st sampling is triggered by clock (on TIM4 update, every 1 ms), and the other samples depend on when the prior sampling was finished. But nevertheless, sampling of each channel in sequence should be the same. Therefore, I calculate the total conversion time as:4 times (# cycles + 12 cycles) times time-period (which is 0.05 us in case of 20 MHz clock). But this gives me total conversion time that is 2 times less than actual. I can't figure out why...