Showing results for 
Search instead for 
Did you mean: 

Adc in stm32f446re

Associate III

Analog source is potentiometer

Mcu board is nucleo f 446re

I am verifying adc code in debug mode with above hardware .as i rotate potentiometer  change in adc value can be observed.but when I don't rotate also, I am able to see the variation in 12bit value with variation about +-50d(max value)but this is not the desired operation.i need stable digital domain value for corresponding analog input how to verify it?à



Adding a capacitor on the potentiometer tap can help. As can choosing a potentiometer with lower impedance, say 10K or 1K, although that will eat up more current than one with higher impedance.

Using an encoder wheel along with a timer in encoder mode instead of a potentiometer will eliminate the jitter.

ADC values are expected to have some amount of jitter in most cases, although you can probably do better than 50 counts. Increasing sample time to max can provide improved accuracy. General tips for improving ADC accuracy are here:


If you feel a post has answered your question, please click "Accept as Solution".

Hi , I think this docx is very helpfull.

Is there any project which gives more handon on this.

Associate III

And while running the code in register level programming swstart bit of status register is not enabling to logic 1 and program is not giving output.

But when I creat the same using cube MX I am able to get the to fix it 

Associate III

Sorry for the multiple queries in one thread.

My analog signal is giving signal in audio frequency band .please suggest  about configuration  such speed , resolution and cycle and mode

Compare the MX code with your register level code for missing register initializations.


No No,If run cube MX code in debug mode it is throwing error


> Is there any project which gives more handon on this.

There are many ADC examples available in the CubeMX repository. Use the Example Selector to find them.

The original question has been answered. If you have another question, post a thread with relevant information, including your code, if that's the problem. Can't debug code we can't see.

If you feel a post has answered your question, please click "Accept as Solution".

This is my  adc.c

#include "adc.h"


void ADC1_Init(void)


//Enable clock to ADC module


//Enable clock to GPIO a


// configure mode to analog


//configure ADC parameter

//1. Sequence start

//2. Sequence length


// Sequence length to 0


//Enable adc



void Start_Conv(void)




uint32_t ADC_read(void)



return (ADC1->DR);


uint32_t data;

int main(void)







for(int i=0;i<4;i++)





main.c file


I've tried your code (in attachment), and it works as expected.


- you should have started a new thread with the new question

- when inserting code, in the forum's editor, click on "..." to expand the top menu, and in there click to "</>" to insert code, otherwise indentations etc. are not preserved and code is hard to read

- I have added definitions which you probably have in adc.h. Most of them redefine already existing symbols from the CMSIS-mandated device header; there's no reason to do that, just use the symbols from the device header directly

- I have added volatile to data (see below)

- I have added an infinite loop (while(1)) at the end of main(), as is mandatory for freestanding code (i.e. if you don't have an operating system as in PC) to not exit/return from main()

- swstart bit of status register is not enabling to logic 1- do you mean ADC_CR2.SWSTART? That bit is cleared by hardware as soon as the conversion starts, which in your case is immediately, so in debugger you won't see this bit read out as 1

- program is not giving output How exactly do you observe that? Do you read content of data variable in debugger? As the data variable is not used anywhere, an optimizing compiler may chose to optimize out writes to it entirely. Tag it as volatile.

- you haven't set sampling time, the default is the shortest one. It is OK for a test just find out that ADC works, but it may also result in the highest error of conversion, unless your input circuitry is properly designed for low-impedance