Drive ADC with TIMER

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

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Drive ADC with TIMER

Post 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?
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Re: Drive ADC with TIMER

Post 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?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Drive ADC with TIMER

Post 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
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Re: Drive ADC with TIMER

Post 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 */
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Drive ADC with TIMER

Post by Giovanni »

The F4 ADC is the same of F7, read the CR2 documentation and populate it accordingly to the example.

Giovanni
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Re: Drive ADC with TIMER

Post by AlSith »

Sorry Mr. Giovanni,

I'm really dismayed..!! :oops: :oops: :oops: :oops:
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Drive ADC with TIMER

Post by Giovanni »

There is no need to apologize, why that?

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

Giovanni
Post Reply