cancel
Showing results for 
Search instead for 
Did you mean: 

How do you change the ADC channel?

LMI2
Lead
Posted on April 26, 2016 at 10:50

I made code with the STMCubeMX. It has several ADC channels enabled. I have read the stm32f4xx_hal_adc.c file and others through, but I can't find the channels in the code.

How are more than one channels handled?

I am now using MB997C, but it is the same with other CPUs too.
5 REPLIES 5
Walid FTITI_O
Senior II
Posted on April 26, 2016 at 11:48

Hi mich.lei,

Can you give us more details about :

version of CubeMx ?

The STM32 devices that you are using ?

Did you try to select more than one channel for ADC and the code generated does not contains that ?

-Hannibal-

LMI2
Lead
Posted on April 26, 2016 at 14:44

Hi

I am trying this with a Discovery F407 board MB997C. CPU is 407VGT. Cube is ver. 4.0.

Yes, I enabled several ADC channels with Cube tool, but I cannot find out how to use them. There are no channels mentioned in suitable places. I saw a post from Clive1, I think, using some register ''hack'', but that does not help much. And it was not from CubeMX.

This is very early stage of the project, nothing secret, so I have attached the .ioc and document files so you can see yourself. I have tried this with 207CPU, and it had the same problem. The name of this test is adcINTtim, but I am going to start with polling/blocking method first.

Thank you for your answer

Leif

________________

Attachments :

adcinttim.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htlc&d=%2Fa%2F0X0000000aWf%2FObTucrJNno8iKNsikcpszesA_rDftX4tJPA5J.RJsJI&asPdf=false
Posted on April 26, 2016 at 15:54

Pity you couldn't actually provide a cite.

The standard method to do multiple channels is to enumerate a list and use DMA.

If you want to do one channel at a time, then you'll have to keep reconfiguring the ADC each time, and waste a lot of time doing that, rather than just letting is read two or more channels into an array, and discarding the value(s) you don't actually need.

Having a method that constantly reconfigures the ADC seems a bit of a hack, perhaps you want to evaluate the paradigm you are forcing on the hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Walid FTITI_O
Senior II
Posted on April 26, 2016 at 17:11

Hi

mich.lei,

,

If I understand well your problem, you are not , in fact, enabling the channel you just select the ADC pinout. To enables several channels in CubeMx you should increase the number of conversion and select a channel for each Rank, as shown in figure below:

0690X00000602bSQAQ.jpg

I have reproduced the case and I share with you the .ioc file (see attached)

-Hannibal

-

Hi

I am trying this with a Discovery F407 board MB997C. CPU is 407VGT. Cube is ver. 4.0.

Yes, I enabled several ADC channels with Cube tool, but I cannot find out how to use them. There are no channels mentioned in suitable places. I saw a post from Clive1, I think, using some register ''hack'', but that does not help much. And it was not from CubeMX.

This is very early stage of the project, nothing secret, so I have attached the .ioc and document files so you can see yourself. I have tried this with 207CPU, and it had the same problem. The name of this test is adcINTtim, but I am going to start with polling/blocking method first.

Thank you for your answer

Leif

________________

Attachments :

adcinttim.ioc : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htlh&d=%2Fa%2F0X0000000aWg%2F_09FVqzxUHXnqegQdnRwx9L5frscF42aQxRFOvQxvEE&asPdf=false
LMI2
Lead
Posted on April 26, 2016 at 19:01

Thank you. I see ADC channels now.

Clive1, if you asked for some code, there was no code from myself. All I did at this stage was to read the files and trying find out how to do things.

Hannibal, you guessed correctly, I did not notice the tab in the Cube tool. Your .ioc file is much better.

I have just started to study the code and I have a few questions, please.

In this configuration, all the enabled channels are now read, one after another?  Do the polled functions work correctly. Life is easy if you have a single channel only? I have tried a single channel ADC with polling methods.

What is the best way to study DMA or interrupt driven conversion?

That is, I need to know what is the conversion result/buffer data size (32bits?). How do you know the number of conversion rounds?

Regards

Leif