cancel
Showing results for 
Search instead for 
Did you mean: 

Dual Adc and Dma

francois2
Associate II
Posted on January 20, 2009 at 16:14

Dual Adc and Dma

3 REPLIES 3
francois2
Associate II
Posted on May 17, 2011 at 12:58

Hi everyone,

I'm working on STM32F10xxB demoboard, and I'm using DualADC mode with continuous conversion mode in regular simultaneous mode.

I'm debugging on IAR Embedded, with JTAG, and I can't get something working properly. Each time I look at the ADC result (saved in two 16 bits variables) there is always a small difference between them, even if as input on the two ADC channels I have the exact same signal (shortcut between the pins).

Depending on the frequency of the signal (sin form) I obtain a difference between 2 and 65 or so... Here some part of my code. I read some posts about the order to start the DMA, or conversion but even though does not work. Thanks for any help ;).

//DMA1 Channel 1

DMA_Cmd(DMA1_Channel1, DISABLE);

DMA_DeInit(DMA1_Channel1);

DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1PeripheralAddress;

DMA_InitStructure.DMA_MemoryBaseAddr = (u32)adc;

DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

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_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);

ADC_Cmd(ADC1, DISABLE);

ADC_DeInit(ADC1);

//ADC1 Channel10

ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC1, &ADC_InitStructure);

//ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_1Cycles5);

ADC_RegularChannelConfig(ADC1, ADC_Channel_10, 1, ADC_SampleTime_71Cycles5);

ADC_Cmd(ADC1, ENABLE);

ADC_ResetCalibration(ADC1);

while(ADC_GetResetCalibrationStatus(ADC1)); //Wait reset calibration

ADC_StartCalibration(ADC1);

while(ADC_GetCalibrationStatus(ADC1)); //Wait calibration

ADC_Cmd(ADC2, DISABLE);

ADC_DeInit(ADC2);

//ADC2 Channel12

ADC_InitStructure.ADC_Mode = ADC_Mode_RegSimult;

ADC_InitStructure.ADC_ScanConvMode = DISABLE;

ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

ADC_InitStructure.ADC_NbrOfChannel = 1;

ADC_Init(ADC2, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_71Cycles5);

ADC_Cmd(ADC2, ENABLE);

ADC_ResetCalibration(ADC2);

while(ADC_GetResetCalibrationStatus(ADC2)); //Wait reset calibration

ADC_StartCalibration(ADC2);

while(ADC_GetCalibrationStatus(ADC2)); //Wait calibration

francois2
Associate II
Posted on May 17, 2011 at 12:58

Ok, im gonna reply myself, since no one else found apparently the solution. Well my mistake comes from the trigger setting. After checking one by one my code, I saw that the ADC2 was enable after ADC1 which is a big mistake. As well, the DMA for ADC2 does not need to be set up because anyway the DMA transfers 32 bits containing both ADC1, and ADC2 values.

Since they are working in DualMode only ADC1 should be started. The function ADC_ExternalTrigConvCmd(ADC2,ENABLE) should be called in order to set up the trigger for ADC2 done by ADC1. As soon as ADC1 starts ADC2 will be triggered. That didnt make any sense (still doesnt make any actually) since for me its not an external trigger, but internal.

Anyway, for me now its working, hope it will help others. Cheers, and good luck! :D

jj
Associate II
Posted on May 17, 2011 at 12:58

Hi Francois-

I applaud you for your effort and kindness in posting your solution. This is the true spirit of this forum - many have helped me - I have tried to repay...

Suspect that your posting issue was both difficult and a bit ''outside'' the major application area (sweet-spot) of most. Thus - no reply.

Agree with you that ''too often'' descriptions are ''not'' clear enough - subject to different interpretation. As a past tech-writer - would even a 1K page .pdf be enough? Recall - the guys writing the manual ''know'' this stuff - they need to constantly ''block-out'' this ''inside knowledge'' - putting themselves in the position of those of us clueless...