cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure two channel of ADC1 single shot mode ?

rumlyen
Associate II
Posted on February 02, 2017 at 23:59

Hi,

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.

My conf:

-----------

{

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;  

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;

  GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* Enable ADC1 clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);

 /* ADC1 DeInit */  

  ADC_DeInit(ADC1);

  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_Init(ADC1, &ADC_InitStructure);

ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_9Cycles); 

//

ADC_RegularChannelConfig(ADC1, ADC_Channel_3, 1, ADC_SampleTime_9Cycles); 

  ADC_Cmd(ADC1, ENABLE);

 /* 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

1 REPLY 1
Posted on February 03, 2017 at 06:32

Not got much insight into the L1, but pretty sure it want to route the signal via the VCOMP switch

Can you use the Injected method to occasionally grab out-of-band samples of PC3?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..