cancel
Showing results for 
Search instead for 
Did you mean: 

ADC different channel

cyril2399
Associate II
Posted on August 02, 2011 at 11:56

Hello,

I can do a ADC conversion for 1 channel. But I have a problem for using 2 channels.

I do this:

ADC_InitStructure.ADC_NbrOfChannel = 2;

ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_13Cycles5);

 ADC_RegularChannelConfig(ADC1, ADC_Channel_15, 2, ADC_SampleTime_13Cycles5);

And then for get the value I do:

ADC_ResultOfConversion1 = ADC_GetConversionValue(ADC1);

ADC_ResultOfConversion2 = ADC_GetConversionValue(ADC1);

But ADC1 convert has 16 channels... How could I do for having the channel 15, rank 2 into ADC_ResultOfConversion2?

For me ADC_GetConversionValue(ADC1) is the same value as ADC_GetConversionValue(ADC1) ... How could I differenciate the two channels?

Thanks

7 REPLIES 7
raptorhal2
Lead
Posted on August 02, 2011 at 15:05

For more than one channel, you need to use DMA.

Cheers, Hal

cyril2399
Associate II
Posted on August 02, 2011 at 16:19

I check the examples for ADC-TIM1 into DMA stm32f10x examples and there is this code for the configuration:

  /* DMA1 Channel5 configuration ----------------------------------------------*/

  DMA_DeInit(DMA1_Channel5);

  DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)TIM1_CCR1_Address;

  DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC1_DR_Address;

  DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;

  DMA_InitStructure.DMA_BufferSize = 1;

  DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;

  DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

  DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

  DMA_InitStructure.DMA_Priority = DMA_Priority_High;

  DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  DMA_Init(DMA1_Channel5, &DMA_InitStructure);

  /* Enable DMA1 Channel5 */

  DMA_Cmd(DMA1_Channel5, ENABLE);

The last line is channel 5. If I want the channel 15 of ADC should I write:

  DMA_Cmd(DMA1_Channel15, ENABLE); ?

Are you telling me I can not do the two conversion at the same time?

If I have understand I have to do my first conversion and then after stop the first do my second conversion.

Is channel 5 the same as channel 5 for ADC's?

thanks

cyril2399
Associate II
Posted on August 02, 2011 at 16:27

Ok forget it I have found the example 3ADCs_DMA into the library.

I can do something with this.

thanks for your help

cyril2399
Associate II
Posted on August 02, 2011 at 17:02

Into the example (3ADCs_DMA) there is something I don't understand...

The example is for 3 ADC's.

they do DMA1 channel1 configuration with   DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC1ConvertedValue;

and DMA2 channel5 configuration

DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADC3ConvertedValue;

with this at the beginning:

 __IO uint16_t ADC1ConvertedValue = 0, ADC3ConvertedValue = 0;

And only 1 and 3 are defined at the beginning like this:

#define ADC1_DR_Address    ((uint32_t)0x4001244C)

#define ADC3_DR_Address    ((uint32_t)0x40013C4C)

When they do the ADC1 configuration, ADC2 configuration and ADC3 configuration they do exactly the same thing for 1 and 3 but for n°2 a ligne is different. Instead of doing  

/* Enable ADC1 DMA */

  ADC_DMACmd(ADC1, ENABLE);

They do

/* Enable ADC2 EOC interupt */

ADC_ITConfig(ADC2, ADC_IT_EOC, ENABLE);

How is used the ADC2?

They do the same things for 1 and 3 but for the second I don't understand.

Could someone explain it to me please?

Thanks

ivanov-i2
Associate II
Posted on August 02, 2011 at 17:48

ADC2 doesn't have an associated DMA channel. The way to use it is only in combination with ADC1 in ''Dual ADC mode''.

For this purpose the data register of ADC1 contains also the result of conversion of ADC2, so both could be transferred by a single DMA operation.

cyril2399
Associate II
Posted on August 03, 2011 at 09:12

I have found the ADc mode and there is no DUAL MODE, there is the list:

#define ADC_Mode_Independent                       ((uint32_t)0x00000000)

#define ADC_Mode_RegInjecSimult                    ((uint32_t)0x00010000)

#define ADC_Mode_RegSimult_AlterTrig               ((uint32_t)0x00020000)

#define ADC_Mode_InjecSimult_FastInterl            ((uint32_t)0x00030000)

#define ADC_Mode_InjecSimult_SlowInterl            ((uint32_t)0x00040000)

#define ADC_Mode_InjecSimult                       ((uint32_t)0x00050000)

#define ADC_Mode_RegSimult                         ((uint32_t)0x00060000)

#define ADC_Mode_FastInterl                        ((uint32_t)0x00070000)

#define ADC_Mode_SlowInterl                        ((uint32_t)0x00080000)

#define ADC_Mode_AlterTrig                         ((uint32_t)0x00090000)

is it ?

ivanov-i2
Associate II
Posted on August 03, 2011 at 09:23

Look at chapter 11.9 and the description of ADC_CR1 in paragraph 11.12.2 of RM0008 - STM32F1xx Reference Manual.

The definitions, which you found, are different variants of the dual ADC mode.