Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Register Log in

Functions in while loop are not working when ADC DMA conversion

uranyumx

Junior Member level 1
Joined
Mar 5, 2011
Messages
18
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,427
Hello,


I successfully convert analog signals into digital with ADC DMA mode. But when ADC is converting the analog signals, the functions in while loop are not working. It looks like that while loop is not operating. Do you have suggestions about the solution?

Code:
volatile uint8_t convCompleted = 0;
 
int main(void)
...
    HAL_ADC_Start_DMA(&hadc1, (uint32_t*)ADCReadings_Evoked,50000);
 
    while(!convCompleted);
 
    HAL_ADC_Stop_DMA(&hadc1);
 
while (1)
 /* USER CODE BEGIN 3 */
        HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_RESET);
        HAL_Delay(1000);
        HAL_GPIO_WritePin(Led_GPIO_Port, Led_Pin, GPIO_PIN_SET);
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
46,985
Helped
13,938
Reputation
28,124
Reaction score
12,576
Trophy points
1,393
Location
Bochum, Germany
Activity points
273,962
There are two while loops. Of course the second doesn't start before the first has ended. If you wan't some code executed when the DMA transfer ends use an interrupt.
 

KlausST

Super Moderator
Staff member
Joined
Apr 17, 2014
Messages
17,464
Helped
3,945
Reputation
7,888
Reaction score
3,815
Trophy points
113
Activity points
115,783
Hi,

What are you trying to achieve?

DMA is useful when you want to run cun code while the ADC is converting data.
Code in the meaning of useful code.

But all you run is a useless "while" loop to wait for the ADC to be finished. Useless, because you don't make useful calculations or do anything useful.

So I see two options
* either you simply want to wait until the conversion is complete --> then don't use DMA but use a blocking ADC call.
* or you want to do something useful, then use ADC_DMA ... and run the code you want. And later check if the ADC has finished ...or use an DMA_interrupt.

ADC_DMA is useful when you want to convert "a lot of samples" before you want to process the ADC values.
Let's say 1000 samples with a sampling rate of 10kHz..which takes 100ms.

Klaus
 

Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top