Page 1 of 1

Drive ADC with TIMER

Posted: Tue Oct 27, 2015 5:52 pm
by AlSith
Hi everybody,

I want drive the ADC with an external timer, as in the dac example. So, to do it, I have to set in the #adcgroupconvversion only the CR2 value..??

I work so. i define the TIMer7, with a callback that recall the ADC Conversion:

Code: Select all

static void gpt_adc_trigger (GPTDriver *gptp) {
  (void)gptp;
  adcStartConversion(&ADCD1, &adcgrpcfg1, &adc_message[0], BUF_SIZE);
}

// ----------------------------------------------------------------------------

// --- General Purpose Timer 7 configuration.
static const GPTConfig gpt7cfg1 = {
  frequency     : 600000U,
  callback      : gpt_adc_trigger,
  cr2           : TIM_CR2_MMS_1,  // MMS = 010 = TRGO on Update Event
  dier          : 0U
};


..and set the ADC so:

Code: Select all

static const ADCConversionGroup adcgrpcfg1 = {
  circular          : TRUE,
  num_channels      : ADC_CHANNELS,
  end_cb            : adccallback,
  error_cb          : adcerrorcallback,
  cr1               : 0,
  cr2               : ADC_CR2_EXTEN,
  smpr1             : ADC_SMPR1_SMP_AN11(ADC_SAMPLE_15),
  smpr2             : 0,
  sqr1              : ADC_SQR1_NUM_CH(ADC_CHANNELS),
  sqr2              : 0,
  sqr3              : ADC_SQR3_SQ1_N(ADC_CHANNEL_IN11)
};
.

I set ADC pin, and start the ADC-self and TIMer7 in continuous mode.
Why, it doesn't work?

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 10:35 am
by AlSith
Ok, let's forget of previous post for a moment.

I have to set my ADC sampling frequency, I want know if my calculate is correct. I use these formulas:

f_ADC = SystemClock / (AHB_Div * APB1_Div * ADC_Div * (N_Cycles + 12));
=> f_sampling= 2 * f_ADC;

they are correct?

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 10:44 am
by Giovanni
About triggering: https://sourceforge.net/p/chibios/svn/H ... ADC/main.c

About clocks: The STM32 RM can answer that, I can add nothing without setting up a test and measuring it.

Giovanni

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 10:52 am
by AlSith
I have already seen this example, I decided to exclude it because:
first: it seems be written for F7;
second: practically, the label used for setting od ADC CR2, are not recognized by system

Code: Select all

ADC_CR2_EXTEN_RISING | ADC_CR2_EXTSEL_SRC(12),        /* CR2 */

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 10:58 am
by Giovanni
The F4 ADC is the same of F7, read the CR2 documentation and populate it accordingly to the example.

Giovanni

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 11:42 am
by AlSith
Sorry Mr. Giovanni,

I'm really dismayed..!! :oops: :oops: :oops: :oops:

Re: Drive ADC with TIMER

Posted: Thu Oct 29, 2015 1:26 pm
by Giovanni
There is no need to apologize, why that?

Questions about ChibiOS are OK. Other things require study of manuals.

Giovanni