cancel
Showing results for 
Search instead for 
Did you mean: 

Incorrect ADC readings

lior2
Associate
Posted on March 03, 2015 at 11:58

Hi,

I have encountered with some issues with ADC readings.

I’m using STM8S003F3 and reading 4 of 5 ADC channels (2, 3, 4, 6) and the readings are not as expected.

For testing the ADC readings, I use STM8S003-Discovery and with a voltage divider for all channels sourced by the 3.3VDC i.e.:

The voltage for channel 0 is 2.63VDC and I expect to read from ADC 815.

The voltage for channel 1 is 1.98VDC and I expect to read from ADC 613.

The voltage for channel 2 is 1.32VDC and I expect to read from ADC 410.

The voltage for channel 3 is 0.66VDC and I expect to read from ADC 206.

(The STM8S003-Discovery (STM8S003K3) has only 4 ADC channels.)

Connection as describe in the attached Resistors.jpg.

In the main loop, I use ADC reading as single channel single conversion mode, and read each time the next channel repeatedly from channel 0 to channel 3.

This is the initialization I have in my code:

               ADC_CR1_SPSEL = 0;                     

               ADC_CSR_CH = channel_0;          

               ADC_CR3_DBUF = 0;

               ADC_CR1_CONT = 0;

               ADC_CR2_ALIGN = ADC_ALIGNMENT;

               ADC_CSR_EOCIE = 0;

               ADC_CSR_AWDIE = 0;

Which:

               channel_0 is the first channel to be read.

               ADC_ALIGNMENT is set to be ADC_RIGHT_ALIGNMENT.

However, there are two phenomena:

1. There are a big difference between the actual reading and the desire (calculate) readings.

As you can see in the attached STMStudio screen shot, there peak of difference ADC reads about ~±20 bits(!).

Channel 0 –

Peak error – 22

Average error – 13

Channel 1 –

Peak error – 9

Average error – 2.5

Channel 3 –

Peak error – 22

Average error – 13

Channel 4 –

Peak error – 10

Average error – 3.5

(The total data, average and other calculations is shown in the attach excel file.

In the excel file there are three columns – desire readings, actual readings and the different between them)

2. Also, you can see (in the attached screen shot and excel file) there is different in error rate between channels 0,2 and channels 1,3.

I have tried several ways to get better accuracy such as lower the ADC frequency reading by changing the prescaler for 3 (error rate is ~±12 bits) and read twice the same channel each time (error rate is ~±12 bits).

Is it common error rate, isn’t should be much lower error rate?

Is there other configuration I have to configure?

Please reply as soon as possible.

Thank you in advance.

0 REPLIES 0