AnsweredAssumed Answered

STM32F4 Timer2 off - Pin status problem

Question asked by draz.raz on Sep 12, 2013
Latest reply on Sep 16, 2013 by draz.raz
Hello,

I have problems to set up the right pin state while TIM2 is configured in PWM mode and turned off. The corresponding CC output pin stays HIGH while timer is off but I strongly need it to be LOW. I thought TIM_OCIdleState would solve this problem but it doesn't.

Heres the initialization code:

        RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

        GPIO_InitTypeDef GPIO_InitStruct;

        GPIO_InitStruct.GPIO_Pin = GPIO_Pin_2;
        GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
        GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
        GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_DOWN;
        GPIO_Init(GPIOA, &GPIO_InitStruct);

        GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_TIM2);


        TIM_TimeBaseInitTypeDef TIM_TimeBaseStruct;

        TIM_TimeBaseStruct.TIM_Prescaler = 0;
        TIM_TimeBaseStruct.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseStruct.TIM_Period = 103;
        TIM_TimeBaseStruct.TIM_ClockDivision = TIM_CKD_DIV1;
        TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStruct);


        TIM_OCInitTypeDef TIM_OCInitStruct;

        TIM_OCInitStruct.TIM_OCMode = TIM_OCMode_PWM1;
        TIM_OCInitStruct.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStruct.TIM_Pulse = 80;
        TIM_OCInitStruct.TIM_OCPolarity = TIM_OCPolarity_High;
        TIM_OCInitStruct.TIM_OCIdleState = TIM_OCIdleState_Reset;
        TIM_OCInitStruct.TIM_OutputNState = TIM_OutputState_Disable;
        TIM_OC3Init(TIM2, &TIM_OCInitStruct);



    /* --- Interrupt TIM1 CC Event --- */

    NVIC_InitTypeDef NVIC_InitStructure;


    NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure);

    TIM_SetCompare3(TIM2,80);
    TIM_ITConfig(TIM2, TIM_IT_CC3, ENABLE);


    TIM_Cmd(TIM2, DISABLE);

Is there a way to get the output pin low while the timer is not running?
(btw., PWM works fine)

Outcomes