Skip to main content
Nabila Gina Nastiti
Associate II
June 8, 2018
Question

9 pins of ADC with DMA2 and timer TIM2 for sampling 200kHz

  • June 8, 2018
  • 1 reply
  • 1942 views
Posted on June 08, 2018 at 14:40

Hello everyone,

I have 9 pins of ADC that each of them will received signal from function generator 20 kHz. I want to use ADC to store the data inside an array by using DMA2. ADC1 has 3 pins, ADC2 has 3 pins, ADC3 has 3 pins. Because the sampling for all 9 pins supposed to be done at the same time (as they are received input at the same time), therefore i use triple mode regular simultaneous. The idea is to read all 9 pins, convert them, store them in DMA2 bufer (size : 3*1000) when conversion finish, and start read from ADC1again and repeat this. It is because i want to store all the signals at the same time from different pins. The process stop when buffer is full.

I use TIM2 for sampling and make external trigger conversion ADC1 as master TRGO, while ADC2 and ADC3 are set to CC2. I disable DMA Access Mode as each stream of DMA2 is connected to one ADC, where stream0 for ADC1, stream2 for ADC2 and stream1 for ADC3. I set the NVIC for all DMA2 streams with preemption priority stream0 as 0, stream2 as 1, and stream1 as 2.

Could anyone help me ifit is do-ableor did i miss something ? I understand that it requires a very fast conversion, but i cannot use fast interleaved because i need all three ADCs. The result so far is not as expected as the conversion stored in array is not sinusoidal.

Please inform me if this problem description is not clear

Thank you

Best regards,

Nabila

#timer #dma #stm32f429i-disc1 #adc

Note: this post was migrated and contained many threaded conversations, some content may be missing.
This topic has been closed for replies.

1 reply

AvaTar
Senior III
June 11, 2018
Posted on June 11, 2018 at 09:52

Do you mean 9 different input channels, or 3 inputs sampled with 3 ADCs ?

I don't know which MCU you are using, but 200kHz can be easily achieved with one ADC and 9 channels.

Because the sampling for all 9 pins supposed to be done at the same time (as they are received input at the same time), ...

In a strict sense, this is not possible. You would need 9 separate ADCs for that.

Using one ADC with 9 multiplexed channels, you get a fixed, constant offset between channels. With a sufficient sample rate, this should not pose difficulties.

Nabila Gina Nastiti
Associate II
June 11, 2018
Posted on June 11, 2018 at 10:04

Hi , thank you for your reply

I use three ADCs, each ADC has 3 inputs, so in total there are 9 different inputs

I am using STM32F429I

I have question about the sampling time. Below is my configuration for one ADC :

ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;

ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; 

ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;

ADC_CommonInit(&ADC_CommonInitStructure);

// ADC Init ****************************************************************

ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;

ADC_InitStructure.ADC_ScanConvMode = ENABLE;

ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; // triggered by TIM2

ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_Rising; 

// addition ADC1 is master to ADC2 and ADC3

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_TRGO;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfConversion = 3;

ADC_Init(ADC1, &ADC_InitStructure);

// ADC regular channel configuration *************************************

ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_15Cycles);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 2, ADC_SampleTime_15Cycles);

ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 3, ADC_SampleTime_15Cycles); 

And here is the configuration for timer :

/* Enable TIM2 Peripheral clock */

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);

TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

TIM_TimeBaseStructure.TIM_Prescaler = 0;//1;

TIM_TimeBaseStructure.TIM_Period = (84000000/ 200000) - 1;// 200 khz from 84 MHz TIM2CLK APB1 = HCLK/4, TIM2CLK = HCLK/2 //42000 1kHz Interrupt frequency

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);

TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_Update);

TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);

TIM_Cmd(TIM2, ENABLE);

Is it correct way to do sampling 200khz ? Should i use reduce the sampling time to 3 cycle ? I've tried to calculate it correctly but i think i didnt understand it correctly

The DMA will poll the result of ADC after finish conversion (Transfer Complete) and store it in array.

Thank you for your attention

Regards,

Nabila G.

Nabila Gina Nastiti
Associate II
June 11, 2018
Posted on June 11, 2018 at 10:09

Oh and the ADC mode is triple mode regular simultaneous