cancel
Showing results for 
Search instead for 
Did you mean: 

ADC measurement issue

SohamC
Associate III

Hello all,

Currently I have been working on a project which involves reading values using ADC. This is the following connection:

 

SohamC_0-1770726822035.png

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.

25 REPLIES 25
Andrew Neil
Super User

Welcome to the forum.

Please see How to write your question to maximize your chances to find a solution for best results

In particular, What board are you using, and what ST-Link ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

The board is EU M4 demo, Board link.

The stlink used is STLINK V2.

That's not an ST board, you'll have to dig into the schematics to see the implications of the different ways of powering it.

Note that STM32F407 clones exist.

 

Are you using a genuine STLink ?

How to recognize a genuine ST-LINK/V2 versus a cloned one

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I power the board using the same pin, so the issue I am facing must be concerned with the Vref change, and how can I use firmware or any external hardware to solve it.

TDK
Super User

> But whenever I power the circuit using a Linear Power supply 5V, the ADC measurements change and are drastically reduced.

Be more precise. What values are you getting and what values are you expecting instead?

If VREF+ is changing, it is expected that ADC values will also change.

Showing the full schematic would help.

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

I would suggest to get the schematics, and check the VDDA related circuitry. Or measure the voltage on the board with a scope, and a timebase in the lower millisecond range.

> I power the board using the same pin,  ...

I doubt that.
The ST-Link provides a +3.3V voltage one can supply the target from.

Any external supply to the M4 Demo would go across the +5V input, and regulated down onboard to +3.3V for the MCU.
The VDDA supply branch for the F407 can be generated separately to provide a more stable supply for analog sections, including VREF. Cheaper boards supply VDDA directly from VDD without any extra measures, with visible VDDA fluctuations as a result.

SohamC
Associate III

Whenever I power the board using STLINK, via the 5V provision, the stm32f407 gets 3.25V at its 3.3PIN. As expected the adr8495 produces the voltage with respect to temperature i.e 5mV/C, but the ADC reads only 80-90 milivolts, when the actual adr8495 output is around 140mV. 
This led me to belive that the ADC Vref is getting change or anything related to it.

And even if the Vref was changed I used the VREFINT pin to know the Vref and use that for my calculations. s mentioned in the datasheet , this VREFINT is mapped to an ADC channel, and stm32f407 has 1.21V(typ) internal regulator based on which it calculates the Vref.
So even if the Vref changed it should have been handled in the firmware, so why does this still happen, such a drastic change from ~140 to ~80. 

> Whenever I power the board using STLINK, via the 5V provision, the stm32f407 gets 3.25V at its 3.3PIN.

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

> This led me to belive that the ADC Vref is getting change or anything related to it.

The ADC Vref is derived from VDDA, andis only as stable as this supply.

> As expected the adr8495 produces the voltage with respect to temperature i.e 5mV/C, but the ADC reads only 80-90 milivolts, when the actual adr8495 output is around 140mV. 

I would highly suggest to validate your ADC inputs another way, to not chasing ghosts here.
Use a stable and known external voltage e.g. a battery (perhaps with a voltage divider), and apply one or more known voltages to the ADC inputs. And check that shorting the ADC inputs to ground yields zero results (+/- one or two bits).

To properly convert the thermocouple amplifier output, check the output impedance of this device (ADR8495), the input impedance of the F407 ADC, and the necessary sampling times.