cancel
Showing results for 
Search instead for 
Did you mean: 

using TIM1 TRGO to start adc conversion

giu
Associate II
Posted on November 22, 2011 at 16:17

hello, I'm trying to trigger the ADC1 with the TRGO signal of TIM1, here is the code that I,m using to configure the timer:

TIM1_DeInit();

TIM1_TimeBaseInit(128, TIM1_CounterMode_Up, 62500, 0);

TIM1_SelectOutputTrigger(TIM1_TRGOSource_Update);

TIM1_Cmd(ENABLE);

while for configuring  the ADC1 and getting the conversion result I'm using (adapted from STM8L-discovery firmware):

u16 ADC_CH3_TRIG(void)

{

    uint8_t i;

    uint16_t res;

/* Enable ADC clock */

  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, ENABLE);

/* de-initialize ADC */

  ADC_DeInit(ADC1);

/*ADC configuration

  ADC configured as follow:

  - Channel 3

  - Mode = Single ConversionMode(ContinuousConvMode disabled)

  - Resolution = 12Bit

  - Prescaler = /1

  - sampling time 9 */

 

  ADC_Cmd(ADC1, ENABLE);    

  ADC_Init(ADC1, ADC_ConversionMode_Single,

  ADC_Resolution_12Bit, ADC_Prescaler_1);

 

ADC_SamplingTimeConfig(ADC1, ADC_Group_FastChannels,              ADC_SamplingTime_9Cycles);

ADC_ExternalTrigConfig(ADC1,

ADC_ExtEventSelection_Trigger2,

ADC_ExtTRGSensitivity_Rising);

ADC_ChannelCmd(ADC1, ADC_Channel_3, ENABLE);

  delay_10us(3);

/* initialize result */

  res = 0;

  for(i=8; i>0; i--)

  {

/* start ADC convertion by software */

    //ADC_SoftwareStartConv(ADC1);

/* wait until end-of-covertion */

    while( ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == 0 );

/* read ADC convertion result */

    res += ADC_GetConversionValue(ADC1);

  }

    

/* de-initialize ADC */

  //ADC_VrefintCmd(DISABLE);

  ADC_DeInit(ADC1);

 

 /* disable SchmittTrigger for ADC_Channel_24, to save power */

  //ADC_SchmittTriggerConfig(ADC1, ADC_Channel_24, DISABLE);

    

  CLK_PeripheralClockConfig(CLK_Peripheral_ADC1, DISABLE);

  ADC_ChannelCmd(ADC1, ADC_Channel_3, DISABLE);

    

  return (res>>3);

}

The program seems to hang up at the while loop waiting for EOC signal... what am I doing wrong? Is there an application note that I can use for ADC triggering with a timer?

#adc-stm8
1 REPLY 1
Nickname13136_O
Associate II
Posted on March 13, 2012 at 13:39

Hello,

You can refer

STM8L15x standard peripheral library 1.5.1

In this library, you can see ADC_DMA example. I hope this will help.

Regards,