I request some guidance to configure ADC.
I have ADC1_Ch1 (single mode) to read analog voltage (PA1) in every 10ms timer interrupt with other sensors to maintain synchronization with them. For a battery protection, I've connected the battery to COMP1 (PC3) via the voltage divider. I thought COMP1 can work independently. But I've found in L151 datasheet that (COMP1 comparator and ADC cannot be used at the same time since they share the ADC switch matrix. ATTACHED here). Is the whole ADC block or that specific channel ?
PC3 has ADC1_ch3 which I'm planning to employ for battery in another single mode (say checking battery value in every 10s). Is there any way to configure two-channels of ADC1 in single mode? Or how can it read two channels individually while they share same ADC DR ? Switching channels from Ch1 to Ch3 by this command: ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_9Cycles);
Or, one in single shot another continuous ?
Or is it a good idea to turn on COMP1 momentary in every 10s and check battery level and switch back to ADC?
I request your kind comment in it.
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
/* Enable ADC1 clock */
/* ADC1 DeInit */
ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_9Cycles);
// ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_9Cycles);
/* Wait until the ADC1 is ready */
while(ADC_GetFlagStatus(ADC1, ADC_FLAG_ADONS) == RESET)
Read ADC data:
ADC1->CR2 |= (uint32_t)ADC_CR2_SWSTART; // ADC starts
ADC1->SR = ~(uint32_t)ADC_FLAG_EOC; // ADC conversion done
Value= ADC1->DR; // Save ADC data