cancel
Showing results for 
Search instead for 
Did you mean: 

ADC continuous mode with 5 channels - STM8S105K6

gcorrea
Associate II
Posted on June 25, 2009 at 06:27

ADC continuous mode with 5 channels - STM8S105K6

8 REPLIES 8
gcorrea
Associate II
Posted on May 17, 2011 at 15:02

Hi,

I would like to know how to use the ADC1 DATA BUFFER in order to acquire 5 channels simultaneously.

I use the STVD 4.1.1 with Cosmic compiler and the FW library.

Is the code bellow correct?

(The ADC1Init is used first for all channels, and then the ADC1Cmd(ENABLE), both functions from the stm8s_adc1.c)

VIN = ADC1_GetBufferValue(1); // ADC1 channel 1??

VOUT = ADC1_GetBufferValue(2); // ADC1 channel 2??

(...)

IBAT = ADC1_GetBufferValue(5); // ADC1 channel 5??

How does the scan mode works? Can I use it for channels from 1 to 5 only?:-o

Thanks,

Guilherme

mozra27
Associate II
Posted on May 17, 2011 at 15:02

Hi Gcorrea,

The following software using the library can configure the ADC1 in the scan mode for 5 channels:

/* Enable ADC1 */

ADC1_Cmd(ENABLE);

/* Enable scan mode */

ADC1_ScanModeCmd(ENABLE);

ADC1_ConversionConfig(ADC1_CONVERSIONMODE_SINGLE, ADC1_CHANNEL_5, ADC1_ALIGN_RIGHT);

/*Start Conversion */

ADC1_StartConversion();

/* Wait until end of conversion */

while (!ADC1_GetFlagStatus(ADC1_FLAG_EOC));

/* Clear end of conversion flag */

ADC1_ClearFlag(ADC1_FLAG_EOC);

for (i = 0; i

{

/* Get conversion value from buffers */

val[i]= ADC1_GetBufferValue(i)

}

The ADC1 scan mode works for all the channels available on the product, refer to the product datasheet to check the channels availability (it depend from the product package)

Regards

mozra

gcorrea
Associate II
Posted on May 17, 2011 at 15:02

Hi mozra,

Thank you very much! :-] Only one more thing regarding the comment: ''The ADC1 scan mode works for all the channels available on the product''

The datasheet says: ''Scan mode for single and continuous conversion of a sequence of channels''

Will the scan mode works even if I use the one of the inputs of the ADC for other purposes? For example: ADC1 ch0 will be used as an GPIO Output pin and the channels from 1 to 5 used as analog inputs for the ADC. Is it ok?

Regards,

Guilherme

mozra27
Associate II
Posted on May 17, 2011 at 15:02

Hi Guilherme,

The scan mode is fixed to start from ch0 and you can specify the channel number, so your case doesn't working.

On the other hand you can use ADC1 ch5 as a GPIO Output pin and the channels from 0 to 4 used as analog inputs for the ADC.

Regards

Mozra

adriano2
Associate II
Posted on May 17, 2011 at 15:02

Hi All

I have the same situation of Guillerme:

I've fixed AIN3, AIN4, AIN5 and AIN6 (on STM8S103) as Analog Inputs and AIN2/PC4 as GPIO.

Could I use Scan Mode? On RM there is written ''When using scan mode, it is not possible to use channels AIN0 to AINn in output mode because the output stage of each channel is disabled when it is selected by the ADC

multiplexer''

Many thanks for your support

Genius1974

mozra27
Associate II
Posted on May 17, 2011 at 15:02

Hi Genius,

The scan mode is used to convert a sequence of analog channels from AIN0 to AINn where ‘n’ is the channel number defined by the CH[3:0] bits in the ADC_CSR register. But if n is lower than 6(STM8S103x channels numbers) you can use the remains channels in output mode

Sorry your case doesn't working because you want to start from AIN3 :-]

if is it possible you can use AIN0, AIN1, AIN2 and AIN3 (on STM8S103) as Analog Inputs and AIN4 or AIN5 as GPIO.

Regards

mozra

adriano2
Associate II
Posted on May 17, 2011 at 15:02

Hi Mozra27

thank you for your answer, I already produced the board. :-[

I have a final question:

- in case I don't use the Scan Mode Feature, can I use PC4/AIN2 as GPIO?

Many Thanks

Genius1974

[ This message was edited by: Genius1974 on 24-06-2009 15:18 ]

mozra27
Associate II
Posted on May 17, 2011 at 15:02

Hi Genius,

Yes, in this case you don't have issue to use all analog inputs as GPIO.

regards

mozra