AnsweredAssumed Answered

howto get tim_16 Frequ. to PB8

Question asked by gnoss.juergen on Jan 24, 2013
Latest reply on Jan 25, 2013 by gnoss.juergen
Hello,

My problem is that I don't get the Frequency produced by Timer 16  seen on PB8.


Somebody can have a look at the code and tell me what's missing or wrong.

 static void setup_Timer16(void) {
    TIM_OCInitTypeDef  TIM_OCInitStructure;
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
    GPIO_InitTypeDef GPIO_InitStructure;

    // clock on Timer 16 enable
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE);

    // GPIOB clocks enable
    RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);

    // GPIOB Configuration: Pin PB8 AF2 connecting to TIM16 Ch1
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Mode = /*GPIO_Mode_OUT*/GPIO_Mode_AF;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
    GPIO_Init(GPIOB, &GPIO_InitStructure);

    // Connect TIM16 pins to AF2
    GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_2);

    TIM_DeInit(TIM16 );
    TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);

    /* Time base configuration */
    TIM_TimeBaseStructure.TIM_Period = (SystemCoreClock / 50000/*lcd_Contrast*/) - 1;
    TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
    TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM16, &TIM_TimeBaseStructure);

    // Timer output compare configuration
    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
    TIM_OCInitStructure.TIM_OCMode = /*TIM_OCMode_Timing*/TIM_OCMode_Toggle;
    TIM_OCInitStructure.TIM_Pulse = 500;
    TIM_OC1Init(TIM16, &TIM_OCInitStructure);

/*
    NVIC_InitTypeDef nvic;
    nvic.NVIC_IRQChannel = TIM16_IRQn;
    nvic.NVIC_IRQChannelCmd = ENABLE;
    nvic.NVIC_IRQChannelPriority = 3;
    NVIC_Init(&nvic);


    TIM_ITConfig(TIM16, TIM_IT_CC1 | TIM_IT_Update, ENABLE);
*/

    /* TIM16 enable counter */
    TIM_Cmd(TIM16, ENABLE);

}

Outcomes