Page 1 of 1

ADC working

Posted: Mon Jan 28, 2013 5:15 pm
by Faisal Mehmood
Hey guys I have never worked with an ADC so want to ask a basic question

I need to use three channels of ADC...

1) Will the conversion of the three channels run in parallel??

2) will i get a single interrupt for completion of adc conversions or an individual interrupt for each channel??

Re: ADC working

Posted: Mon Jan 28, 2013 5:20 pm
by Tectu
1) This depends on the MCU you are using. Most MCUs come with one ADC which has multiple channels. The channels are multiplexed and therefore the conversations work in parallel. However the newer / bigger MUCs like the STM32F4 come with two or even three independend ADCs. Therefore possible that you can make three conversations in parallel.

2) Mostly the callback function of the ADC driver is used. You can use the same or different callback routines for each ADC channel configuration.


~ Tectu

Re: ADC working

Posted: Mon Jan 28, 2013 5:38 pm
by Faisal Mehmood
em using stm32f4 discovery

the adcgrpcfg structure is programmed as:

Code: Select all

static const ADCConversionGroup adcgrpcfg = {
  FALSE,
  ADC_GRP1_NUM_CHANNELS,
  adccb,
  NULL,
  /* HW dependent part.*/
  0,
  ADC_CR2_SWSTART,
  ADC_SMPR1_SMP_AN11(ADC_SAMPLE_56) | ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_144),
  0,
  ADC_SQR1_NUM_CH(ADC_GRP1_NUM_CHANNELS),
  0,
  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN11) | ADC_SQR3_SQ1_N(ADC_CHANNEL_SENSOR)
};


Here is a single adccb function as callback.. how can i add individual callbacks for each channel?

Re: ADC working

Posted: Mon Jan 28, 2013 5:54 pm
by Tectu
You can assign a different callback to each conversion group separately by passing a different ADCConversionGroup to the adcStartConversion() routine.

tl;dr -> simply group your channels by the callback you want for them and create unique ADCConversionGroup structures.

Also, you might want to check out this thread.


~ Tectu

Re: ADC working

Posted: Mon Jan 28, 2013 6:07 pm
by Faisal Mehmood
Thanx tectu for your timely responses :)

I'll surely visit that thread

Re: ADC working

Posted: Mon Jan 28, 2013 6:08 pm
by Tectu
No problem. You're welcome and I am always totally happy when I can help other people.
Feel free to ask future questions, but make sure you don't miss the documentation completely ;-)


~ Tectu

Re: ADC working

Posted: Mon Jan 28, 2013 6:23 pm
by Faisal Mehmood
hahaha yeah surely :lol:

my practise is to check stm32f4 reference manual and chibios hal reference for any problem.... I ask you guys if the official documents can't clear my misunderstanding :)

Re: ADC working

Posted: Mon Jan 28, 2013 6:25 pm
by Tectu
That's the way to go :)


~ Tectu