Skip to main content
Associate II
September 15, 2026
Solved

STM32G030C8T6 temperature sensor and oversampling issue

  • September 15, 2026
  • 7 replies
  • 72 views

I’m trying to use ADC oversampling and noticed that temperature value is distorted in that case.

I have configured ADC with 7 external inputs, temperature sensor input and Vref input. Vcc/Vcca is 3.27V, sampling time is 7.5 cycles.

When oversampling is disabled - I’ve got averaged raw value 2115 for analog input (voltage 1.64V), 1005 for temperature sensor and 1582 for Vref. When oversampling is enabled (no matter 2x or 16x, with shifting to same count of bits as added by oversampling) - I’ve got 2115 for analog input, 1107 (!!) for temperature sensor and 1584 for Vref. So, only temperature sensor input value differs. And, as result, I’ve got 63*C instead of 33*C when oversampling is enabled.

What’s wrong with oversampling? Can it be fixed by some kind of settings? Or I must forget about it and use software oversampling instead?

I’m using latest CubeIDE 2.2.0 and CubeMX 6.18.1 with latest libs 1.6.3.

Best answer by Gyessine

Hello ​@NiTr0man 
As ozone said
the important is sample time rate
for example, the STM32G030 max frequency is 64MHZ if it’s all going to ADC clock
if you are using that and 160 cycles your sampling time is just 2.5us which is less than 5us
can you provide at least caption from your clock ocnfiguration?
BR
Gyessine

7 replies

Andrew Neil
Super User
September 15, 2026

Please post a minimum but complete example which illustrates the issue.

 

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.
TDK
September 15, 2026

There is a minimum sampling time requirement for the temperature sensor. Increase yours to meet this. How much you need to increase depends on what your ADC clock is.

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
NiTr0manAuthor
Associate II
September 17, 2026

There is a minimum sampling time requirement for the temperature sensor. Increase yours to meet this. How much you need to increase depends on what your ADC clock is.

 

I’ve increased sampling time up to 160 cycles at tests. Nothing is changed.

 

Ozone
Principal
September 17, 2026

> I’ve increased sampling time up to 160 cycles at tests.

Number of cycles is not the important criterium.
What is the resulting sample time ?

 

GyessineBest answer
ST Technical Moderator
September 18, 2026

Hello ​@NiTr0man 
As ozone said
the important is sample time rate
for example, the STM32G030 max frequency is 64MHZ if it’s all going to ADC clock
if you are using that and 160 cycles your sampling time is just 2.5us which is less than 5us
can you provide at least caption from your clock ocnfiguration?
BR
Gyessine

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question.
NiTr0manAuthor
Associate II
September 18, 2026

Yes, but ADC clock rate is up to 35 MHz.

As I replied earlier, I’ve re-checked again with 32 MHz ADC clock and 160 samples and now it works OK, I don’t know why it wasn’t worked earlier I tested it.