cancel
Showing results for 
Search instead for 
Did you mean: 

TIMER WITH EXTERNAL CLOCK PIN STM32F429

gerson74
Associate II
Posted on August 20, 2014 at 14:14

Hi!!!

I would like to connect the GPIO A6 to the timer 13 as input capture and also to the timer 3 as external clock. 

I've tried to use the input connected only to timer 13 and it runs ( it reaches the interrupt routine each rising edge of  PA6). 

I've tried to use the input connected only to timer 3 and it runs ( it reaches the interrupt routine every 50 rising edge of  PA6). 

Then I've tried to use the input connected to both timers and it DOESN'T run as I wanted: timer 3 seems to work correctly but timer 13 does not work ( it doesn't reach the interrupt routine ).

Is it possible to connect 2 timers to the same pin? Am I doing something wrong?

Below the code.

Initialization routine timer:

//----------------------------------------------------------

int init_TIM3   ( void )

{

    

    NVIC_InitTypeDef NVIC_InitStructure;

    TIM_DeInit( TIM3 ); // disabilito il ripetitore a timer

    // Enable the TIM3 global Interrupt

    NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    GPIO_InitTypeDef GPIO_InitStructure;

    // GPIOA clock enable

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    //  pin configuration

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6,  GPIO_AF_TIM3); // PA6 TIM3_CH1

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

     int i;

     // Enable TIM3 Peripheral clock

     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

     TIM_TimeBaseStructure.TIM_Prescaler = 0;

     TIM_TimeBaseStructure.TIM_Period = 50;

     TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;

     TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

     TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

     TIM_TIxExternalClockConfig(TIM3, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);

     TIM_Cmd(TIM3, ENABLE);

     // Likely will interrupt initially unless we clear it

     for(i=0; i<3; i++)

       if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET)

         TIM_ClearITPendingBit(TIM3, TIM_IT_Update);

     TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

}

//----------------------------------------------------------

void init_TIM13( void )

//----------------------------------------------------------

{

    GPIO_InitTypeDef              GPIO_InitStructure;

    NVIC_InitTypeDef              NVIC_InitStructure;

    TIM_ICInitTypeDef             TIM_ICInitStructure;

    TIM_TimeBaseInitTypeDef       TIM_TimeBaseStructure;

    TIM_DeInit( TIM13 );

    /* TIM13 clock enable */

    RCC_APB1PeriphClockCmd  ( RCC_APB1Periph_TIM13 , ENABLE );

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

    //  pin configuration

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;

    GPIO_Init(GPIOA, &GPIO_InitStructure);

    GPIO_PinAFConfig(GPIOA, GPIO_PinSource6,  GPIO_AF_TIM13); // PA6 TIM13_CH1

    /* Enable the TIM13 global Interrupt */

    NVIC_InitStructure.NVIC_IRQChannel = TIM8_UP_TIM13_IRQn;

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

        TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;

        TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;

        TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;

        TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;

        TIM_ICInitStructure.TIM_ICFilter = 0x0;

        TIM_ICInit(TIM13, &TIM_ICInitStructure);

    /* Enable the CC1 Interrupt Request */

    TIM_ITConfig(TIM13, TIM_IT_CC1, ENABLE);

    /* TIM enable counter */

    TIM_Cmd(TIM13, ENABLE);

 

}

Thank's!!!
1 REPLY 1
Posted on August 20, 2014 at 15:48

Is it possible to connect 2 timers to the same pin? Am I doing something wrong?

You can only mux a pin to a single peripheral.

GPIO_PinAFConfig(GPIOA, GPIO_PinSource6,  GPIO_AF_TIM3); // Only ONE setting per pin

You'll have to use two pins or reevaluate what you are trying to achieve. Like using internal connectivity options (ITR). Review the Reference Manual for internal routing options between timers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..