Skip to main content
alprof
Associate II
July 28, 2013
Question

STM32F4Discovery counter problem,

  • July 28, 2013
  • 2 replies
  • 648 views
Posted on July 28, 2013 at 22:22

I have problem with timer - I want use one as simply counter of external impulses.

Now I have (with too many unnecessary settings), but counter not work. I want use eg. TIM1, then I should use GPIO setting as AF for TIM1_CH1?

gpio_pin_cfg(GPIOA, 8, GPIO_AF1_IN_FLOATING);

RCC->

APB2ENR

|= RCC_APB2ENR_TIM1EN;

TIM1->

CCER

|= TIM_CCER_CC1E;

TIM1->

CCR1

|= 2;

TIM1->

SMCR

|= TIM_SMCR_ECE;

TIM1->

SMCR

|= 7;

TIM1->

CR2

|= TIM_CR2_TI1S;

TIM1->

CCMR1

|= 1;

TIM1->

CR1

|= TIM_CR1_CEN ;
    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    July 28, 2013
    Posted on July 29, 2013 at 00:05

    This has a high probability of functioning as desired.

    void TIM1_Configuration(void)
    {
    GPIO_InitTypeDef GPIO_InitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    /* GPIOA clock enable */
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
    /* TIM1 clock enable */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
    /* GPIOA Configuration: TIM1 CH1 (PA8) */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; // Input/Output controlled by peripheral
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; // Button to ground expectation
    GPIO_Init(GPIOA, &GPIO_InitStructure);
    /* Connect TIM1 pins to AF */
    GPIO_PinAFConfig(GPIOA, GPIO_PinSource8, GPIO_AF_TIM1);
    TIM_TimeBaseStructure.TIM_Period = 65535; // TIM1 16-bit
    TIM_TimeBaseStructure.TIM_Prescaler = 0;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
    /* Select external clock source */
    TIM_TIxExternalClockConfig(TIM1, TIM_TIxExternalCLK1Source_TI1, TIM_ICPolarity_Rising, 0);
    /* Enable the timer */
    TIM_Cmd(TIM1, ENABLE);
    /* Main Output Enable, and Input */
    TIM_CtrlPWMOutputs(TIM1, ENABLE);
    }

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    alprof
    alprofAuthor
    Associate II
    July 29, 2013
    Posted on July 29, 2013 at 09:49

    Ok, thank you. I not use SPL, but now I can compare.