cancel
Showing results for 
Search instead for 
Did you mean: 

ADC+DMA Start with Timer delay -Help needed!-

arsalan_elec
Associate II
Posted on May 13, 2014 at 22:53

hello All,

i want to start an ADC with DMA in a timer(5) interrupt routine. when i test timer and adc individually they work right. but when i insert ADC start, in timer isr the timer and adc works once and then timer stays in the isr and adc does not start again. can anyone help me please? my code is looks like below. Thanks


void

TIM5_IRQHandler(

void

)

//Start ADC after delay

{
HAL_NVIC_ClearPendingIRQ(TIM5_IRQn);
HAL_TIM_IRQHandler(&htim5);
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_10);
HAL_ADC_Start_DMA((&hadc1) ,(uint32_t*)&uhADCxConvertedValue, 1000);
}
void

HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* AdcHandle)
{
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_11);
HAL_ADC_Stop_DMA(&hadc1);
}

4 REPLIES 4
arsalan_elec
Associate II
Posted on May 14, 2014 at 06:40

I found that when DMA sample length set under 540 instead of 1000, it works!

but the timer period is about 1ms and adc conversion take about 700us for 1000 samples and 400us for 540 samples. i really confused! does anyone have any idea ?
arsalan_elec
Associate II
Posted on May 15, 2014 at 08:52

still no one has any idea!

i found that when i start a timer and adc+dma only adc works and timer stay in interrupt routine. in main function i just add this:

__IO uint16_t data[1000];
int

main(

void

)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_ADC1_Init();
MX_TIM5_Init();
HAL_TIMEx_OCN_Start_IT(&htim5,TIM_CHANNEL_1);
HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&data,700);
...

and adc works but timer stays in interrupt. why?!!! if i don't start adc the timer works normally. please help me
Posted on May 15, 2014 at 15:29

still no one has any idea!

I think it's more the forum expressing disinterest with Cube and/or random fragments of code.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
arsalan_elec
Associate II
Posted on May 15, 2014 at 21:42

thanks clive1, your right! 

my problem was not from cube, i have some problems with keil, im new to it.

i found that when i declare ''TIM_HandleTypeDef htim5'' in tim.c and extern in time.h and declare in main.c as ''extern TIM_HandleTypeDef htim5'' the timer doesn't work. but vise versa if i declare it in main.c and use it in tim.c , code works normal. i still don't understand why.