Page 2 of 2

Re: STM32 ADC and exttrig event problem

Posted: Thu Sep 27, 2012 8:13 am
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?

Re: STM32 ADC and exttrig event problem

Posted: Thu Sep 27, 2012 8:37 am
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

Re: STM32 ADC and exttrig event problem

Posted: Sun Sep 30, 2012 4:41 pm
by Giovanni
I committed the proposed change, also the drivers for F2, F4 and L1 have been modified in a similar way.

Giovanni

Re: STM32 ADC and exttrig event problem

Posted: Mon Oct 01, 2012 3:23 pm
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?

Re: STM32 ADC and exttrig event problem

Posted: Mon Oct 01, 2012 4:01 pm
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