STM32 ADC and exttrig event problem

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

alexblack
Posts: 277
Joined: Mon Sep 24, 2012 3:52 pm
Been thanked: 33 times

Re: STM32 ADC and exttrig event problem

Post by alexblack »

I'll study this document later and try to understand the problem.

And what about ADC low level driver? I propose the following changes to \os\hal\platforms\STM32F1xx\adc_lld.c:

Code: Select all

/**
 * @brief   Starts an ADC conversion.
 *
 * @param[in] adcp      pointer to the @p ADCDriver object
 *
 * @notapi
 */
void adc_lld_start_conversion(ADCDriver *adcp) {
  uint32_t mode, n, cr2;
  const ADCConversionGroup *grpp = adcp->grpp;
 
  /* DMA setup.*/
  mode = adcp->dmamode;
  if (grpp->circular)
    mode |= STM32_DMA_CR_CIRC;
  if (adcp->depth > 1) {
    /* If the buffer depth is greater than one then the half transfer interrupt
       interrupt is enabled in order to allows streaming processing.*/
    mode |= STM32_DMA_CR_HTIE;
    n = (uint32_t)grpp->num_channels * (uint32_t)adcp->depth;
  }
  else
    n = (uint32_t)grpp->num_channels;
  dmaStreamSetMemory0(adcp->dmastp, adcp->samples);
  dmaStreamSetTransactionSize(adcp->dmastp, n);
  dmaStreamSetMode(adcp->dmastp, mode);
  dmaStreamEnable(adcp->dmastp);

  /* ADC setup.*/
  adcp->adc->CR1   = grpp->cr1 | ADC_CR1_SCAN;
  cr2 = grpp->cr2 | ADC_CR2_DMA | ADC_CR2_ADON;
  if ((cr2 & (ADC_CR2_EXTTRIG | ADC_CR2_JEXTTRIG)) == 0) cr2 |= ADC_CR2_CONT;
  adcp->adc->CR2   = cr2;
  adcp->adc->SMPR1 = grpp->smpr1;
  adcp->adc->SMPR2 = grpp->smpr2;
  adcp->adc->SQR1  = grpp->sqr1;
  adcp->adc->SQR2  = grpp->sqr2;
  adcp->adc->SQR3  = grpp->sqr3;

  /* ADC start by writing ADC_CR2_ADON a second time.*/
  adcp->adc->CR2   = cr2;
}


In general, what the procedure for amendments to the system?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32 ADC and exttrig event problem

Post by Giovanni »

The change looks OK, in general posting changes on the forum is OK but I could forget about it :)

The "safe" way is to open a ticket on the SF bugs tracker, tickets are handled accurately and recorded in the changes list.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32 ADC and exttrig event problem

Post by Giovanni »

I committed the proposed change, also the drivers for F2, F4 and L1 have been modified in a similar way.

Giovanni
andyturk
Posts: 23
Joined: Tue May 01, 2012 7:22 pm

Re: STM32 ADC and exttrig event problem

Post by andyturk »

Giovanni wrote:If you need to make conversions at intervals you don't even need to touch a timer, there are several other ways:
1) A periodic thread.
2) A virtual timer callback.
3) A GPT driver callback.

Giovanni,

How much jitter is there in using a GPT callback? I'm using that method right now to drive periodic ADC samples. One of the requirements (unimplemented for now) is that the code calculate the frequency of the analog signal. My assumption has been that ultimately, I'd have to use a hardware timer to get enough precision. My sampling frequency isn't that high--maybe 10kHz.

What do you think?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: STM32 ADC and exttrig event problem

Post by Giovanni »

Hi,

The Jitter depends mainly on the priority you assign to that GPT, potentially it can be very low if you don't have ISRs at higher priority (there is no intrinsic jitter in the callback), the kernel doesn't affect this much, the kernel contribution to the jitter increases linearly with the number of threads but it very low anyway.

Giovanni
Post Reply