Page 1 of 1

ADCv1 and adcerrorcallback (Analog watchdog problem)  Topic is solved

Posted: Sun Nov 03, 2019 10:25 am
by RadaR
Brief description

    - chibios_trunk (latest build from github)
    - stm32L031F6
    - Enabled Oversampling ADC (16X)
    - Enabled Analog WatchDog
    - Used ADC 4pcs Channel (0,1,2,4)

ADC struct defines:

Code: Select all

#define ADC_GRP2_NUM_CHANNELS   4
#define ADC_GRP2_BUF_DEPTH      2

/* Variable containing ADC conversions data */
static adcsample_t  aADCxConvertedData[ADC_GRP2_NUM_CHANNELS*ADC_GRP2_BUF_DEPTH];


ADC conversion group:

Code: Select all

static const ADCConversionGroup adcgrpcfg2 = {
  TRUE,
  ADC_GRP2_NUM_CHANNELS,
  adccallback,
  adcerrorcallback,
  ADC_CFGR1_CONT | ADC_CFGR1_RES_12BIT | ADC_CFGR1_AWDEN ,             /* CFGR1 [glow=red]Enabled Analog WatchDog for all channel[/glow] */
  ADC_CFGR2_OVSE | ADC_CFGR2_OVSR_16X,               /* CFGR2 [glow=red]Enabled Oversampling ADC[/glow] (16X) */
  ADC_TR(0, 2000),                                     /* TR  [glow=red]Analog watchdog high treshold set to 2000 [/glow]*/
  ADC_SMPR_SMP_41P5,                                /* SMPR */
  ADC_CHSELR_CHSEL0 | ADC_CHSELR_CHSEL1 |
  ADC_CHSELR_CHSEL2 | ADC_CHSELR_CHSEL4           /* CHSELR */
};



Error Callback function define (set global flag and on LED)

Code: Select all

volatile uint8_t Blocked_by_WatchDog;


Code: Select all

static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) {
  //if(adcp == &ADCD1 && err == ADC_ERR_AWD) {
    Blocked_by_WatchDog = 1;
    palWriteLine(LINE_LED_STAT, PAL_HIGH);
  //}
}


Callback from ADC (half and complete)

Code: Select all

volatile adcsample_t Global_CURR;
volatile adcsample_t Global_AB;
volatile adcsample_t Global_16V;
volatile adcsample_t Global_TEMP;


Code: Select all

static void adccallback(ADCDriver *adcp) {

  if (adcIsBufferComplete(adcp)) {  // [glow=red]analize all buffer[/glow]
    Global_16V=(aADCxConvertedData[3]+aADCxConvertedData[7])/(2*SET_ADC_OVERSAMPLING);
    Global_TEMP=(aADCxConvertedData[2]+aADCxConvertedData[6])/(2*SET_ADC_OVERSAMPLING);
    Global_AB=(aADCxConvertedData[1]+aADCxConvertedData[5])/(2*SET_ADC_OVERSAMPLING);
    Global_CURR=(aADCxConvertedData[0]+aADCxConvertedData[4])/(2*SET_ADC_OVERSAMPLING);
  }
  else { // [glow=red]analize half of buffer[/glow]
        Global_16V=aADCxConvertedData[3]/SET_ADC_OVERSAMPLING;
        Global_TEMP=aADCxConvertedData[2]/SET_ADC_OVERSAMPLING;
        Global_AB=aADCxConvertedData[1]/SET_ADC_OVERSAMPLING;
        Global_CURR=aADCxConvertedData[0]/SET_ADC_OVERSAMPLING;
  }
}




Main code

Code: Select all

 //Activates the ADC1 driver and the temperature sensor.
  adcStart(&ADCD1, NULL);

  // start ADC
  adcStartConversion(&ADCD1, &adcgrpcfg2, aADCxConvertedData, ADC_GRP2_BUF_DEPTH);



Now the main problem

1) Starting ADC with value lower than treshold (2000)

Снимок экрана 2019-11-03 в 11.22.41.png


All is Ok.

2) Now give at one channel ADC value higher than treshold (more than 2000)

Снимок экрана 2019-11-03 в 11.17.04.png

Снимок экрана 2019-11-03 в 11.18.40.png


ADC driver stop to call adccallback to update value. All value now is zero.

But main problem - ADC driver never call adcerrorcallback

if ADC set low then treshold then all rollback to normal state.

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 11:45 am
by Giovanni
Hi,

It is a known error, the ADC ISR is not defined for the L0, moving in bug reports.

You may re-enable the ISR and it should work.

Giovanni

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 12:08 pm
by RadaR
It is a known error, the ADC ISR is not defined for the L0, moving in bug reports.

You may re-enable the ISR and it should work.


you mean

// re-set IER

Code: Select all

adcp->adc->ISR    = adcp->adc->ISR;
adcp->adc->IER    = ADC_IER_OVRIE | ADC_IER_AWDIE;


and re-enable

Code: Select all

adcp->adc->CR = ADC_CR_ADEN;
    while (!(adcp->adc->ISR & ADC_ISR_ADRDY))
      ;


what about ?

Code: Select all

ADC driver never call adcerrorcallback

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 12:13 pm
by Giovanni
STM32_ADC1_IRQ_SHARED_WITH_EXTI

Try putting it to FALSE in registry, it disables the ISR.

Giovanni

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 12:39 pm
by RadaR
Giovanni wrote:STM32_ADC1_IRQ_SHARED_WITH_EXTI

Try putting it to FALSE in registry, it disables the ISR.

Giovanni



Thanks, i'll try.

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 12:46 pm
by RadaR
Giovanni wrote:STM32_ADC1_IRQ_SHARED_WITH_EXTI

Try putting it to FALSE in registry, it disables the ISR.

Giovanni


Helped!!!

Now i can catch adcerrorcallback

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 12:47 pm
by RadaR
What the best solutions for this situation? use this fix or try to define a ADC ISR ?

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 1:00 pm
by Giovanni
It is not fixed yet because I am undecided because that IRQ sharing.

Probably I will make the same fix that I posted here.

Giovanni

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 03, 2019 1:29 pm
by RadaR
Can you post here when you make a final decision what solution apply

Re: ADCv1 and adcerrorcallback (Analog watchdog problem)

Posted: Sun Nov 10, 2019 10:02 am
by Giovanni
Hi,

Fixed as bug #1058.

I just removed that check, EXTI interrupts can be implemented via the hook macro in the ADC ISR if required.

Giovanni