Skip to main content
dmatheis
Associate III
December 16, 2009
Question

Using Tim1 ETR to count up (Update Event not generated)

  • December 16, 2009
  • 1 reply
  • 1310 views
Posted on December 16, 2009 at 08:15

Using Tim1 ETR to count up (Update Event not generated)

    This topic has been closed for replies.

    1 reply

    dmatheis
    dmatheisAuthor
    Associate III
    May 17, 2011
    Posted on May 17, 2011 at 13:34

    Hello,

    I'm searching for an example code using Tim1 ETR to count up or down (ETR Clock mode 2). My STM32F103RBT6 (Tim1_ETR Pin PA12) is connected to an Atmel 125 kHz RFID Frontend-IC (U3280M), which extracts the field clock of 125 KHz (period 8 µS). Every 32 periods I'll have to check another pin state, so I want use this clock signal for the Tim1 timer to count 32 periods (32 * 8 µS = 256 µS) and then generate an Update Interrupt. But TIM1_UP_IRQHandler() isn't called after 32 periods in my code. The scope shows the signal, I think something is wrong with my timer init. Timer start (TIM_Cmd(TIM1, ENABLE);) is generated by calling an external interrupt (I don't post this code section, because it is executed). The relevant sections:

    Code:

    Timer Init:

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

    TIM_DeInit(TIM1);

    /* Time base configuration */

    TIM_TimeBaseStructure.TIM_Period = 32*8;

    TIM_TimeBaseStructure.TIM_Prescaler = 0; /* no prescaler */

    TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; /* no clock division */

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;

    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

    TIM_ClearFlag(TIM1, TIM_FLAG_Update); /* Clear the interrput flag */

    /* External Clock Mode 2, count at each rising, no filter */

    TIM_ETRClockMode2Config(TIM1, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0x00);

    TIM_SelectInputTrigger(TIM1, TIM_TS_ETRF); /* Select the TIM1 Input Trigger: */

    TIM_UpdateDisableConfig(TIM1, DISABLE); /* enable Update Event */

    TIM_UpdateRequestConfig(TIM1, TIM_UpdateSource_Regular); /* Only counter overflow should generate an update */

    TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE); /* enable update interrupt */

    NVIC Init:

    NVIC_InitStruct.NVIC_IRQChannel = TIM1_UP_IRQn;

    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = TIM1_UP_IRQnChannelPreemptionPriority;

    NVIC_InitStruct.NVIC_IRQChannelSubPriority = TIM1_UP_IRQnChannelSubPriority;

    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStruct);

    GPIO Init:

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12;

    GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;

    GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING; /* RM-> normal pushpull config, page 145, table 19 */

    GPIO_Init(GPIOA, &GPIO_InitStruct);

    So what's wrong with my code (probably, something with the timer initialisation) or does someone have an example code using ETR clock mode 2?

    Thank you

    Dominik