Question
Problem in ADC1 (Scan Mode, Buffered reading) Triggered by TIM1
Posted on May 16, 2014 at 16:19
Hi everyone
I am using STM8S003F3 in my board. for reading 5 analog inputs in regular interval I have used single conversion - scan mode - buffered ADC triggered by TIM1 by the following code//ADC1_DeInit ();
ADC1_Init ( ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_6, ADC1_PRESSEL_FCPU_D18, ADC1_EXTTRIG_TIM , ENABLE, ADC1_ALIGN_RIGHT, ADC1_SCHMITTTRIG_ALL, DISABLE ); ADC1->CR2 |= ADC1_CR2_SCAN;//ADC1_ScanModeCmd ( ENABLE ); ADC1->CSR |= (uint8_t)ADC1_IT_EOCIE;//ADC1_ITConfig ( ADC1_IT_EOCIE, ENABLE ); ADC1->CR3 |= ADC1_CR3_DBUF;//ADC1_DataBufferCmd ( ENABLE ); ADC1->CR1 |= ADC1_CR1_ADON;//ADC1_Cmd ( ENABLE ); and I configured TIM1 to trigger ADC1 in regular times with the following code//TIM1_DeInit ();
TIM1_TimeBaseInit (TIM1_PRESCALER, TIM1_COUNTERMODE_UP, TIM1_PERIOD, 0); // TIM1_ITConfig (TIM1_IT_UPDATE, ENABLE); TIM1->CR1 |= TIM1_CR1_ARPE;//TIM1_ARRPreloadConfig (ENABLE); TIM1_SelectOutputTrigger (TIM1_TRGOSOURCE_UPDATE); TIM1->CR1 |= TIM1_CR1_CEN;//TIM1_Cmd (ENABLE); when I run my program, it works normal for at least 30 seconds, after that the ADC buffer values get zero!!! it seems that all interrupts are working correct. A new clue that I found is that, ADC overrun flag is always SET from the start and as I checked, ADC triggering by TIM1 is slow enough to avoid over running! ( I even make triggering 10 times slower ) Even if I clear the over run flag, it gets SET again. I think buffer over running stops ADC from conversion input channels but I don't know how I can deal with this I appreciate if you give me your comments #stm8s-adc1-scan-mode #adc-stm8 #stm8-adc-problem