AnsweredAssumed Answered

STM32f207 PWM output

Question asked by boeh_ocansey.eugenia on Jul 15, 2016
Latest reply on Jul 18, 2016 by Clive One
I am trying to generate a PWM output on port PE9. I have set up the Timer configuration, the GPIO configuration and the interrupts. Somehow when I add the code to set up the PWM mode, then I completely lose my signal. Without the code for configuring the PWM mode, I get a PWM signal but with a very small duty cycle which I would like to regulate. I have no idea what is going on.

static void ledamdrv_TIMInit(void)
    TIM_TimeBaseInitTypeDef TIM_Base; // structure with timer base settings
    TIM_OCInitTypeDef  TIM_OCInitStructure;
    uint16_t PrescalerValue;

    GPIO_InitTypeDef GPIO_InitStructure;

    // Enable clocks
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

    /* Compute the prescaler value */
    PrescalerValue = (uint16_t) (ROUNDDIV(SystemAPB2TimerClock, LEDAMDRV_TIMER_FREQ_HZ) - 1);

    // Setup Timer, PWM generation with CL modulation
    TIM_DeInit( TIM1 );
    TIM_Base.TIM_Prescaler = 0;
    TIM_Base.TIM_ClockDivision = TIM_CKD_DIV1;
    TIM_Base.TIM_CounterMode = TIM_CounterMode_Up;
    TIM_TimeBaseInit( TIM1, &TIM_Base );

     /* Prescaler configuration */
     TIM_PrescalerConfig(TIM1, PrescalerValue, TIM_PSCReloadMode_Immediate);

    /* Enable TIM1 Preload register on ARR */
     // TIM_ARRPreloadConfig(TIM1, ENABLE);

    // /* PWM1 Mode configuration: Channel1 */
        // TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
        // TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;  // Don't need pin output, just interrup
       //  TIM_OCInitStructure.TIM_Pulse = ( (LEDAMDRV_TIMER_FREQ_HZ / LEDMADDRV_ISR_FREQ_HZ) / 4);//50% duty cycle
       //  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

       //  TIM_OC1Init(TIM1, &TIM_OCInitStructure);

         TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);

    /* TIM1 enable counter */
    TIM_Cmd(TIM1, ENABLE);
    /* TIM Interrupt enable */
    TIM_ITConfig(TIM1, TIM_IT_Update, ENABLE);

    TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE); //added this 14-7-2016


As soon as I uncomment the commented code above, I completely lose the PWM signal. Any ideas on how to solve this will be very appreciated.