2023-02-23 04:31 AM
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.
Solved! Go to Solution.
2023-02-27 07:01 AM
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.
2023-02-23 04:43 AM
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...
2023-02-23 05:40 AM
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?
2023-02-23 08:45 AM
It seems to be 3.3V but I don't like not finding the precise code that sets it to 3.3V.
2023-02-23 09:20 AM
>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.
2023-02-25 06:12 PM
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).
2023-02-26 03:22 AM
there are two "Vref" : the + reference of the sar adc and the internal reference source:
this is what tried to explain.
+
int.ref.
and vref+ and vref- are on pins (or internal conn. to vdd/vss):
>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?
2023-02-26 11:02 PM
@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".
2023-02-27 07:01 AM
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.
2023-03-05 10:48 PM
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.