cancel
Showing results for 
Search instead for 
Did you mean: 

Triple ADC mode with DMA [STM32F4 discovery]

ronandouguet
Associate II
Posted on February 20, 2012 at 14:52

The original post was too long to process during our migration. Please click on the attachment to read the original post.
22 REPLIES 22
raptorhal2
Lead
Posted on February 20, 2012 at 16:23

Change ScanConvMode from DISABLE to ENABLE for all 3 ADCs to get the second and third channel converted. The library example you may have started from converted only one channel.

Depending on your tension (pressure?) signal impedance, you may want to increase the sample time for better accuracy, but that is not related to the problem of converting only one channel.

Minor nit: PAO is ADC123_IN0, not _IN12.

Cheers, Hal

ronandouguet
Associate II
Posted on February 20, 2012 at 17:45

Thanks for your response.

Now, I do the three conversions ! It is great :) I will set the sample time depending on the sensors (anemometer, clinometer...) But I still have a problem. A flashing led at every interrupt (of DMA2_stream0) and I test the new example :

int main(void)
{
uint16_t i;
// Initialisation Hardware
HwInit();
for (i=0;i<9;i++)
{
ADCTripleConvertedValue[i]=i;
}
/* Infinite loop */
while (1)
{
/* Analog to digital converter */
DelayMS(100);
ADC_SoftwareStartConv(ADC1); // Start ADC
}
}
/**
* @brief This function handles DMAx global interrupt request.
* @param None
* @retval None
*/
/* Private define ------------------------------------------------------------*/
#define DMA2_IRQHANDLER DMA2_Stream0_IRQHandler
uint16_t AN0, AN1, AN2, AN3, AN4, AN5, AN6, AN7, AN8;
void DMA2_IRQHANDLER(void)
{
if(DMA_GetITStatus(DMA2_Stream0, DMA_IT_TCIF0) != RESET)
{
DMA_ClearITPendingBit(DMA2_Stream0, DMA_IT_TCIF0); // Reset du Flag
GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
AN0 = DMA_GetADC(0) & 0x0FFF; 
AN1 = DMA_GetADC(1) & 0x0FFF; 
AN2 = DMA_GetADC(2) & 0x0FFF; 
AN3 = DMA_GetADC(3) & 0x0FFF; 
AN4 = DMA_GetADC(4) & 0x0FFF; 
AN5 = DMA_GetADC(5) & 0x0FFF; 
AN6 = DMA_GetADC(6) & 0x0FFF; 
AN7 = DMA_GetADC(7) & 0x0FFF; 
AN8 = DMA_GetADC(8) & 0x0FFF; 
}
else
{
USART_SendString(USART3,''error 
'');
}
}

Normaly the frequence of flashing led must be 5 Hz (1/2*100ms) but the led : turn on : 100 ms turn off : 100 ms tunr on : 200 ms turn off : 100 ms ... I don't see where does the error. Thank again, Ronan.
raptorhal2
Lead
Posted on February 20, 2012 at 22:02

I will set the sample time depending on the sensors (anemometer, clinometer...)

Remember, the sampling times for each simultaneous conversion have to be equal.

But I still have a problem. A flashing led at every interrupt (of DMA2_stream0) and I test the new example :

The problem is not clear to me. LED Pin D12 is also USART3 RTS. If that is not the problem, please describe the problem differently.

Cheers, Hal

ronandouguet
Associate II
Posted on February 21, 2012 at 09:48

Sorry for my first explanation which is not clear.

To verify that there is an interrupt (DMA) every 100 ms, I use a Led. Every DMA interrupt, I make a flashing led. Normally the led must flash at 20 Hz (if there is a conversion every 100ms).

But when I tested my program the led don't flash regulary and i don't see where does the problem ?

Regards,

Ronan.
raptorhal2
Lead
Posted on February 23, 2012 at 19:28

If you toggle the LED every 100 msec, the LED will flash 5 times per second. That is probably visible, but to be sure, slow it down with a 500 msec delay.

I can't find anything wrong. Put a count variable on each ADC conversion command and each DMA interrupt, run for a few seconds, then inspect the count variables in Debug mode. This may isolate the problem to main or the DMA handler, or the LED init.

Cheers, Hal

ronandouguet
Associate II
Posted on February 29, 2012 at 17:31

Hi Hal,

I observe

signals

with

a scope so

not need to change

interrupt timer (every 100ms).

I verified the differents interrupts :

   -> ADC interrupt : every 100 ms

   -> DMA interrupt : the cycle is 100 ms, 100ms, 200 ms, 200ms

So the problem comes DMA Handler but I don't see where ?

Maybe the FIFOMode or MemoryBurst ???

Thanks,

Ronan.

raptorhal2
Lead
Posted on March 01, 2012 at 18:27

See my post STOne-32 ADC Lib Examples Problem dated Feb 24 in the STM32 forum for one fix you need. It may not fix your current problem, but it will avoid other problems.

I am otherwise busy, but I will take a better look at your code in a few days if a fix has not been found by then.

Cheers, Hal

raptorhal2
Lead
Posted on March 04, 2012 at 18:43

There are two problems in utils.c:

The PA4 pin can be either ADC123_IN4 or DAC1_OUT, but not both. Change _IN4 to an available free _INx pin.

There are three channels set up for conversion per ADC, and a 9 word DMA buffer size, but the ADC init NumberOfConversions is only 2 per ADC. Change it to 3.

Cheers, Hal