ADC Conversion sometimes 0

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Posts: 78
Joined: Tue Feb 25, 2020 4:06 pm
Has thanked: 3 times
Been thanked: 2 times

ADC Conversion sometimes 0

Postby JSStabl » Wed Sep 06, 2023 2:01 pm

I might have run into an issue similar to this:

There are quite some errata sheets that point to something suspiciously similar to what I have been experiencing..
I'm using a STM32L496 where I have a bunch of ADCs connected. We have built hundreds of these devices and sometimes, some of them just report 0 on an entire ADC Conversion Group (adc1) until restarted.

Heres the adc setting

Code: Select all

const ADCConversionGroup adc1_grpcfg = {
.circular       = true,
.num_channels   = ADC1_GRP_NUM_CHANNELS,    /* number of Channels */
.end_cb         = adc1_Callback,            /* End Callback link */
.error_cb       = adc1_ErrCallback,         /* Error Calback link */
.cfgr           = ADC_CFGR_EXTEN_RISING |   /* Trigger on rising edge*/
                  ADC_CFGR_EXTSEL_SRC(11),  /* TIM2 TRGO */
.cfgr2          = 0U,
.tr1            = ADC_TR(0, 4095),          /* ADC Watchdog init*/
.smpr         = {


  .sqr          = {                         /*Sampelsequence */

And the adc settings look like this

Code: Select all

const ADCConfig adc1cfg = {
  .difsel       = 0U

I start the adc conversion like this:

Code: Select all

adcStartConversion(&ADCD1, &adc1_grpcfg,
                      g_ADCsamples[ADC_CONTROLLER_1], ADC1_GRP_BUF_DEPTH);

Heres the callback

Code: Select all

static void adc1_Callback(ADCDriver *adcp) {

    if (adcIsBufferComplete(adcp)) {

      g_DatabaseADC[ADC_DATA_VMEAS1]         = g_ADCsamples[ADC_CONTROLLER_1][0];
      g_DatabaseADC[ADC_DATA_TMEAS]          = g_ADCsamples[ADC_CONTROLLER_1][1];
      g_DatabaseADC[ADC_DATA_VREFINT]        = g_ADCsamples[ADC_CONTROLLER_1][2];
      g_DatabaseADC[ADC_DATA_TEMPSENSE]      = g_ADCsamples[ADC_CONTROLLER_1][3];
      g_DatabaseADC[ADC_DATA_VBAT]           = g_ADCsamples[ADC_CONTROLLER_1][4];
      g_DatabaseADC[ADC_DATA_BMSADAPTER]     = g_ADCsamples[ADC_CONTROLLER_1][5];

    else {


Now sometimes the entire g_ADCsamples[ADC_CONTROLLER_1] arrays just stays 0 for an entire lifecycle until restarted. I cannot find anything on the boards that would enable that behavior, has the fix thats mentioned in the link above been implemented in the chibiOS HAL as well?
I'm using HAL 7.1.5 and chibiOS 20.3.4

Can I update to HAL 8 without updating chibiOS?

User avatar
Site Admin
Posts: 14408
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1067 times
Been thanked: 913 times

Re: ADC Conversion sometimes 0

Postby Giovanni » Wed Sep 06, 2023 5:41 pm


There is no workaround in the driver itself, you may try to perform the conversion twice as suggested in that topic.

You may try to update the HAL, should work but this is unexplored territory.


Posts: 78
Joined: Tue Feb 25, 2020 4:06 pm
Has thanked: 3 times
Been thanked: 2 times

Re: ADC Conversion sometimes 0

Postby JSStabl » Wed Sep 06, 2023 5:45 pm

OK thanks, I just figured since they had a fix merged in the issue (increase the timings slightly) that might be something that the ChibiOS HAL might have included as well.

Ill try the workaround and report.

Return to “ChibiOS/HAL”

Who is online

Users browsing this forum: No registered users and 2 guests