cancel
Showing results for 
Search instead for 
Did you mean: 

Dual Interleaved mode with external trigger for each sample. STM32F103xx

mailmail9114
Associate II
Posted on August 26, 2015 at 09:55

hi, im using STM32F103 ADC1 with external trigger (ADC_ExternalTrigConv_T2_CC2) and DMA1 at this moment.

its important to trigger each adc conversion with the external trigger.

this  works great - but its to slow for my application.

    RCC_ADCCLKConfig(RCC_PCLK2_Div4);

    /* Enable ADC1 and GPIOC clock */

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);

    /* ADC1 configuration ------------------------------------------------------*/

    ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

    ADC_InitStructure.ADC_ScanConvMode =DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConv =  ADC_ExternalTrigConv_T2_CC2;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfChannel = count;

    ADC_Init(ADC1, &ADC_InitStructure);

    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1,ADC_SampleTime_1Cycles5);

    

    /* Enable ADC1 DMA */

    ADC_DMACmd(ADC1, ENABLE);

    /* Enable ADC1 external trigger */

    ADC_ExternalTrigConvCmd(ADC1, ENABLE);

    /* Enable ADC1 */

    ADC_Cmd(ADC1, ENABLE);

    /* Start ADC1 Software Conversion */

    ADC_SoftwareStartConvCmd(ADC1, ENABLE);

    

    

   

im now planning to use ADC1 and ADC in interleaved mode to double the sampling freq.

Tigger  TrigConv_T2_CC2  -> Sample ADC1 CH1

Tigger  TrigConv_T2_CC2  -> Sample ADC2 CH1

Tigger  TrigConv_T2_CC2  -> Sample ADC1 CH1

Tigger  TrigConv_T2_CC2  -> Sample ADC2 CH1

.

.

.

But with thís configuration, the trigger dosnt work anymore. both adc works - but its untriggerd.

        /* ADC1 configuration ------------------------------------------------------*/

    ADC_InitStructure.ADC_Mode = ADC_Mode_FastInterl;

    ADC_InitStructure.ADC_ScanConvMode =DISABLE; //single channel mode

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConv =  ADC_ExternalTrigConv_T2_CC2;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfChannel = 1;

    ADC_Init(ADC1, &ADC_InitStructure);

    /* ADC1 regular channels configuration */

    ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1,ADC_SampleTime_1Cycles5);

    /* ADC2 configuration ------------------------------------------------------*/

    ADC_InitStructure.ADC_Mode = ADC_Mode_FastInterl;

    ADC_InitStructure.ADC_ScanConvMode = DISABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

    ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

    ADC_InitStructure.ADC_NbrOfChannel = 1;

    ADC_Init(ADC2, &ADC_InitStructure);

    /* ADC2 regular channels configuration */

    ADC_RegularChannelConfig(ADC2, ADC_Channel_1, 1, ADC_SampleTime_1Cycles5);

    /* Enable ADC2 external trigger conversion */

    ADC_ExternalTrigConvCmd(ADC2, ENABLE);

 

  Is the ADC_Mode_FastInterl the correct mode ? Thanks.

  
1 REPLY 1
keaven
Associate II
Posted on August 26, 2015 at 15:52

Hi Peter,

I didn't worked with STM32F1x but with a STM32F4x in order to use the external trigger for both ADCs you must use the injected mode. It might not exist on a STM32F1x tho. If you want to use the regular conversion mode in dual ADCs you must set the number of cycle for a 2 sample delay. Then your external trigger will start the conversion for ADC1 and after a number of ADC controller cycle it will do the conversion with ADC2. Here is my init code for dual mode on a STM32F4 . I am running with a 1Khz external trigger and ADC at 5 Mhz so I can convert 2140 pixel values in 704 us. Hope this help

static ADC_HandleTypeDef hADC1;
static ADC_HandleTypeDef hADC2;
void InitADCs (void)
{
ADC_ChannelConfTypeDef ChannelConfig;
ADC_MultiModeTypeDef MultiMode;
//ADC1
hADC1.Instance = ADC1;
hADC1.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
hADC1.Init.Resolution = ADC_RESOLUTION12b;
hADC1.Init.ScanConvMode = DISABLE;
hADC1.Init.ContinuousConvMode = DISABLE;
hADC1.Init.DiscontinuousConvMode = DISABLE;
hADC1.Init.NbrOfDiscConversion = 0;
hADC1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_RISING;
hADC1.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T4_CC4;
hADC1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hADC1.Init.NbrOfConversion = 1;
hADC1.Init.DMAContinuousRequests = ENABLE;
hADC1.Init.EOCSelection = DISABLE;
HAL_ADC_Init(&hADC1);
//Channel Configuration
ChannelConfig.Channel = ADC_CHANNEL_13;
ChannelConfig.Rank = 1;
ChannelConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
ChannelConfig.Offset = 0;
HAL_ADC_ConfigChannel(&hADC1, &ChannelConfig);
//ADC2
hADC2.Instance = ADC2;
hADC2.Init.ClockPrescaler = ADC_CLOCKPRESCALER_PCLK_DIV2;
hADC2.Init.Resolution = ADC_RESOLUTION12b;
hADC2.Init.ScanConvMode = DISABLE;
hADC2.Init.ContinuousConvMode = DISABLE;
hADC2.Init.DiscontinuousConvMode = DISABLE;
hADC2.Init.NbrOfDiscConversion = 0;
hADC2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
hADC2.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T4_CC4;
hADC2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
hADC2.Init.NbrOfConversion = 1;
hADC2.Init.DMAContinuousRequests = ENABLE;
hADC2.Init.EOCSelection = DISABLE;
HAL_ADC_Init(&hADC2);
//Use same channel configuration of ADC1
HAL_ADC_ConfigChannel(&hADC2, &ChannelConfig);
//Configure Dual Mode Interleaved
MultiMode.Mode = ADC_DUALMODE_INTERL;
MultiMode.DMAAccessMode = ADC_DMAACCESSMODE_2;
MultiMode.TwoSamplingDelay = ADC_TWOSAMPLINGDELAY_8CYCLES; 
HAL_ADCEx_MultiModeConfigChannel(&hADC1, &MultiMode);
//Enable ADC2
HAL_ADC_Start(&hADC2);
//Enable ADC1 dual interleaved DMA with double buffering
//Custom Function to use double buffers mode in dual ADC mode.
HAL_ADCEx_MultiModeStart_DMA_MultiBuffer(&hADC1, (uint32_t)&OddFramePixels[0], (uint32_t)&EvenFramePixels[0], CCD_NUMBER_OF_PIXELS);
return;
}