Start ADC Conversion from within ADC conversion callback

Discussions and support about ChibiOS/HAL, the MCU Hardware Abstraction Layer.
Post Reply
Alex
Posts: 39
Joined: Sat Feb 22, 2014 2:40 pm
Been thanked: 3 times

Start ADC Conversion from within ADC conversion callback

Post by Alex »

Can i call start adc conversion from within callback of previous adc conversion?
My approaches was unsuccessfull..

for example: (reconstruction, may be small errors)

Code: Select all

void adc1_callback(ADCDriver *adcp, adcsample_t *buffer, size_t n)
{
...
  adcStartConversionI(adcp, &adc_grp_cfg2, &sample_2, ADC_GRP2_NUM_CHANNELS);
...
}

// conversion group for previous conversion
static const ADCConversionGroup adc_grp_cfg1 = {
  FALSE,
  1,                                                                                                
  adc1_callback,                                                                               
  NULL,                                                                            
  .u.adc = {
      0, ADC_CR2_SWSTART, 0, 0,                                                                         
    { 0,     ADC_SMPR2_SMP_AN8(ADC_SAMPLE_1P5)},                                                
    { 0, 0,  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN8 ) }
   }
};

// conversion group for next conversion
static const ADCConversionGroup adc_cfg_grp2 = {                                         
  FALSE,                                                                                                                        
  ADC_WDG_NUM_CHANNELS,                                                                                                   
  NULL,                                                                                                                         
  adcerr_wdg,                                                                                                                
  .u.adc = {                                                                           
    ADC_CR1_AWDEN | ADC_CR1_AWDIE | ADC_CR1_AWDSGL | ADC_CR1_AWDCH_0 | ADC_CR1_AWDCH_3,   
      ADC_CR2_SWSTART | ADC_CR2_CONT,                                                                               
      NEGATIVE_VOLTAGE_LIMIT,                                                                                             
      POSITIVE_VOLTAGE_LIMIT,                                                                                            
    { 0,     ADC_SMPR2_SMP_AN9(ADC_SAMPLE_1P5)},                                                            
    { 0, 0,  ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9)}}};                                                            
                     


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

Re: Start ADC Conversion from within ADC conversion callbac

Post by Giovanni »

It should work. You are not defining "unsuccessful".

Giovanni
Alex
Posts: 39
Joined: Sat Feb 22, 2014 2:40 pm
Been thanked: 3 times

Re: Start ADC Conversion from within ADC conversion callbac

Post by Alex »

Thank you!

To define "unsuccessfull" need too many words...
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Start ADC Conversion from within ADC conversion callbac

Post by Giovanni »

Hi,

You should give a minimum of info when asking for support, at very least what you expect and what you are getting instead. Specifying also the device used, the ChibiOS version would be useful too.

Giovanni
Alex
Posts: 39
Joined: Sat Feb 22, 2014 2:40 pm
Been thanked: 3 times

Re: Start ADC Conversion from within ADC conversion callbac

Post by Alex »

Sorry, but i don't wait no more anything..

Device - STM32F373C8T6, OS - Nil from ChibiOs 3.0

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

Re: Start ADC Conversion from within ADC conversion callbac

Post by Giovanni »

Hi,

It was not my intention to offend you, I just needed more info in order to give support.

Giovanni
Alex
Posts: 39
Joined: Sat Feb 22, 2014 2:40 pm
Been thanked: 3 times

Re: Start ADC Conversion from within ADC conversion callbac

Post by Alex »

Same problem, other side look:

this conversion group:

Code: Select all

static const ADCConversionGroup adc_cfg_wdg2 = {                                        
  FALSE,                                                                                                                        
  2,                                                                                                   
  NULL,                                                                                                                         
  adcerr_wdg,                                                                                                                
  .u.adc = {                                                                           
    ADC_CR1_AWDEN | ADC_CR1_AWDIE | ADC_CR1_AWDSGL | ADC_CR1_AWDCH_0 | ADC_CR1_AWDCH_3,   
      ADC_CR2_SWSTART | ADC_CR2_CONT,                                                                               
      NEGATIVE_VOLTAGE_LIMIT,                                                                                             
      POSITIVE_VOLTAGE_LIMIT,                                                                                            
    { 0,     ADC_SMPR2_SMP_AN8(ADC_SAMPLE_1P5) | ADC_SMPR2_SMP_AN9(ADC_SAMPLE_1P5)},      
    { 0, 0,  ADC_SQR3_SQ2_N(ADC_CHANNEL_IN8)   | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN9)}}};      


and this call conversion

Code: Select all

adcStartConversionI(&ADCD1, &adc_cfg_wdg2, buf, ADC_WDG_BUFDEPTH);


if ADC_WDG_BUFDEPTH > 0, store results of conversion, but not call adcerr_wdg
if ADC_WDG_BUFDEPTH == 0, call adcerr_wdg, but not store results of conversion, in same conditions

I want both actions: store results of conversion, and call adcerr_wdg - this is possible?

clear up a point: I am interested in: result of conversion at channel 8 once of certain time period,
and check ranges signal at channel 9 during whole this period

PS: Device STM32F373C8T6, board- self made, OS - NIL from ChibiOs v3.0
PPS: Sorry for my Engish ...

thank you very much for you tolerance
Post Reply