cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 Seamless ADC Channel Configuration Switching

joeyjumpers
Associate II

I have two sets (set A, set B) of 3 ADC channels that I'm sampling using continuous multi mode w/ DMA. For latency reasons, I'd prefer to sample set A for a while (let's say 1 msec), followed by sampling set B for a while, followed by sampling set A for a while, etc. I would prefer NOT to interleave every sample, e.g., by setting a sequence length 2.

As I have discovered, switching ADC configuration channels on-the-fly in DMA mode really can't be done. Ideally I would just like to call ADC_RegularChannelConfig(...) on-the-fly, but I get DMA errors. Makes sense. Referencing the RM and some online docs, I have a switch sequence similar to the following:

 ADC_Cmd(ADC1, DISABLE);

 ADC_Cmd(ADC2, DISABLE);

 ADC_Cmd(ADC3, DISABLE);

 DMA_Cmd(DMA2_Stream0, DISABLE);

 while (DMA_GetCmdStatus(DMA2_Stream0) == ENABLE); // Wait for DMA shutdown.

 // Switch ADC configuration.

 ADC_RegularChannelConfig( ... );

 ADC_RegularChannelConfig( ... );

 ADC_RegularChannelConfig( ... );

 // Re-enable ADCs and DMA. 

 ADC_Cmd(ADC1, ENABLE);

 ADC_Cmd(ADC2, ENABLE);

 ADC_Cmd(ADC3, ENABLE);

 DMA_Cmd(DMA2_Stream0, ENABLE);

 // Restart conversion.

 ADC_SoftwareStartConv(ADC1);

This switch sequence works reliably. The major issue I have is that ADCs are somewhat inaccurate (I have plots taken over millions of samples to prove it) for hundreds of us immediately after calling ADC_Cmd(..., ENABLE). In my application, I can't wait around for ADCs to become accurate, I need the data right away. So you see my problem here.

Major questions are:

1) Is the switch sequence I have above optimal? Any alternative that doesn't make me disable ADCs to switch?

2) Is there anything I can do to make ADCs more accurate immediately after the switch sequence?

0 REPLIES 0