cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F205 ADC in non Scan Mode

martin
Associate II
Posted on February 06, 2014 at 08:36

G'day,

I am working with the STM32F205 and despite having carefully read the ADC chapter in the Family Reference Manual (RM0033) I seem to be missing something...

Page 231 of RM0033 Rev 5 says that the SCAN bit in the ADC_CR1 register enables or disables the ADC's scan mode.  It goes on to say that ''In scan mode, the inputs selected through the ADC_SQRx or ADC_JSQRx registers are converted''.  OK so far.  But the whole chapter doesn't seem to mention how, if you do not use scan mode, you control which ADC input is to be converted... ?

In my case, I just want to perform an occasional A to D conversion of a single input channel, initiated by my code on a casual ''as needed'' basis, with my code waiting for the conversion to complete by polling the EOC flag then reading the result from the ADC Data Register.  This does not seem to justify the complexity of setting up and using the ADC's Scan mode, but I cannot seem to see how I specify which ADC channel I wish to convert when not using scan mode... ?

Hopefully I am just missing something obvious.  Perhaps the relevant page has fallen out out of my RM0033 PDF file ?

Any suggestions would be  appreciated...

Thanking you,

mai-au.

7 REPLIES 7
chen
Associate II
Posted on February 06, 2014 at 10:26

Hi

The documentation is not great.

If I have understood you correctly, you just want to read the ADC on 1 channel when your code want it to.

You are reading the wrong section, read the section titled ''Single conversion mode''

Scan mode is for getting the ADC to do a conversion of more than channel. The ADC can cycle through the channels doing conversions on each channel and then moving onto the next. The whole thing starts to become quite complicated (eg where does the output get stored)

The Single Conversion mode should be simple and straight forward.

martin_irvine
Associate II
Posted on February 06, 2014 at 16:15

Hello sung.chen_chung,

Thank you for your reply.  You have understood me correctly.  I believe I understand what scan mode does and it's complications, which is why for my current simple requirement I would prefer to use single conversion mode.

Section 10.3.4 ''Single Converion Mode'' in the RM0033 manual says ''In Single conversion mode the ADC does one conversion...''  OK, so that's what I want.  It also says ''Once the conversion of the selected channel is complete...''  But how do I specify the selected channel for Single Conversion Mode ?

Section 10.3.3 ''Channel Selection'' talks about there being 16 multiplexed channels which can be organised into regular and injected groups by using the ADC_SQRx and ADC_JSQR registers.  But this is for Scan Mode, isn't it ?  How do I specify the one channel to use in Single Converion Mode ?

It seems to me there should be another 4 or 5 bits somewhere in one of the ADC registers to select the channel to be converted when operating in single conversion mode.  But the manual does not seem to mention this.  Or am I missing something important here... ?

Any further advice from anyone would be welcome, thank you.

mai-au.

chen
Associate II
Posted on February 06, 2014 at 16:25

Hi

From the reference manual :

''Channel selection

There are 16 multiplexed channels. It is possible to organize the conversions in two groups:

regular and injected. A group consists of a sequence of conversions that can be done on

any channel and in any order. For instance, it is possible to implement the conversion

sequence in the following order: ADC_IN3, ADC_IN8, ADC_IN2, ADC_IN2, ADC_IN0,

ADC_IN2, ADC_IN2, ADC_IN15.

• A regular group is composed of up to 16 conversions. The regular channels and their

order in the conversion sequence must be selected in the ADC_SQRx registers. The

total number of conversions in the regular group must be written in the L[3:0] bits in the

ADC_SQR1 register.

• An injected group is composed of up to 4 conversions. The injected channels and

their order in the conversion sequence must be selected in the ADC_JSQR register.''

You just set 1 channel in ADC_SQRx

martin_irvine
Associate II
Posted on February 06, 2014 at 17:01

Hello again sung.chen_chung, and thanks for your reply.

So, do you think the manual is saying that even for Single Conversion Mode you still have to setup a ''regular scan group'' using the ADC_SQRx registers, and in the case of wanting to do a simple single conversion of only one channel, you setup a ''regular scan group'' with only 1 channel in the channel list ?

If so, perhaps the important point here (that I was not understanding) is that the real difference between scan mode and single conversion mode is not about whether you are using only one channel or a number of channels, but whether each time you start the conversion only one channel gets converted or a number of channels get converted ?  So now I guess that in single conversion mode you could actually setup a ''regular scan group'' with say 5 channels in the list, and each time you start a conversion only one of the 5 channels will get converted, but the converted channel will advance through the list by one channel each time you manually start a conversion...

Do you think I am understanding this correctly now ?

Thanks again for your assistance,

mai-au.

Hi

From the reference manual :

''Channel selection

There are 16 multiplexed channels. It is possible to organize the conversions in two groups:

regular and injected. A group consists of a sequence of conversions that can be done on

any channel and in any order. For instance, it is possible to implement the conversion

sequence in the following order: ADC_IN3, ADC_IN8, ADC_IN2, ADC_IN2, ADC_IN0,

ADC_IN2, ADC_IN2, ADC_IN15.

• A regular group is composed of up to 16 conversions. The regular channels and their

order in the conversion sequence must be selected in the ADC_SQRx registers. The

total number of conversions in the regular group must be written in the L[3:0] bits in the

ADC_SQR1 register.

• An injected group is composed of up to 4 conversions. The injected channels and

their order in the conversion sequence must be selected in the ADC_JSQR register.''

You just set 1 channel in ADC_SQRx

chen
Associate II
Posted on February 06, 2014 at 17:32

Hi

''So, do you think the manual is saying that even for Single Conversion Mode you still have to setup a ''regular scan group'' using the ADC_SQRx registers, and in the case of wanting to do a simple single conversion of only one channel, you setup a ''regular scan group'' with only 1 channel in the channel list ?''

I guess so.

''  So now I guess that in single conversion mode you could actually setup a ''regular scan group'' with say 5 channels in the list, and each time you start a conversion only one of the 5 channels will get converted, but the converted channel will advance through the list by one channel each time you manually start a conversion...''

No, I think the behavior is undefined in this case.

If you set up more than 1 channel - it effectively becomes a Scan Mode and NOT a single convert. Once in ScanMode, setting off a conversion will trigger all the channels to be converted.

The problem (and complexity) is what happens to the output data. There is only 1 register for the output - where will the data go.

That is why (normally) the ScanMode is linked to DMA.

To be honest - I have not used the ADC peripheral so I am not 100% certain what will happen.

raptorhal2
Lead
Posted on February 06, 2014 at 22:44

To specify one channel to scan, use the following:

ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_28Cycles5);
Cheers, Hal

raptorhal2
Lead
Posted on February 06, 2014 at 22:50

''  So now I guess that in single conversion mode you could actually setup a ''regular scan group'' with say 5 channels in the list, and each time you start a conversion only one of the 5 channels will get converted, but the converted channel will advance through the list by one channel each time you manually start a conversion...''

 

No, I think the behavior is undefined in this case.

I believe the converted channel will always be the first one in the list.

Cheers, Hal