cancel
Showing results for 
Search instead for 
Did you mean: 

Where is ADCREF voltage set?

Haddock
Associate III

I use ADC 12 bit in STM32L03 and cannot find where CubeIDE defines which reference voltage the ADC should have. ADC_Init() is auto-generated. Is it the default used and what voltage is it?

The processor is fed with 3.3V and has VDDA connected to that voltage.

1 ACCEPTED SOLUTION

Accepted Solutions

The Vref+ input (which is sometimes bonded to same pin as VDDA) has different purpose to the Vrefint internal voltage reference.

The range of ADC is always between zero and Vref+ (you always get 0xFFF if you measure Vref+). This is hard wired, it is how the ADC is built.

The internal voltage reference is an internal voltage source of a known value. If the Vref+ value can be unknown, you can measure the known value of Vrefint to calculate the conversion factor of the ADC (I.E. how many millivolts is one bit, or what voltage corresponds to 0xFFF).

If you want to use external voltage reference for this purpose instead, you just connect it to the ADC input and treat it as any other analog input you want to measure.

View solution in original post

10 REPLIES 10
LCE
Principal

In case of doubt, do your own, and put some defines in adc.h or main.h.

/* ADC basic settings */
#if( 0 == NUCLEO_F767 )
	#define ADC_REFERENCE_VOLT			(float)2.5			/* external ref */
#else
	#define ADC_REFERENCE_VOLT			(float)3.3			/* external ref = VCC */
#endif
 
#define ADC_VOLT_PER_LSB			(float)(ADC_REFERENCE_VOLT / 4096.0)
#define ADC_MILVOLT_PER_LSB			(float)(ADC_VOLT_PER_LSB * 1000.0)
 

And if you are using Cube stuff, put some /* USE BEGIN */ comments around it, or so...

Haddock
Associate III

Ok. But the problem is; Where to find (in the autogenerated code) the line that sets the ADC ref. source?

Perhaps it is NOT autogenerated. Perhaps I must set it myself?

Haddock
Associate III

It seems to be 3.3V but I don't like not finding the precise code that sets it to 3.3V.

AScha.3
Chief II

>but I don't like not finding the precise code that sets it to 3.3V.

depends on the exact chip and case you use, look in rm .

on low pin count devices vref = vdda , so you set it with your voltage on vdda or vdd, 3.3v is usual.

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

Hmm... to me Vref is the internal bandgap voltage around 1.23V, which ADC measured value at precise Vdd and Temperature is stored as calibrated data in Flash. The Datasheet will let you know where it is memory mapped. From Vref and Vtemp, the STM32 can deduct its Vdda voltage (Vdda=Vdd in most chips, it is the supply voltage).

AScha.3
Chief II

there are two "Vref" : the + reference of the sar adc and the internal reference source:

0693W00000aHfjtQAC.pngthis is what tried to explain.

+

int.ref.

0693W00000aHfkIQAS.pngand vref+ and vref- are on pins (or internal conn. to vdd/vss):

0693W00000aHfkXQAS.png0693W00000aHfkEQAS.png>cannot find where CubeIDE defines which reference voltage the ADC should have

because Cube cannot set, what voltage you supply to the pin (which is vref+)

ok now?

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

@AScha.3​ . Thanx. I suspected this. You wrote "because Cube cannot set, what voltage you supply to the pin (which is vref+)"

I thought some register needed to be set that tells the AD that "your ref is at pin VDDA, not the internal vref".

The Vref+ input (which is sometimes bonded to same pin as VDDA) has different purpose to the Vrefint internal voltage reference.

The range of ADC is always between zero and Vref+ (you always get 0xFFF if you measure Vref+). This is hard wired, it is how the ADC is built.

The internal voltage reference is an internal voltage source of a known value. If the Vref+ value can be unknown, you can measure the known value of Vrefint to calculate the conversion factor of the ADC (I.E. how many millivolts is one bit, or what voltage corresponds to 0xFFF).

If you want to use external voltage reference for this purpose instead, you just connect it to the ADC input and treat it as any other analog input you want to measure.

What you are saying is that I use the internal reference to find out the ADC "quality" and then I measure the external ref 3.3V (which is not always exactly 3.30V) and apply the calibration factor from before to the external reference and to future measurements on other channels?

It's a method I'm not used to (if I interpreted you correctly).

I have other problems with ADC blocking mode. Will present the code in another thread and see what response I get.