cancel
Showing results for 
Search instead for 
Did you mean: 

Triggering ADC from Timer. Does timer output have to be enabled?

jameslivingston9
Associate II
Posted on January 04, 2013 at 16:31

Hi,

I'm using a STM32F103.

My main question is, is there a way to trigger an ADC regular group using a timer output compare channel but without enabling output to the timer channel's physical output pin?

I've been trying to trigger ADC1 with TIM4_CH4, but I have to use the default pin for TIM4_CH4 for I2C1 and I can't remap TIM4_CH4 because that pin is used for external RAM.

I started with the example code posted in ''Timer4 trigger for ADC'' (Posted: 6/15/2011 4:44 PM) and that works fine.

But, if I remap I2C1 (using the default TIM4_CH4 pin), the timer interferes with the I2C.

And, if I disable the timer's output, (TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable), the ADC does not get triggered.

Is it just that you can't trigger an ADC without using the timer's output pin or does it seem like I have something else messed up?

Below is the example code from ''Timer4 trigger for ADC''.

Thanks.

TIM4_CC4 should be viable (TIMER 4 CHANNEL 4)

You'll need to program ADC1->CR2, with EXTSEL[2:0] = 5   (101)

  /* TIM4 configuration ------------------------------------------------------*/

  /* Time Base configuration */

  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

  TIM_TimeBaseStructure.TIM_Period = 0xFF;

  TIM_TimeBaseStructure.TIM_Prescaler = 0x4;

  TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;

  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

  TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);

  /* TIM4 channel4 configuration in PWM mode */

  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

  TIM_OCInitStructure.TIM_Pulse = 0x7F;

  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;

  TIM_OC4Init(TIM4, &TIM_OCInitStructure);

..

  /* 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_T4_CC4;

  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;

  ADC_InitStructure.ADC_NbrOfChannel = 1;

  ADC_Init(ADC1, &ADC_InitStructure);

#adc-tim
5 REPLIES 5
Posted on January 04, 2013 at 17:46

Not sure if the output pin needs enabling or not, but I can foresee issues in the muxing fabric if it conflicts on the pin. But if it does perhaps you can remap TIM4_CH4 to PD15, it's on the die even if it's not bonded out on your package.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jameslivingston9
Associate II
Posted on January 04, 2013 at 18:02

Posted on January 04, 2013 at 18:16

I would do that but PD15 is being used for FSMC.

Which part are you using, specific part#, the High Density / XL? Can you use TIM2_CH2 as a trigger? Is TIM1 being used?

Perhaps you can route externally via a Px11 pin

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
jameslivingston9
Associate II
Posted on January 04, 2013 at 18:44

Timers 1 - 3 are being used for various other things,

but I think we found our solution.

We are using ADC3 to monitor a battery voltage and we don't need a hardware trigger for that.

We can move the battery to ADC1 and use ADC3 with Timer 5 as the trigger.

Thanks for your help.

Posted on February 22, 2013 at 15:49

> But, if I remap I2C1 (using the default TIM4_CH4 pin), the timer interferes with the I2C.

I don't understand, why would that be so. What were the symptoms?

Thanks,

JW