cancel
Showing results for 
Search instead for 
Did you mean: 

ADC1 External Trigger Not Working

Stephen28
Associate III
Posted on May 22, 2010 at 00:27

ADC1 External Trigger Not Working

5 REPLIES 5
Posted on May 17, 2011 at 13:52

Have you tried using the firmware library, and have you looked at the example code in Examples\ADC\TIMTrigger_AutoInjection\main.c

Uses TIM1,CC1 but might at least represent a working example.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Stephen28
Associate III
Posted on May 17, 2011 at 13:52

Thanks, I had not found the TIMTrigger_Autoinjection example.  I will examine it.

BTW, I am using the firmware library. 
t1
Associate II
Posted on May 17, 2011 at 13:52

ADC_CR2 = 0x00160903

This is enabling DMA.  You might try it with DMA disabled.

It you configure it for a SWSTART trigger, do you see it working when you write SWSTART?

Stephen28
Associate III
Posted on May 17, 2011 at 13:52

A little more data.  I had a slightly different setup working that was using TIM3_TRGO, that triggered the ADC to do a series of DMA transfers at a specified rate.  This setup uses TIM1 to trigger TIM3, when TIM3 times out it generates TRGO and triggers the ADC to start conversions.

The new setup uses TIM8 as the base timer.  The plan was to have TIM8 trigger TIM2, because TIM3 does not have a TIM8 input; when TIM2_CC2 fires then the ADC would start conversions.

I tried an experiment. I setup the following timer chain TIM8->TIM2->TIM3->ADC and now I get ADC samples.

I can trigger the ADC from TIM3_TRGO and not TIM2_CC2, what am I missing?  Does the TIM2_CC2 event only occur when there is an input signal to the CCR2, and the event does not occur as a result of a simple timeout?

Stephen28
Associate III
Posted on May 17, 2011 at 13:52

I was wrong.  TIM8->TIM2->TIM3->ADC is not working.  TIM3 is not starting as a result of the TIM2 TRGO.

Below is the code for setting up TIM2 to trigger the ADC.  Even though I am using DMA there is an ADC EOC interrupt that simply toggles a GPIO to verify that the ADC is running, and verify the timing.

When I run this code I do not get any ADC samples happening.  When I add the line ''ADC_Cmd(ADC1, ENABLE);'' to the TIM2_CC2 ISR then the ADC samples correctly.  This proves to me that the ADC sampling is working fine, and that the ADC does not receive the trigger from TIM2.  I even tried the line ''TIM_GenerateEvent( TIM2, TIM_EventSource_CC2);'' in the TIM2_CC2 ISR and the ADC does not fire.  More proof that the  TIM2_CC2 signal is not getting to the ADC.

Help???

  prvTIM_TimeBaseStructure.TIM_Period = WindowEnd;

  prvTIM_TimeBaseStructure.TIM_Prescaler = 127;

  prvTIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

  prvTIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  prvTIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

  TIM_TimeBaseInit( TIM2, &prvTIM_TimeBaseStructure );

  /* Selects the Counter overflow as only update source for TIM2 */

  //  TIM_UpdateRequestConfig( TIM2, TIM_UpdateSource_Global );

  /* configuration: Channel2

   * Controls the start of ADC

   */

  prvTIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;

  prvTIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;

  prvTIM_OCInitStructure.TIM_Pulse = WindowStart;

  prvTIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

  TIM_OC2Init( TIM2, &prvTIM_OCInitStructure );

  /* Selects the single One-pulse mode for TIM2

   * to stop after the number of repeats

   */

  TIM_SelectOnePulseMode( TIM2, TIM_OPMode_Single );

  /*

   * Ensure the Interrupt bit is clear.

   * Setup TIM2 to interrupt on Timeout

   */

  TIM_ClearITPendingBit( TIM2, TIM_IT_CC2 );

  TIM_ITConfig( TIM2, TIM_IT_CC2, ENABLE );

  TIM_ClearITPendingBit( TIM2, TIM_IT_Update );

  TIM_ITConfig( TIM2, TIM_IT_Update, ENABLE );

  /*

   * Setup TIM2 as slave to TIM8

   */

  TIM_SelectInputTrigger( TIM2, TIM_TS_ITR1 );

  TIM_SelectSlaveMode( TIM2, TIM_SlaveMode_Trigger );

  TIM_SelectOutputTrigger( TIM2, TIM_TRGOSource_OC2Ref );

  TIM_SelectMasterSlaveMode( TIM2, TIM_MasterSlaveMode_Enable );

  /* Enable TIM2 Interrupt */

  NVIC_EnableIRQ( TIM2_IRQn );

  /*

   * Setup ADC1 to sample the receiver input signal

   */

  prvADC_InitStructure.ADC_Mode = ADC_Mode_Independent;

  prvADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

  prvADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Left;

  prvADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;

  prvADC_InitStructure.ADC_NbrOfChannel = 1;

  prvADC_InitStructure.ADC_ScanConvMode = DISABLE;

  ADC_Init( ADC1, &prvADC_InitStructure );

  ADC_RegularChannelConfig( ADC1, ADC_Channel_9, 1, ADC_SampleTime_1Cycles5 );

  /* Enable the start of conversion for ADC1 through external trigger */

  ADC_ExternalTrigConvCmd( ADC1, ENABLE );

  /* Enable ADC Interrupt on End of Conversion to Test is ADC is being triggered */

  ADC_ITConfig( ADC1, ADC_IT_EOC, ENABLE );

  /* Enable ADC Interrupt */

  NVIC_EnableIRQ( ADC1_2_IRQn );

  /* Enable ADC1 DMA transfer */

  ADC_DMACmd( ADC1, ENABLE );

  /* Configure DMA for ADC1 */

  /* DMA1 channel1 configuration ----------------------------------------------*/

  DMA_DeInit( DMA1_Channel1 );

  prvDMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&ADC1->DR;

  prvDMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)ADC_DMA_Buffer;

  prvDMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;

  prvDMA_InitStructure.DMA_BufferSize = ADC_ARRAY_SIZE;

  prvDMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;

  prvDMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;

  prvDMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;

  prvDMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;

  prvDMA_InitStructure.DMA_Mode = DMA_Mode_Normal;

  prvDMA_InitStructure.DMA_Priority = DMA_Priority_High;

  prvDMA_InitStructure.DMA_M2M = DMA_M2M_Disable;

  DMA_Init( DMA1_Channel1, &prvDMA_InitStructure );

  /* Enable DMA1 channel1 */

  DMA_Cmd( DMA1_Channel1, ENABLE );

  /* Enable ADC1 */

  ADC_Cmd( ADC1, ENABLE );