Topic : Incorrect ADC reading - STM8S

Forum : ST7/STM8

Original Post
Post Information Post
May 27, 2015 - 10:48am
Guest account


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.)

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;


               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 2 –

Peak error – 22

Average error – 13

Channel 3 –

Peak error – 10

Average error – 3.5

2. Also, 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.

Post Information Post
May 27, 2015 - 10:49am
Etienne Cassin


We would like to help you as quickly as possible on this issue, but we need to have more informations about the problem before we can help further.

In order to understand the issue you are facing, we need the following information about your configuration:
- Version of Windows: At a command prompt type the following command: "systeminfo.exe", which gives you a system report. We need the full "Operating System" and "Version" from the report.
- Version of Ride7 and RKit that you are using. You can get these from the Ride7 "Help | About" dialog box.
- Your Ride7 serial key or your RLink/Primer/Open4 serial number.
Please check from the Raisonance downloads page at that you are using the latest version of the tools.

1) Raisonance toolsets and Ride7 operate on Windows 7 (32 and 64-bit), Windows Vista (32 and 64-bit) and Windows XP SP3 (32-bit only). Other versions of Windows, including Windows 2000, Windows XP 64-bit and Windows Server, are not supported.
2) Only native versions of Windows are supported. Emulators such as VMware, QEMU, Citrix, Wine, Xen (or others) are not supported.

Concerning your particular problem:
- Provide the steps you followed to raise the error.
- The precise error message you received, and which tool produced it. If possible, a screenshot of the message (using the PrtScr keyboard key) is helpful.
- Does the problem occur when using the examples given with Ride7 (from the Ride7 installation directory, default being "C:\Program Files\Raisonance\Ride\Examples\")?

The Raisonance support team.