STM32F4 ADC configuration

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

Moderator: RoccoMarco

erfan
Posts: 14
Joined: Sat Apr 18, 2015 4:25 pm

Re: STM32F4 ADC configuration

Post by erfan »

Hey guys,
I'm using STM32F30x. In mcuconf.c files of some examples which are provided in testhall folder, I realized that just ADC1 and ADC3 have been enabled as following configuration:

#define STM32_ADC_USE_ADC1 TRUE
#define STM32_ADC_USE_ADC3 TRUE

As I know this kind of STM32F30x has four ADC main ports. I want to know if it's possible to use ADC2 and ADC4 as well.
Screenshot 2015-04-20 15.14.22.png
Screenshot 2015-04-20 15.14.22.png (33.96 KiB) Viewed 5750 times


Thank you.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 ADC configuration

Post by Giovanni »

Hi,

ADC2 and ADC4 currently can only be used in "dual mode" but not alone.

It would be possible to modify the driver to allow the use in single mode but it would be not so immediate because ADC1 and ADC2 share a clock enable, ADC3 and ADC4 share another one. Enabling one unit means necessarily enabling the other one that would make handling clocks a bit messy.

Do you need 4 independent ADCs?

Giovanni
erfan
Posts: 14
Joined: Sat Apr 18, 2015 4:25 pm

Re: STM32F4 ADC configuration

Post by erfan »

Thanks Giovanni for your reply. Actually I was curious to find out why there is no sign of other ADCs in mcuconf.h :D To be honest I have just started using your valuable RTOS and I'm very grateful for that.
I'm working on ADC example right now. So would you please tell me about samples array? As I noticed, this is a one dimension array with the length of # of channel * Buffer Depth. Is that correct? and if it's correct so, would you tell me how exactly this array will fill by ADC converting.
Thank you again,
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 ADC configuration

Post by Giovanni »

Hi,

Samples are an M*N matrix, where M is the number of channels defined in a conversion group structure, N is the number of times the conversion is performed (the parameter to adcConvert()).

See the demo application under ./testhal, an example of matrix is shown there.

The most simple case is when the group contains a single channel and you convert it only once M=1,N=1, just one sample.

Giovanni
erfan
Posts: 14
Joined: Sat Apr 18, 2015 4:25 pm

Re: STM32F4 ADC configuration

Post by erfan »

Hi Giovanni,
You mentioned that samples are M * N Matrix.
Capture.PNG
Capture.PNG (9.84 KiB) Viewed 5709 times

So if I want to have access to the arrays of this matrix, I should recall them by using "samples1[m] [n]"?
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 ADC configuration

Post by Giovanni »

It depends on how you declared "samples1", you could access it both as an array or as a matrix.

In HAL demos it is an array with one M*N dimension.

Giovanni
erfan
Posts: 14
Joined: Sat Apr 18, 2015 4:25 pm

Re: STM32F4 ADC configuration

Post by erfan »

Just one more question :) Before going further in programming I want to know how ADC conversation would fill "sample1" array. I thought in the way shown below ;) , is this correct?
aaa.png
aaa.png (13.99 KiB) Viewed 5702 times

Thanks,
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 ADC configuration

Post by Giovanni »

Nope, one row contains all channels belonging to a group. The driver writes channels sequentially in memory.

Giovanni
erfan
Posts: 14
Joined: Sat Apr 18, 2015 4:25 pm

Re: STM32F4 ADC configuration

Post by erfan »

Hi Mr.Giovanni,
It seems that I didn't get your point, unfortunately I'm a little confused :(
As you said before, we can deal with buffer memory as an array with M*N dimension. So would you please tell me that is the following illustration exactly shows how the driver writes channels in memory?
Memory.png
Memory.png (50.28 KiB) Viewed 5672 times

Thanks,




Giovanni wrote:Nope, one row contains all channels belonging to a group. The driver writes channels sequentially in memory.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 ADC configuration

Post by Giovanni »

The last image is correct.

Giovanni
Post Reply