ADC working

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

ADC working

Post 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??
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: ADC working

Post 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
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: ADC working

Post 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?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: ADC working

Post 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
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: ADC working

Post by Faisal Mehmood »

Thanx tectu for your timely responses :)

I'll surely visit that thread
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: ADC working

Post 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
Faisal Mehmood
Posts: 25
Joined: Sat Jan 26, 2013 10:18 pm

Re: ADC working

Post 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 :)
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: ADC working

Post by Tectu »

That's the way to go :)


~ Tectu
Post Reply