ADC Conversion sometimes 0

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
JSStabl
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:
https://github.com/stm32-rs/stm32l4xx-hal/issues/180

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         = {

    ADC_SMPR1_SMP_AN0(ADC_SMPR_SMP_247P5) |
    ADC_SMPR1_SMP_AN7(ADC_SMPR_SMP_247P5),
    ADC_SMPR2_SMP_AN15(ADC_SMPR_SMP_247P5) |
    ADC_SMPR2_SMP_AN16(ADC_SMPR_SMP_247P5) |
    ADC_SMPR2_SMP_AN17(ADC_SMPR_SMP_247P5) |
    ADC_SMPR2_SMP_AN18(ADC_SMPR_SMP_247P5)

  },
  .sqr          = {                         /*Sampelsequence */
    ADC_SQR1_NUM_CH(ADC1_GRP_NUM_CHANNELS)|
    ADC_SQR1_SQ1_N(ADC_CHANNEL_IN7)|
    ADC_SQR1_SQ2_N(ADC_CHANNEL_IN16)|
    ADC_SQR1_SQ3_N(ADC_CHANNEL_IN0)|
    ADC_SQR1_SQ4_N(ADC_CHANNEL_IN17),
    ADC_SQR2_SQ5_N(ADC_CHANNEL_IN18) |
    ADC_SQR2_SQ6_N(ADC_CHANNEL_IN15),
    0U,
    0U
  }
 };


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
Giovanni
Site Admin
Posts: 14458
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1076 times
Been thanked: 922 times
Contact:

Re: ADC Conversion sometimes 0

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

Hi,

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.

Giovanni

JSStabl
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 3 guests