cancel
Showing results for 
Search instead for 
Did you mean: 

ADC Conversion Time and DMA Interrupt

lars-kristian
Associate II
Posted on June 20, 2009 at 17:59

ADC Conversion Time and DMA Interrupt

4 REPLIES 4
lars-kristian
Associate II
Posted on May 17, 2011 at 13:15

Hi everyone,

I'm using the ADC 1&2 in regular simultaneous mode (dual mode) each converting three channels continously. The DMA 1 is configured to transfer the three values to memory and generate an EOT-Interrupt.

It all works fine, but the frequency of the returning Interrupt I measured isn't consistent with my calculated values.

The Clocks are configured as following:

SYSCLK = 56 MHz

AHB = 28 MHz

APB2 = 28 MHz

ADCCLK = 3.5 MHz

Sampletime 71.5 cycles of ADCCLK = 20us

Conversiontime 71.5+12.5 = 24us (each channel of ADC)

When I calculate it in this way(3 channels with 24us each = 72us for all of them before Interrupt is generated)I thought the Interrupt is generated after this time. But it isn't. I'm toggling a GPIO Pin with every DMA Interrupt and measure the high and low periods. And the result is...the Interrupt occurs every 40us. Does the ADC works faster in DUAL-Mode? I searched in the forum and just got one hint that the conversion time speeds up, when using the ADCs in dual mode. Is it right?

Or could there be any other failure in my Setup/calculation.

By the way, all the values I get are right, but the ADC is working faster then calculated.

Regards

Lars

shawn
Associate II
Posted on May 17, 2011 at 13:15

Lars,

I think the problem is in your calculation of the sample time. Sorry to not debug your math, but I will show you how I calculate it.

ADCCLK = 3,000,000 Hz

Sampling Setting = 71.5 Cycles (assumed for all three channels)

Conversion Time = 12.5 Cycles per channel

Sampling Time = 84 Cycles / 3MHz = 28.0 uS

Channels = 3

Total Sample Time = 28.0 * 3 = 84 uS

This gives a sample frequency of 11,905 Hz.

These values are higher than yours, what are your clock settings? Can you show some code? Are you running two separate DMAs for both ADCS and seeing two interrupts which makes you think it is half of the 82uS?

Shawn

lars-kristian
Associate II
Posted on May 17, 2011 at 13:15

Hi Shawn,

for some other reasons I had to rewrite my code.

I think I calculated it in the same way. After setting up my new code the clocks are runnig with these frequencies:

ADCCLK: 3,500,000 Hz

APB2: 28,000,000 Hz

AHB: 56,000,000 Hz

The new ADC Settings:

ADCCLK: 3,500,000 Hz

Sampling Setting: 239.5 Cycles

Conversion Time 12.5 Cycles

Sampling Time: 252 Cycles/3.5 MHz = 72 uS

Channels: 3 (for tests I only use ADC 1)

Total sample time = 216 uS --> sample frequency = 4,629 Hz

I'm using just one DMA for transferprocess and still toggling a GPIO_Pin with every End of transfer interrupt.

I measure the toggling speed of the GPIO_Pin and still get a frequency with 10,640 Hz.

For the configuration of the clocks I used the Init-file provided by Keil. I checked their code and it is right. All the timers I configured are running with the right speed.

So what could be the reason for my problem?

Now I'm surprised, cause it's 2.5 times faster than I calculated.

Some Code:

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;

DMA_InitStructure.DMA_MemoryBaseAddr=(u32)ADC12ConvertedValue;

DMA_InitStructure.DMA_DIR=DMA_DIR_PeripheralSRC;

DMA_InitStructure.DMA_BufferSize=3;

DMA_InitStructure.DMA_PeripheralInc=DMA_PeripheralInc_Disable;

DMA_InitStructure.DMA_MemoryInc=DMA_MemoryInc_Enable;

DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;

DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;

DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;

DMA_InitStructure.DMA_Priority = DMA_Priority_High;

DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

DMA_Init(DMA1_Channel1, &DMA_InitStructure);

/* Enabele EOT-Interrupt */

DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);

/* Enable DMA1 Channel1*/

DMA_Cmd(DMA1_Channel1, ENABLE);

ADC:

ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

ADC_InitStructure.ADC_ScanConvMode = ENABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 3;

ADC_Init(ADC1, &ADC_InitStructure);

/* ADC regular channels configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_4,3, ADC_SampleTime_239Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14,1, ADC_SampleTime_239Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_15,2, ADC_SampleTime_239Cycles5);

ADC_DMACmd(ADC1, ENABLE);

Regards,

Lars

Update:

I partly fixed the problem. My project requires the use of regular and Simultaneous converted AD-Channels. So I set up the ADC as Regular injected simultaneous mode a week ago. As soon as I disable the injected channel configuration the sampling frequency is the same as the calculated. It only appears when the regular and the injected channels are the same. So here's some code, that shows this configuration:

/* ADC regular channels configuration */

ADC_RegularChannelConfig(ADC1, ADC_Channel_4,3, ADC_SampleTime_239Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_14,1, ADC_SampleTime_239Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_15,2, ADC_SampleTime_239Cycles5);

/* ADC injected channels configuration */

ADC_InjectedSequencerLengthConfig(ADC1, 2);

ADC_InjectedChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_28Cycles5);

ADC_InjectedChannelConfig(ADC1, ADC_Channel_5, 2, ADC_SampleTime_28Cycles5);

I thought I can configure a few channels as regular ones, and when I need a few of them for special purposes, I trigger the injected group and get the values. Does this work? The reference manual says it should work.....

In what connection does the injected mode stands with the sampling frequency?

[ This message was edited by: lars-kristian.elsner on 20-06-2009 19:39 ]

[ This message was edited by: lars-kristian.elsner on 20-06-2009 20:30 ]

[ This message was edited by: lars-kristian.elsner on 20-06-2009 20:30 ]

lars-kristian
Associate II
Posted on May 17, 2011 at 13:15

Problem fixed.

I didn't notice that the sample setting for each channel can be different, but not between regular and injected conversion. So I changed the sampling setting for the injected channels and now it works.

Regards

Lars