Skip to main content
paulcornelius9
Associate II
February 18, 2009
Question

Use of the external trigger to initiate single ADC conversions

  • February 18, 2009
  • 5 replies
  • 2387 views
Posted on February 18, 2009 at 01:20

Use of the external trigger to initiate single ADC conversions

    This topic has been closed for replies.

    5 replies

    paulcornelius9
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:42

    I am trying to do a simple A/D conversion, but time-synchronized to another event. For this purpose I use ADC1, regular channel, single conversion mode with an external trigger from TIM1 CC3. I perform the following procedure:

    1. Turn ADC1 on (ADON bit=1)

    2. Set single conversion (CONT=0)

    3. Select TIM1 CC3 as the trigger (EXTSEL=010)

    4. Produce these triggers at a rate of 100 kHz (confirmed by oscilloscope)

    5. Set External trigger mode (EXTTRIG=1)

    The result is: NOTHING. The SRTR flag never comes on. The EOC flag never comes on. No data is in ADC_DR.

    While messing around with this I discovered that a conversion will occur the second time I set the EXTTRIG bit to 1, even though it is already 1. It appears to be analagous to the use of the ADON bit to trigger a conversion from software (you need to set it to 1 to turn the ADC on, then write a 1 to it again to start a conversion). This is documented in the Programmer's guide for the ADON bit, but I can find no mention of a similar behavior for the EXTTRIG bit.

    Also I have determined that when I set the EXTTRIG to 0, then the next time I set it to 1, no conversion occurs. A second write to the bit is always necessary. But if I never reset it to 0, then a conversion will occur each time I write a 1.

    Can anyone confirm that this is how it is supposed to work?

    When the EXTTRIG is set to 1 and a contiuous stream of triggers is sent out (the rate in my application is 100 kHz), will the ADC perform exactly one conversion and then stop, or will it perform a conversion every time it gets a trigger?

    Paul Cornelius

    jamessteward
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:42

    Guys,

    That's horrendous, and completely defeats the usefulness of DMA to fill a buffer from the ADC.

    Seriously, is there no way to use DMA to transfer conversion results when the ADC is using an external trigger?

    Does it only work for;

    ADC_InitStructure.ADC_ScanConvMode = ENABLE;

    ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;

    ???

    Did anyone ask ST tech support about this?

    James.

    paulcornelius9
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:42

    Bill:

    No one ever replied, and I ended up doing things a different way. But if I remember correctly, I had to set the EXTTRIG flag twice in order to get the first conversion to occur, and set it again for each A/D conversion I wanted to perform thereafter. It seemed like each time I set the bit to 1 the ADC became ''armed'' for one conversion. I didn't verify that these conversions were in fact initiated by the hardware trigger, but I assume that they were.

    So I think after each conversion, you will need to move the data out of the result register and then re-arm the ADC with another EXTTRIG=1.

    Paul Cornelius

    butera
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 12:42

    Paul -

    Did you ever get an answer for this?

    I have hit the same screen. Am trying to trigger off of a periodic TIM2_CC2 event.

    I can see the timer event on both a scope and the debugger. But can seem to configure the ADC to recognize the trigger.

    Grateful for any input,

    - Bill

    jamessteward
    Associate II
    May 17, 2011
    Posted on May 17, 2011 at 12:42

    After reading the code offered in this thread

    http://www.st.com/mcu/forums-cat-7578-23.html&start=10

    I adapted mine to use timer 3 instead of 1. Also the example.c kindly posted uses;

    ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T3_TRGO;

    and

    TIM_SelectOutputTrigger(TIM3, TIM_TRGOSource_Update);

    With these changes, I *think* I have it working as desired now.

    Cheers,

    James.