2026-02-10 4:47 AM - edited 2026-02-10 5:10 AM
Hello all,
Currently I have been working on a project which involves reading values using ADC. This is the following connection:
AD8495 is used as an ambient temperature sensor. The connections given in the image are taken from the datasheet for adr8495. I have connected the output to channel A0 of my ADC on board with STM32F407ZGT6. The configuration of ADC is as follows.
static void MX_ADC1_Init(void)
{
ADC_ChannelConfTypeDef sConfig = {0};
hadc1.Instance = ADC1;
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
hadc1.Init.ScanConvMode = ENABLE;
hadc1.Init.ContinuousConvMode = DISABLE;
hadc1.Init.DiscontinuousConvMode = ENABLE;
hadc1.Init.NbrOfDiscConversion = 3;
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hadc1.Init.NbrOfConversion = 3;
hadc1.Init.DMAContinuousRequests = DISABLE;
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
if (HAL_ADC_Init(&hadc1) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_VREFINT;
sConfig.Rank = 1;
sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_0;
sConfig.Rank = 2;
sConfig.SamplingTime = ADC_SAMPLETIME_84CYCLES;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_1;
sConfig.Rank = 3;
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
{
Error_Handler();
}
}The issue I am facing is as follows: Whenever I power the board using STLINK using 5v provision on it, and the adr8495 is powered as well, the ADC works properly showing the reading with respect to the ambient Temperature of the room.
But whenever I power the circuit using a Linear Power supply 5V, the ADC measurements change and are drastically reduced. I have checked all the common issues like grounding , any short connections,
but I have not been able to find an issue. One thing that might help is whenever I power the board using STLINK-V2 the 3.3Pin on the board is stable around 3.25V , and whenever Linear power supply is used the Pin is stable around 3.35V
I also came up with the idea of using VREFINT as for measuring the Vref that the board is actually getting powered by, and use that value for the engineering conversions i.e Converting raw ADC values to millivolts.
Can anyone provide any suggestion? Do ask if you have any query related to connections or the firmware.
Edited to apply proper source code formatting - please see How to insert source code for future reference.
2026-02-10 11:13 PM
>I don*t understand how you mean that.
The ST-Link provides only +3.3V via the (SWD) debug connection. Regardless how the ST-Link itself is powered (+5V via USB).
What I meant to say was that STLINK V2 has A 5V output provision, this output is connected to the 5V header pin of the M4 demo board.
Then the 5V is converted via a 3.3regulator present on the board which gives the stable ~3.3V necessary for the stm32f407.
2026-02-10 11:21 PM
>If VREF+ is changing, it is expected that ADC values will also change.
Yes I understand that, but my thought process is:
-I am using the intrenal VREFINT pin for knowing the Vref obtained.
-So even if The vref i changing , that should be handled in the firmware by VREFINT.
-And if this is not helping , it would mean the internal 1.21 is also changing because of the changing Vref which would then reflect in calculating actual Vref using VREFINT.
-Does the VREFINT pin read proper Vref irrespective(the input voltage is bound within 3-3.4V) of the Vref obtained?
-Why is this method not working?
2026-02-11 2:03 AM - edited 2026-02-11 3:12 AM
I recommend to consult the reference manual (RM0090), sections 5.1.1 and 13.2 in this regard.
Some larger packages have a separate Vref+ input pin, others not. In the latter case, VDDA is used.
The F407 discovery board does have a variant with separate pin, but connects VDDA to it.
Here the relevant excerpt from the ST F407 discovery board :
As said, check with the schematics of your board.
The Vref voltage is connected to an internal ADC channel (by a voltage divider) for measurement, as a side note.
To state it more clearly, Vref+ represents the maximal ADC conversion result, i.e. 0x0FFF for 12 bit.
If this Vref fluctuates, all other ADC conversion results fluctuate proportionally.
Thus my recommendation to measure a stable, known external voltage source, I would suggest 1.5 ... 2.5V.
If this value fluctuates by more than about 2..4 counts (in each direction), you most probably have a stability problem.
2026-02-11 4:50 AM - edited 2026-02-11 6:18 AM
>Thus my recommendation to measure a stable, known external voltage source, I would suggest 1.5 ... 2.5V.
If this value fluctuates by more than about 2..4 counts (in each direction), you most probably have a stability problem.
I did what you recommended;
First I powered the circuit using STLINK V2 ; Second I used a linear power supply.
Additional circuitry involved was a ref03 Stable 2.5V regulator. I checked the adc reading for the cases for the two cases. This is the observation:
Again Can you kindly tell me why any reason that my roundabout method of measuring actual Vref and using that as for the conversions is not working?
Slight correction the ADC reading for linear power supply was 2.433mV and not 2.483 mV
2026-02-11 5:27 AM
As I understand the datasheet and the reference manual, the normal ADC channels of the F407 always use Vref+ as reference voltage.
As mentioned, check the schematics of your board, and measure Vref+ directly at the MCU pin, in both supply scenarios (ST-Link and external 5V).
A good multimeter should be sufficient.
Re-reading a former post :
> What I meant to say was that STLINK V2 has A 5V output provision, this output is connected to the 5V header pin of the M4 demo board.
I don't think so. At least if you mean the stand-alone ST-Link device:
The user manual mentions several times that this pin is only used the "ensure signal level compatibility", but nowhere does it say it might be used to supply the target.
Newer onboard and stand-alone ST-Link variants explicitely say so if possible, and state additional constraints.
2026-02-11 6:16 AM
STLINK purchase link: In this there is a provision of 5V , which I used in the circuitry and measured on a DSO. It gave a stable 4.8-5V.
You might be correct , I could have used it wrong until now, but it has worked.
Further I did some changes in the firmware on how to use the VREFINT in increasing the accuracy according to this video , you can see on minute 9:38.
This resulted in change of reading. The vref obtained using STLINK V2 was around 3.199,
And the Vref measured using a linear power supply was 3.26V-3.27V
This still did not solve the issue , the measured adr8495 output was still around 80-90mV
2026-02-11 10:29 PM
> In this there is a provision of 5V , which I used in the circuitry and measured on a DSO. It gave a stable 4.8-5V.
> You might be correct , I could have used it wrong until now, but it has worked.
Which does not mean this pins is meant to supply a target, and deliver enough current.
You would have to check with the schematics, which are probably not publicly available.
But this remark in the user manual is more than a hint.
And the F407 is not really a low-power MCU.
> This still did not solve the issue , the measured adr8495 output was still around 80-90mV
You need to separate matters here.
Check the ADC channel with a stable, low impedance DC source first - e.g. a battery as mentioned.
Best is to check each channel alone, and then both in combination.
If this yields about identical results, proceed with your thermocouple amplifier.
Besides external factors like reference voltage and input impedance, there are internal ones' like the sampling time, inter-sample delay and sampling frequency. As a first-order approximation a SAR-ADC input stage can be viewed as a RC element, whose bandwitdh must fit that of the input signal.
In short, if the thermocouple results differ significantly from those with a DC source try longer sampling times.
2026-02-16 3:33 AM
>In short, if the thermocouple results differ significantly from those with a DC source try longer sampling times.
I have connected the thermocouple to an amplifier circuit with high current output. Thus the sampling time should not be an issue for that.
I thought of this before and even tried it but there was no difference since I realized it later that the current output was high. The output of this amplifier is connected to the ADC via RC filter.
2026-02-16 6:28 AM - edited 2026-02-16 6:28 AM
You should simplify the problem as @Ozone suggests, including powering the board from a non-programmer source. What you are describing should work if the design is correct, but it isn't. So there is an issue somewhere.
The more your show the more the more likely the issue will be spotted.
2026-02-16 10:49 PM
Interfacing adc with external circuitry is not easy task. Unfortunately, app. note doesn't provide an example schematic, so customer have to solve a few issues:
injected current should never exceed stated in data sheet limits, 5 mA or so. Modern common OPA can easily supply 20-100 mA when powered from anything else except same 3.3V power source as an stm32 adc.
This brings up input protection, that again is not easy to solve for high precision analog signals.
I'd recommend buffer adc inputs by low voltage R2R outputs op-amp, powered by analog domain 3.3V, and buffer may have resistors at its own inputs. CMOS/ JFET high input impedance op-amp keep good precision even with high value of resistors, that may be necessary for circuits exposed to long lines or harsh external environment